import Mathlib import OAI.Analysis.HardSphere.Cutoffs.PathLift import OAI.Analysis.HardSphere.Orbitals.CellPartition import OAI.Analysis.HardSphere.Conditioning.Sampling namespace OAI section section noncomputable section open MeasureTheory ProbabilityTheory Set open scoped ENNReal BigOperators namespace HardSphere.Sampling variable {I : Type*} [Fintype I] [DecidableEq I] abbrev Allocation (m : ℕ) (I : Type*) := Option (Fin m ↪ I) instance allocationMeasurable (m : ℕ) : MeasurableSpace (Allocation m I) := ⊤ instance allocationSingletons (m : ℕ) : MeasurableSingletonClass (Allocation m I) := ⟨fun _ ↦ trivial⟩ instance allocationFintype (m : ℕ) : Fintype (Allocation m I) := inferInstanceAs (Fintype (Option (Fin m↪I))) def allocationPMF (E : Finset I) (m : ℕ) : PMF (Allocation m I) := by classical by_cases h : m≤E.card · haveI : Nonempty (Fin m↪E) := Function.Embedding.nonempty_of_card_le (by simpa using h) exact (PMF.uniformOfFintype (Fin m↪E)).map (fun f ↦ some (f.trans (Function.Embedding.subtype _))) · exact PMF.pure none omit [Fintype I] [DecidableEq I] in lemma allocationPMF_large (E : Finset I) (m : ℕ) (h : m≤E.card) [Nonempty (Fin m↪E)] : allocationPMF E m=(PMF.uniformOfFintype (Fin m↪E)).map (fun f ↦ some (f.trans (Function.Embedding.subtype _))) := by simp [allocationPMF,h] omit [Fintype I] [DecidableEq I] in lemma allocationPMF_small (E : Finset I) (m : ℕ) (h : ¬m≤E.card) : allocationPMF E m=PMF.pure none := by simp [allocationPMF,h] omit [Fintype I] [DecidableEq I] in lemma allocationPMF_support (E : Finset I) (m : ℕ) (a : Allocation m I) (h : a∈(allocationPMF E m).support) : ∀f,a=some f→∀k,f k∈E := by classical by_cases hm : m≤E.card · have : Nonempty (Fin m↪E) := Function.Embedding.nonempty_of_card_le (by simpa using hm) rw [allocationPMF_large E m hm,PMF.support_map] at h obtain ⟨g,_,rfl⟩ := h intro f hf k have he : g.trans (Function.Embedding.subtype _)=f := Option.some.inj hf exact he ▸ (g k).property · rw [allocationPMF_small E m hm,PMF.support_pure] at h have ha : a=none := h simp only [ha,reduceCtorEq,false_implies,implies_true] def allocationKernel (m : ℕ) : Kernel (Finset I) (Allocation m I) := ⟨fun E ↦ (allocationPMF E m).toMeasure,measurable_of_countable _⟩ instance allocationKernel_markov (m : ℕ) : IsMarkovKernel (allocationKernel (I:=I) m) := ⟨fun E ↦ by change IsProbabilityMeasure (allocationPMF E m).toMeasure; infer_instance⟩ omit [Fintype I] [DecidableEq I] in lemma allocated_group_uniform (E : Finset I) (m q : ℕ) (h : m≤E.card) (group : Fin q↪Fin m) : (allocationPMF E m).map (Option.map (fun f ↦ group.trans f))=allocationPMF E q := by classical have hqm : q ≤ m := by simpa using Fintype.card_le_of_embedding group have hq : q≤E.card := hqm.trans h have : Nonempty (Fin m↪E) := Function.Embedding.nonempty_of_card_le (by simpa using h) have : Nonempty (Fin q↪E) := Function.Embedding.nonempty_of_card_le (by simpa using hq) rw [allocationPMF_large E m h,allocationPMF_large E q hq,PMF.map_comp] have hu := congrArg (fun P : PMF (Fin q↪E) ↦ P.map (fun f ↦ some (f.trans (Function.Embedding.subtype _)))) (embedding_restriction_uniform (V:=E) group) rw [PMF.map_comp] at hu exact hu lemma allocation_half_bad (E B : Finset I) (m : ℕ) (hE : 2*m≤E.card) (hB : 10*(E∩B).card≤E.card) : (allocationPMF E (2*m)).toMeasure {a | ∃f,a=some f ∧ m≤(Finset.univ.filter (fun k ↦ f k∈B)).card}≤ ENNReal.ofReal ((2/5:ℝ)^m) := by classical have : Nonempty (Fin (2*m)↪E) := Function.Embedding.nonempty_of_card_le (by simpa using hE) let : MeasurableSpace (Fin (2*m)↪E) := ⊤ let : MeasurableSingletonClass (Fin (2*m)↪E) := ⟨fun _ ↦ trivial⟩ by_cases hempty : E.Nonempty · have : Nonempty E := hempty.to_subtype rw [allocationPMF_large E (2*m) hE,←PMF.toMeasure_map _ _ (measurable_of_countable _)] rw [Measure.map_apply (measurable_of_countable _) (by exact MeasurableSet.of_discrete)] let bad : Set E := {i | i.val∈B} have hc : Fintype.card bad=(E∩B).card := by let equiv : bad ≃ (E∩B : Finset I) := { toFun := fun i ↦ ⟨i.val.val,Finset.mem_inter.mpr ⟨i.val.property,i.property⟩⟩ invFun := fun i ↦ ⟨⟨i.val,(Finset.mem_inter.mp i.property).1⟩,(Finset.mem_inter.mp i.property).2⟩ left_inv := fun i ↦ by cases i; rfl right_inv := fun i ↦ by cases i; rfl } exact (Fintype.card_congr equiv).trans (Fintype.card_coe (E∩B)) have hb : (Nat.card bad:ℝ)≤(Fintype.card E:ℝ)/10 := by rw [Nat.card_eq_fintype_card,hc,Fintype.card_coe] have hb' : (10:ℝ)*((E∩B).card:ℝ)≤(E.card:ℝ) := by exact_mod_cast hB linarith rw [PMF.toMeasure_apply_eq_toOuterMeasure_apply _ (by exact MeasurableSet.of_discrete)] have hset : (fun f : Fin (2*m)↪E ↦ some (f.trans (Function.Embedding.subtype _))) ⁻¹' {a : Allocation (2*m) I | ∃f,a=some f ∧ m≤(Finset.univ.filter (fun k ↦ f k∈B)).card}= {f : Fin (2*m)↪E | m≤(Finset.univ.filter (fun k ↦ f k∈bad)).card} := by ext f simp [bad] rw [hset] have he : ENNReal.ofReal ((2/5:ℝ)^m)=(2/5:ℝ≥0∞)^m := by rw [ENNReal.ofReal_pow (by norm_num),ENNReal.ofReal_div_of_pos (by norm_num)] norm_num rw [he] convert uniform_half_bad (V:=E) m bad hb using 1 congr 1 ext f simp only [Set.mem_ofPred_eq] apply iff_of_eq congr 1 congr 1 ext k simp only [Finset.mem_filter,Finset.mem_univ,true_and] · have hz : E=∅ := Finset.not_nonempty_iff_eq_empty.mp hempty have hm : m=0 := by simp [hz] at hE; omega subst m simp only [pow_zero,ENNReal.ofReal_one] exact prob_le_one end HardSphere.Sampling end end section noncomputable section open MeasureTheory ProbabilityTheory Set open scoped ENNReal NNReal Topology BigOperators namespace HardSphere.Groups open Wiener CellOrbital attribute [local instance] Classical.propDecidable attribute [local irreducible] torusDistance def Confined {L : Length} (v : Torus L) (ω : ConfigurationPath 1 L) : Prop := ∀s : Time,torusDistance L (ω s 0) v≤10 lemma confined_closed {L : Length} (v : Torus L) : IsClosed {ω | Confined v ω} := by simp only [Confined,ofPred_forall] apply isClosed_iInter intro s apply isClosed_le _ continuous_const exact (torusDistance_continuous_pair L).comp (f:=fun ω : ConfigurationPath 1 L ↦ (ω s 0,v)) (by fun_prop) def EndpointEligible {N K : ℕ} {L : Length} (v : Fin 3→Fin K) (s₀ : ℝ) (Y Z : Configuration N L) (i : Fin N) : Prop := Y i∈centeredCell L (gridCenter L v) ∧ torusDistance L (Z i) (gridCenter L v)≤3 ∧ ∀j,j≠i→s₀