Skip to content

feat(MeasureTheory): Introduce MassFunction α giving rise to a Measure α ⊤#34138

Open
pfaffelh wants to merge 1012 commits intoleanprover-community:masterfrom
pfaffelh:pfaffelh_MF0
Open

feat(MeasureTheory): Introduce MassFunction α giving rise to a Measure α ⊤#34138
pfaffelh wants to merge 1012 commits intoleanprover-community:masterfrom
pfaffelh:pfaffelh_MF0

Conversation

@pfaffelh
Copy link
Copy Markdown
Contributor

@pfaffelh pfaffelh commented Jan 19, 2026

Define MassFunction α := α → ℝ≥0∞
Define toMeasure (w : MassFunction α) : @Measure α ⊤ as a sum of diracs
Show properties of the resulting objects

This PR intends to start a more userfriendly interaction with probability mass functions (PMF). There are two main differences between MassFunction and PMF:

  • PMF hast the additional property HasSum 1, making the resulting measure a probability measure. (For MassFunction, I intend to use the typeclass IsProbabilityMeasurein a later PR instead.)
  • The toMeasure function of MassFunction directly defines the measure as a sum of diracs, which immediately makes computations possible.

Discussion thread on zulip


Open in Gitpod

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Jan 19, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 19, 2026

PR summary cd20542ace

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.MeasureTheory.Measure.MassFunction (new file) 1559

Declarations diff

+ Function.support_subsingleton_of_disjoint
+ MassFunction
+ Set.PairwiseDisjoint.fiber_subtype
+ Set.PairwiseDisjoint.singleton_subtype'
+ Set.indicator_iUnion_of_disjoint'
+ apply_eq_zero_iff
+ apply_pos_iff
+ ext
+ indicator.mul_indicator_eq
+ instFunLike
+ mem_support_iff
+ mulIndicator_iUnion_of_disjoint
+ mulSupport_subsingleton_of_disjoint
+ restrict_toMeasure_support
+ support
+ toMeasure
+ toMeasure'
+ toMeasure_additive
+ toMeasure_apply
+ toMeasure_apply_eq_of_inter_support_eq
+ toMeasure_apply_eq_zero_iff
+ toMeasure_apply_finset
+ toMeasure_apply_fintype
+ toMeasure_apply_inter_support
+ toMeasure_apply_singleton
+ toMeasure_apply_univ
+ toMeasure_apply_univ'
+ toMeasure_apply₁
+ toMeasure_apply₂
+ toMeasure_ext
+ toMeasure_inj
+ toMeasure_injective
+ toMeasure_mono
+ toMeasure_trim_eq_toMeasure'
+ tprod_mulIndicator_of_disjoint
+ tprod_mulIndicator_of_nmem

You can run this locally as follows
## summary with just the declaration names:
./scripts/pr_summary/declarations_diff.sh <optional_commit>

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

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


No changes to technical debt.

You can run this locally as

./scripts/reporting/technical-debt-metrics.sh 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).

@pfaffelh pfaffelh changed the title feat(MeasureTheory): Introduce Mass Function α giving rise to a Measure α ⊤` feat(MeasureTheory): Introduce MassFunction α giving rise to a Measure α ⊤ Jan 21, 2026
@DavidLedvinka DavidLedvinka added the t-measure-probability Measure theory / Probability theory label Jan 21, 2026
@EtienneC30 EtienneC30 removed their assignment Feb 26, 2026
Jun2M and others added 20 commits March 2, 2026 22:02
…ver-community#34783)

Preliminary PR for leanprover-community#26770 (subgraph). Adds the `Compatible` predicate and basic API to `Mathlib.Combinatorics.Graph.Basic`.

- **Compatible**: two graphs are compatible if they agree on incidence for every edge in the intersection of their edge sets.
- Includes `Compatible.isLink_iff`, reflexivity/symmetry instances, `IsLink.of_compatible`, `Compatible.of_disjoint_edgeSet`, and the `Inc`/`IsLoopAt`/`IsNonloopAt` variants.
- **copy** API for copying a graph with new vertex/edge sets and `IsLink`.
…leanprover-community#35461)

We also make the universe heterogeneous instances lower priority, so Lean can more easily elaborate universes.

Co-authored-by: vihdzp <vi.hdz.p@mgmail.com>
…etion.map` (leanprover-community#35595)

This PR extracts the change of the definition of `AdicCompletion.map` from leanprover-community#34936.
@Thmoas-Guan expressed interest in using this result, so I am splitting it out here to unblock it.
…over-community#35557)

We add a variant of `TensorProduct.AlgebraTensorModule.assoc` stated in terms of `IsTensorProduct`.

From Pi1.
If a natural transformation is an isomorphism, then the induced morphism on (co)limits is an isomorphism.
…-community#35258)

This adds an API lemma for `Finsupp` that turned out to be useful in [Heights](github.com/MichaelStollBayreuth/Heights).
…nity#35553)

The plan is to instead make `Order.succ_eq_add_one` a simp lemma, i.e. write `x + 1` instead of `succ x`. We have the typeclass `SuccAddOrder` which can be used to transfer the relevant theorems from `succ x` to the `x + 1` spelling.
…unity#35284)

and versions for `(m)fderivWithin` versions. This generalises the existing lemmas `(m)differentiableAt_of_isInvertible_(m)fderiv` and friends.

Extracted from leanprover-community#35078; from the path to immersions, embeddings and submanifolds.
…y#35476)

We insert a newline between the end of markdown lists and following text. In the absence of these newlines, doc-gen4 will render the following text as part of the last item of the list.
…35520)

This PR adds three Python scripts for managing `set_option backward.isDefEq.respectTransparency false in` when testing Lean PRs that change this behaviour:

- `scripts/dag_traversal.py` — reusable parallel DAG traversal library for Lean import graphs, with both library and CLI interfaces
- `scripts/add_backward_defeq.py` — adds `set_option` before failing declarations, traversing the DAG forward (roots first) so each module is only built after its imports are clean
- `scripts/remove_backward_defeq.py` — removes unnecessary `set_option` lines (skipping those with trailing comments), traversing the DAG backward (leaves first) to avoid invalidating cached builds

🤖 Prepared with Claude Code
Co-authored-by: bwangpj <70694994+bwangpj@users.noreply.github.com>
…35644)

This lets `measurability` solve goals like `MeasurableSet {x | f x ∈ s}`.
…y#35704)

Currently, this shows up [in the docs](https://leanprover-community.github.io/mathlib4_docs/Mathlib/RingTheory/Kaehler/Basic.html#KaehlerDifferential.kerTotal) as:

> The `S`-submodule of `S →₀ S` (the direct sum of copies of `S` indexed by `S`) generated by the relations:
> 1. `dx + dy = d(x + y)`
> 2. `x dy + y dx = d(x * y)`
> 3. `dr = 0` for `r ∈ R` where `db` is the unit in the copy of `S` with index `b`.
>
> This is the kernel of the surjection `Finsupp.linearCombination S Ω[S⁄R] S (KaehlerDifferential.D R S)`. See `KaehlerDifferential.kerTotal_eq` and `KaehlerDifferential.linearCombination_surjective`.
…ommunity#34643)

Given a model category `C`, we show that a few localizer morphisms are localized weak equivalences, which can be understood by saying that we obtain the same localized category (up to equivalence) by inverting weak equivalences in `C`, `CofibrantObject C`, `FibrantObject C` or `BifibrantObject C`.
@github-actions github-actions bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 2, 2026
@github-actions github-actions bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Mar 2, 2026
@ocfnash ocfnash self-assigned this Mar 4, 2026
@ocfnash
Copy link
Copy Markdown
Contributor

ocfnash commented Mar 27, 2026

Thanks for this and also for splitting out #37060 which hopefully we can merge soon.

Part of the reason we've been slow with review here is that there is a plan to deprecate PMF and instead just work with sums of Dirac masses. For example there are two open PRs in this direction #36374 and #36378 which are likely to be merged soon.

I have asked for some measure theory experts to weigh up the pros and cons one last time and I hope to return here (or let them do so) with concrete proposals for how to resolve the proposal here soon.

@pfaffelh
Copy link
Copy Markdown
Contributor Author

Thanks for the update! I welcome if PMF is deprecated. Let me mention that the MassFuntion α I want to introduce here is "only" a function α → ℝ≥0∞ (similar to PMF, but without any summability requirement). Its .toMeasure then gives a sum of diracs (similar to the other two PRs). This has two advantages:

  1. Once toMeasure is applied, the sum of diracs is nice to work with.
  2. MassFunction is still a LawfulMonad (as PMF), so I can e.g. use do-notation, bind, join and sequence, all of which have nice probabilistic meanings.

@pfaffelh
Copy link
Copy Markdown
Contributor Author

WIP +

@kex-y kex-y removed their assignment Mar 31, 2026
@ocfnash
Copy link
Copy Markdown
Contributor

ocfnash commented Apr 1, 2026

+WIP

(assuming this is what was intended here)

@github-actions github-actions bot added the WIP Work in progress label Apr 1, 2026
@ocfnash
Copy link
Copy Markdown
Contributor

ocfnash commented Apr 1, 2026

Thanks again for this work. I can't quite tell from these words what you're planning but I'll happily take a close look once you're ready for review again.

Note that #37060 has been delegated so it may help to resolve that first.

@ocfnash ocfnash added the awaiting-author A reviewer has asked the author a question or requested changes. label Apr 1, 2026
@pfaffelh
Copy link
Copy Markdown
Contributor Author

pfaffelh commented Apr 2, 2026

Yes, thanks for taking care! (I am on vacation, back at the computer next week.) There was a disussion in the geometric distribution PR, 36768. @EtienneC30 concluded "We could treat MassFunction like ProbabilityMeasure type where it should only be used when one wants to use the structure on the type (the topology in the case of ProbabilityMeasure or the monad and do notation in the case of MF) but should otherwise just use measure and the rest of the measure theory API." which found some agreement. My idea is to change the current PR in this direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author A reviewer has asked the author a question or requested changes. new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-measure-probability Measure theory / Probability theory WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.