import OAI.Probability.FKMaps.CornerMass namespace OAI noncomputable section open Set MeasureTheory open scoped BigOperators ENNReal namespace FKCRT attribute [local instance] Classical.propDecidable /-- Equal-Lebesgue-mass time cells. The endpoint one is assigned to the last cell; this retains a total, surjective coding without changing any mass. -/ def timeCell (N : ℕ) (hN : 0 ht (Subtype.ext h)) exact propext (timeCell_eq_iff N hN t ht' i) rw [measure_congr he,cell_volume N hN i] lemma timeCell_map (N : ℕ) (hN : 0 linarith lemma cellPoint_mono (N : ℕ) (hN : 0 linarith /-- Discrete positive preorder samples and their exact equal-mass coding approximate the continuous interval-minimum metric with its own modulus. -/ theorem sampled_excursion_error (N : ℕ) (hN : 0 linarith end FKCRT end noncomputable section open List Equiv Equiv.Perm MeasureTheory Set open scoped BigOperators ENNReal namespace FKCRT.Inventory.CoreTree open MapCycles PermutationWedge attribute [local instance] Classical.propDecidable lemma wordNodeEquiv_val (t : CoreTree) (v : t.Node) : (t.wordNodeEquiv v).val=t.nodeIndex v := rfl lemma nodeIndex_wordNodeEquiv_symm (t : CoreTree) (i : Fin (t.word.length+1)) : t.nodeIndex (t.wordNodeEquiv.symm i)=i.val := by exact congrArg Fin.val (t.wordNodeEquiv.apply_symm_apply i) /-- Same-code positive mesh, with the omitted root still present at time zero. -/ def nodePoint (t : CoreTree) (v : t.Node) : unitInterval := ⟨((t.wordNodeEquiv v).val:ℝ)/(t.word.length+1:ℝ),by constructor · positivity · apply (div_le_one (by positivity)).mpr exact_mod_cast (t.wordNodeEquiv v).isLt.le⟩ lemma nodePoint_nonroot (t : CoreTree) (ht : 0 f (FKCRT.cellPoint t.word.length ht k)) ⟨i,Finset.mem_Icc.mpr ⟨le_rfl,hij⟩⟩ have hki := (Finset.mem_Icc.mp hk).1 have hkj := (Finset.mem_Icc.mp hk).2 let v := t.wordNodeEquiv.symm i.succ let w := t.wordNodeEquiv.symm j.succ let m := t.wordNodeEquiv.symm k.succ have hv : t.nodeIndex v=i.val+1 := t.nodeIndex_wordNodeEquiv_symm i.succ have hw : t.nodeIndex w=j.val+1 := t.nodeIndex_wordNodeEquiv_symm j.succ have hm : t.nodeIndex m=k.val+1 := t.nodeIndex_wordNodeEquiv_symm k.succ have hvm : t.nodeIndex v ≤ t.nodeIndex m := by rw [hv,hm];omega have hmw : t.nodeIndex m ≤ t.nodeIndex w := by rw [hm,hw];omega have hn : t≠leaf := by intro h;subst t;simp [word] at ht obtain ⟨a,ha⟩ := t.pole_some_of_ne_leaf hn v obtain ⟨b,hb⟩ := t.pole_some_of_ne_leaf hn w have hm' : ∀ z,t.nodeIndex v ≤ t.nodeIndex z → t.nodeIndex z ≤ t.nodeIndex w → f (t.nodePoint m) ≤ f (t.nodePoint z) := by intro z hz₁ hz₂ obtain ⟨r,hr⟩ := t.exists_positive_index z (by omega) subst z rw [t.nodePoint_nonroot ht k,t.nodePoint_nonroot ht r] apply hmin r rw [Finset.mem_Icc] simp only [v,w,t.nodeIndex_wordNodeEquiv_symm,Fin.val_succ] at hz₁ hz₂ constructor <;> omega have hd := t.normalized_pole_comparison v w m a b ha hb hvm hmw (fun z => f (t.nodePoint z)) hs herr hm' have hgrid := FKCRT.sampled_excursion_error t.word.length ht f hmod s u hsu k hki hkj (fun r hr₁ hr₂ => hmin r (Finset.mem_Icc.mpr ⟨hr₁,hr₂⟩)) have hvp : t.nodePoint v=FKCRT.cellPoint t.word.length ht i := t.nodePoint_nonroot ht i have hwp : t.nodePoint w=FKCRT.cellPoint t.word.length ht j := t.nodePoint_nonroot ht j have hmp : t.nodePoint m=FKCRT.cellPoint t.word.length ht k := t.nodePoint_nonroot ht k simp only [hvp,hwp,hmp] at hd change |scale*((FKCRT.graph M Set.univ).dist (t.realizedPole M e v) (t.realizedPole M e w):ℝ)-FKCRT.excursionDist f s u| ≤ _ rw [t.realizedPole_some M e v a ha,t.realizedPole_some M e w b hb, t.realized_distance_of M e he hp a b] exact (abs_sub_le _ _ _).trans (add_le_add hd hgrid) /-- Uniform measured-space distortion from actual marked ancestral error, actual largest core, and the modulus of the chosen continuous path. -/ theorem time_distortion (t : CoreTree) {n : ℕ} (M : FKCRT.RootedMap n) (e : t.Dart ≃ FKCRT.Dart n) (ht : 0