mathlib4 review helperopen PRs by @wwylele on leanprover-community/mathlib4

← queue

#46460 feat: connect eVariation and hausdorffMeasure

t-topology t-measure-probability CI success

+139 −0 · 3 files · 1 commit · head ed68984 · updated 11 days ago · Files changed on GitHub

PR description

Mathlib has two ways to say "arc length": 1-d Hausdorff measure and variation. This PR proves they are equal under suitable conditions.


AI usage: this was originally drafted by Aristotle long time ago (the new code is probably nothing alike any more). This was then iteratively improved by Claude and me.

Conversation on GitHub 2
github-actions[bot] · comment · 2026-11-25
PR summary ed689843a9
Import changes for modified files

No significant changes to the import graph

<details><summary>Import changes for all files</summary>

|Files|Import difference| |-|-| | Mathlib.Topology.EMetricSpace.HausdorffMeasureBoundedVariation (new file)|2558|

</details>


<details><summary>

Declarations diff (regex)

</summary>

+ Icc_add_Ici + Iic_add_Icc + eVariationOn_inter_Icc_eq + ediam_image_slice_le + hausdorffMeasure_eq_eVariationOn + hausdorffMeasure_le_eVariationOn + slice + subset_iUnion_slice + sum_eVariationOn_slice_le + toReal_eVariationOn_Iic_mono <details> <summary>You can run this locally as follows</summary>

## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

</details>

The doc-module for scripts/pr_summary/declarations_diff.sh in the undefined repository contains some details about this script.

</details>

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit ed68984).

  • +4 new declarations
  • −0 removed declarations
+MeasureTheory.Measure.hausdorffMeasure_eq_eVariationOn
+MeasureTheory.Measure.hausdorffMeasure_le_eVariationOn
+eVariationOn.Icc_add_Ici
+eVariationOn.Iic_add_Icc

No changes to strong technical debt. No changes to weak technical debt.

Current commit ed689843a9 Reference commit e62b985f6c

This script lives in the undefined repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
wwylele · comment · 2026-11-25

t-measure-probability

Mathlib.lean +1 −0

public import Mathlib.Topology.EMetricSpace.Basic
8363public import Mathlib.Topology.EMetricSpace.BoundedVariation
8364public import Mathlib.Topology.EMetricSpace.Defs
8365public import Mathlib.Topology.EMetricSpace.Diam
8366public import Mathlib.Topology.EMetricSpace.HausdorffMeasureBoundedVariation
8367public import Mathlib.Topology.EMetricSpace.Lipschitz
8368public import Mathlib.Topology.EMetricSpace.MulOpposite
8369public import Mathlib.Topology.EMetricSpace.PairReduction

Mathlib/Topology/EMetricSpace/BoundedVariation.lean +11 −0

theorem Icc_add_Icc (f : α → E) {s : Set α} {a b c : α} (hab : a ≤ b) (hb
410 ⟨⟨hb, le_rfl, hbc⟩, inter_subset_right.trans Icc_subset_Ici_self⟩
411 rw [← eVariationOn.union f A B, ← inter_union_distrib_left, Icc_union_Icc_eq_Icc hab hbc]
theorem Iic_add_Icc newL413–416
413theorem Iic_add_Icc (f : α → E) {s : Set α} {a b : α} (hab : a ≤ b) (ha : a ∈ s) :
414 eVariationOn f (s ∩ Iic a) + eVariationOn f (s ∩ Icc a b) = eVariationOn f (s ∩ Iic b) := by
415 rw [← eVariationOn.union f (s := s ∩ Iic a) (t := s ∩ Icc a b) ⟨⟨ha, le_rfl⟩, fun _ h ↦ h.2⟩
416 ⟨⟨ha, le_rfl, hab⟩, fun _ h ↦ h.2.1⟩, ← inter_union_distrib_left, Iic_union_Icc_eq_Iic hab]
theorem Icc_add_Ici newL418–422
418theorem Icc_add_Ici (f : α → E) {s : Set α} {a b : α} (hab : a ≤ b) (hb : b ∈ s) :
419 eVariationOn f (s ∩ Icc a b) + eVariationOn f (s ∩ Ici b) = eVariationOn f (s ∩ Ici a) := by
420 rw [← eVariationOn.union f (s := s ∩ Icc a b) (t := s ∩ Ici b)
421 ⟨⟨hb, hab, le_rfl⟩, fun _ h ↦ h.2.2⟩ ⟨⟨hb, le_rfl⟩, fun _ h ↦ h.2⟩,
422 ← inter_union_distrib_left, Icc_union_Ici_eq_Ici hab]
424theorem sum (f : α → E) {s : Set α} {E : ℕ → α} (hE : Monotone E) {n : ℕ}
425 (hn : ∀ i, 0 < i → i < n → E i ∈ s) :
426 ∑ i ∈ Finset.range n, eVariationOn f (s ∩ Icc (E i) (E (i + 1))) =

Mathlib/Topology/EMetricSpace/HausdorffMeasureBoundedVariation.lean +127 −0 new file

1/-
2Copyright (c) 2026 Weiyi Wang. All rights reserved.
3Released under Apache 2.0 license as described in the file LICENSE.
4Authors: Weiyi Wang
5-/
6module
7
8public import Mathlib.Topology.Connected.HausdorffMeasure
9public import Mathlib.Topology.EMetricSpace.BoundedVariation
11/-!
12# Variation and one-dimensional Hausdorff measure
14This file relates the variation `eVariationOn f s` of a map `f : α → E` on a set `s` to the
15one-dimensional Hausdorff measure of the image `f '' s`.
17## Main results
19* `MeasureTheory.Measure.hausdorffMeasure_le_eVariationOn`: for any map `f` and any set `s`,
20 `μH[1] (f '' s)` is at most the variation of `f` on `s`.
21* `MeasureTheory.Measure.hausdorffMeasure_eq_eVariationOn`: if `f` is continuous and injective on an
22 interval `s`, then `μH[1] (f '' s)` equals the variation of `f` on `s`.
23-/
25open ENNReal Set Filter Topology Metric
27public section
29namespace MeasureTheory.Measure
30variable {α E : Type*} [LinearOrder α] [EMetricSpace E] (f : α → E) (s : Set α) {ε : ℝ}
lemma toReal_eVariationOn_Iic_mono newL32–35
32private lemma toReal_eVariationOn_Iic_mono (htop : eVariationOn f s ≠ ∞) {x y : α} (hxy : x ≤ y) :
33 (eVariationOn f (s ∩ Iic x)).toReal ≤ (eVariationOn f (s ∩ Iic y)).toReal :=
34 ENNReal.toReal_mono (ne_top_of_le_ne_top htop (eVariationOn.mono f inter_subset_left))
35 (eVariationOn.mono f (inter_subset_inter_right _ (Iic_subset_Iic.mpr hxy)))
lemma eVariationOn_inter_Icc_eq newL37–44
37private lemma eVariationOn_inter_Icc_eq (htop : eVariationOn f s ≠ ∞) {x y : α} (hx : x ∈ s)
38 (hxy : x ≤ y) :
39 eVariationOn f (s ∩ Icc x y) = ENNReal.ofReal
40 ((eVariationOn f (s ∩ Iic y)).toReal - (eVariationOn f (s ∩ Iic x)).toReal) := by
41 have h {t : Set α} (ht : t ⊆ s) : eVariationOn f t ≠ ∞ :=
42 ne_top_of_le_ne_top htop (eVariationOn.mono f ht)
43 rw [← eVariationOn.Iic_add_Icc f hxy hx, ENNReal.toReal_add (h inter_subset_left)
44 (h inter_subset_left), add_sub_cancel_left, ENNReal.ofReal_toReal (h inter_subset_left)]
def slice newL46–50
46/-- The set of elements `x` where `eVariationOn f (s ∩ Iic x)` sits between `[k * ε, (k + 1) * ε)`.
47This provides coverings of `s` where each piece has variation at most `ε`. -/
48private def slice (ε : ℝ) (k : ℕ) : Set α :=
49 {x ∈ s | k * ε ≤ (eVariationOn f (s ∩ Iic x)).toReal ∧
50 (eVariationOn f (s ∩ Iic x)).toReal < (k + 1) * ε}
lemma subset_iUnion_slice newL52–57
52private lemma subset_iUnion_slice (hε : 0 < ε) : s ⊆ ⋃ k, slice f s ε k := by
53 intro x hx
54 have h0 : 0 ≤ (eVariationOn f (s ∩ Iic x)).toReal / ε := by positivity
55 refine mem_iUnion.mpr ⟨⌊(eVariationOn f (s ∩ Iic x)).toReal / ε⌋₊, hx, ?_, ?_⟩
56 · exact (le_div_iff₀ hε).mp (Nat.floor_le h0)
57 · exact (div_lt_iff₀ hε).mp (Nat.lt_floor_add_one _)
lemma ediam_image_slice_le newL59–66
59private lemma ediam_image_slice_le (htop : eVariationOn f s ≠ ∞) (k : ℕ) :
60 ediam (f '' slice f s ε k) ≤ ENNReal.ofReal ε := by
61 refine ediam_image_le_iff.mpr fun x hx y hy ↦ ?_
62 wlog! hxy : x ≤ y
63 · exact edist_comm (f x) (f y) ▸ this f s htop k y hy x hx hxy.le
64 apply (eVariationOn.edist_le f (s := s ∩ Icc x y) ⟨hx.1, le_rfl, hxy⟩ ⟨hy.1, hxy, le_rfl⟩).trans
65 rw [eVariationOn_inter_Icc_eq f s htop hx.1 hxy]
66 exact ENNReal.ofReal_le_ofReal (by linarith [hx.2.1, hy.2.2])
lemma sum_eVariationOn_slice_le newL68–80
68private lemma sum_eVariationOn_slice_le (htop : eVariationOn f s ≠ ∞) (hε : 0 ≤ ε) (m : ℕ) :
69 ∑ k ∈ Finset.range m, eVariationOn f (slice f s ε k) ≤ eVariationOn f s := by
70 suffices ∑ k ∈ Finset.range m, eVariationOn f (slice f s ε k) ≤
71 eVariationOn f {x ∈ s | (eVariationOn f (s ∩ Iic x)).toReal < m * ε} from
72 this.trans (eVariationOn.mono f fun x hx ↦ hx.1)
73 induction m with
74 | zero => simp
75 | succ m ih =>
76 grw [Finset.sum_range_succ, ih]
77 refine (eVariationOn.add_le_union f fun x hx y hy ↦ ?_).trans (eVariationOn.mono f ?_)
78 · by_contra! h
79 linarith [hx.2, hy.2.1, toReal_eVariationOn_Iic_mono f s htop h.le]
80 · exact Set.union_subset (fun x hx ↦ ⟨hx.1, by grind⟩) (fun x hx ↦ ⟨hx.1, mod_cast hx.2.2⟩)
82variable [MeasurableSpace E] [BorelSpace E]
theorem hausdorffMeasure_le_eVariationOn newL84–101
84theorem hausdorffMeasure_le_eVariationOn : μH[1] (f '' s) ≤ eVariationOn f s := by
85 by_cases htop : eVariationOn f s = ∞
86 · simp [htop]
87 set ε : ℕ → ℝ := fun n ↦ 1 / (n + 1)
88 have hε (n : ℕ) : 0 < ε n := by positivity
89 have hr : Tendsto (fun n ↦ ENNReal.ofReal (ε n)) atTop (𝓝 0) := by
90 simpa [ε] using ENNReal.tendsto_ofReal (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ))
91 refine hausdorffMeasure_le_liminf_tsum _ _ _ hr (fun n k ↦ f '' slice f s (ε n) k)
92 (.of_forall fun n k ↦ ediam_image_slice_le f s htop k)
93 (.of_forall fun n ↦ (image_mono (subset_iUnion_slice f s (hε n))).trans image_iUnion.le)
94 |>.trans <| liminf_le_of_frequently_le' (.of_forall fun n ↦ ?_)
95 refine ENNReal.tsum_le_of_sum_range_le fun m ↦ ?_
96 calc ∑ k ∈ Finset.range m, ediam (f '' slice f s (ε n) k) ^ (1 : ℝ)
97 _ ≤ ∑ k ∈ Finset.range m, eVariationOn f (slice f s (ε n) k) := by
98 gcongr with k
99 rw [ENNReal.rpow_one]
100 exact ediam_image_le_iff.mpr fun x hx y hy ↦ eVariationOn.edist_le f hx hy
101 _ ≤ eVariationOn f s := sum_eVariationOn_slice_le f s htop (hε n).le m
theorem hausdorffMeasure_eq_eVariationOn newL103–125
103theorem hausdorffMeasure_eq_eVariationOn {α : Type*} [ConditionallyCompleteLinearOrder α]
104 [DenselyOrdered α] [TopologicalSpace α] [OrderTopology α] {f : α → E} {s : Set α}
105 (hs : s.OrdConnected) (hinj : InjOn f s) (hcont : ContinuousOn f s) :
106 μH[1] (f '' s) = eVariationOn f s := by
107 refine le_antisymm (hausdorffMeasure_le_eVariationOn f s) <| iSup_le fun ⟨n, u, hu, us⟩ ↦ ?_
108 have hIcc (i : ℕ) : Icc (u i) (u (i + 1)) ⊆ s := hs.out (us i) (us (i + 1))
109 calc ∑ i ∈ Finset.range n, edist (f (u (i + 1))) (f (u i))
110 _ ≤ ∑ i ∈ Finset.range n, μH[1] (f '' Icc (u i) (u (i + 1))) := by
111 gcongr with i
112 exact (isPreconnected_Icc.image _ (hcont.mono (hIcc i))).edist_le_hausdorffMeasure
113 (mem_image_of_mem f (right_mem_Icc.mpr (hu i.le_succ)))
114 (mem_image_of_mem f (left_mem_Icc.mpr (hu i.le_succ)))
115 _ = μH[1] (⋃ i ∈ Finset.range n, f '' Icc (u i) (u (i + 1))) := by
116 have := nullSingletonClass_hausdorff E one_pos
117 refine (measure_biUnion_finset₀ (fun i hi j hj hij ↦ ?_) fun i _ ↦ ?_).symm
118 · wlog h : i < j generalizing i j
119 · exact (this j hj i hi hij.symm (hij.lt_or_gt.resolve_left h)).symm
120 rw [Function.onFun, AEDisjoint, ← hinj.image_inter (hIcc i) (hIcc j)]
121 refine (Subsingleton.image (fun p hp q hq ↦ ?_) f).measure_zero _
122 rw [le_antisymm (hp.1.2.trans (hu h)) hp.2.1, le_antisymm (hq.1.2.trans (hu h)) hq.2.1]
123 · exact (isCompact_Icc.image_of_continuousOn (hcont.mono (hIcc i)))
124 |>.isClosed.measurableSet.nullMeasurableSet
125 _ ≤ μH[1] (f '' s) := measure_mono (iUnion₂_subset fun i _ ↦ image_mono (hIcc i))
127end MeasureTheory.Measure
0/10 declarations checked

Your review, as Markdown

Paste it as a comment or a review on the PR. Line links to the head commit unfold into code snippets on GitHub.