import Mathlib import OAI.Analysis.HardSphere.Conditioning.RoutePartition import OAI.Analysis.HardSphere.Allocation.PhysicalRouteFactors namespace OAI section noncomputable section open MeasureTheory ProbabilityTheory Set open scoped ENNReal NNReal namespace HardSphere.Comparison variable {J : Type*} def routePosition {d : ℕ} (labels : Fin d↪J) (i : routeSlots labels) : Fin (d+1) := (Finset.mem_map.mp i.property).choose lemma routeEmbedding_position {d : ℕ} (labels : Fin d↪J) (i : routeSlots labels) : routeEmbedding labels (routePosition labels i)=i.val := (Finset.mem_map.mp i.property).choose_spec.2 def routeSlotEquiv {d : ℕ} (labels : Fin d↪J) : Fin (d+1) ≃ routeSlots labels where toFun k := ⟨routeEmbedding labels k,Finset.mem_map.mpr ⟨k,Finset.mem_univ _,rfl⟩⟩ invFun := routePosition labels left_inv _ := (routeEmbedding labels).injective (routeEmbedding_position labels _) right_inv _ := Subtype.ext (routeEmbedding_position labels _) lemma routePermutation_symm_first {n : ℕ} (labels : Fin (n+1)↪J) : (routePermutation labels).symm (routeEmbedding labels 0)=none := by apply (routePermutation labels).injective rw [Equiv.apply_symm_apply,routePermutation_star] exact routeEmbedding_castSucc labels 0 lemma routePermutation_symm_later {n : ℕ} (labels : Fin (n+1)↪J) (k : Fin (n+2)) (hk : k.val≠0) : (routePermutation labels).symm (routeEmbedding labels k)= some (labels ⟨k.val-1,by omega⟩) := by apply (routePermutation labels).injective rw [Equiv.apply_symm_apply,routePermutation_label] congr 1 exact Fin.ext (by simp only [Fin.val_succ];omega) end HardSphere.Comparison namespace HardSphere.Groups open Wiener Bridge Sampling Comparison GaussianPacking PathCutoff CellOrbital variable {J : Type*} def physicalSlotReference {N K M G : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (g : Fin G) (m : ℕ) (t r R C S : ℝ) (u : Time) (particle : J→Fin N) (v : Fin 3→Fin K) : Option J→Kernel (PhysicalDatum N K M G L) C(Time,Point) | none => Kernel.const _ (cellPathReference v) | some i => datumIndividualReference hL g m r R C S t u (particle i) instance physicalSlotReference_finite {N K M G : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (g : Fin G) (m : ℕ) (t r R C S : ℝ) (u : Time) (particle : J→Fin N) (v : Fin 3→Fin K) (i : Option J) : IsFiniteKernel (physicalSlotReference (M:=M) hL g m t r R C S u particle v i) := by cases i <;> dsimp only [physicalSlotReference] <;> infer_instance lemma physicalSlot_first {N K M G n : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (g : Fin G) (m : ℕ) (t r R C S : ℝ) (u : Time) (particle : J↪Fin N) (labels : Fin (n+1)↪J) (v : Fin (n+2)→(Fin 3→Fin K)) (k : Fin (n+2)) (d : PhysicalDatum N K M G L) : physicalSlotReference hL g m t r R C S u particle (v (Fin.last (n+1))) (routeEmbedding labels k) d=routeFirstReference hL g m t r R C S u (labels.trans particle) v k d := by by_cases hk : k.val