# Measure spaces #

THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.

The definition of a measure and a measure space are in `measure_theory.measure_space_def`

, with
only a few basic properties. This file provides many more properties of these objects.
This separation allows the measurability tactic to import only the file `measure_space_def`

, and to
be available in `measure_space`

(through `measurable_space`

).

Given a measurable space `α`

, a measure on `α`

is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:

`μ ∅ = 0`

;`μ`

is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets.

Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure.

Measures on `α`

form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`

.

We introduce the following typeclasses for measures:

`is_probability_measure μ`

:`μ univ = 1`

;`is_finite_measure μ`

:`μ univ < ∞`

;`sigma_finite μ`

: there exists a countable collection of sets that cover`univ`

where`μ`

is finite;`is_locally_finite_measure μ`

:`∀ x, ∃ s ∈ 𝓝 x, μ s < ∞`

;`has_no_atoms μ`

:`∀ x, μ {x} = 0`

; possibly should be redefined as`∀ s, 0 < μ s → ∃ t ⊆ s, 0 < μ t ∧ μ t < μ s`

.

Given a measure, the null sets are the sets where `μ s = 0`

, where `μ`

denotes the corresponding
outer measure (so `s`

might not be measurable). We can then define the completion of `μ`

as the
measure on the least `σ`

-algebra that also contains all null sets, by defining the measure to be `0`

on the null sets.

## Main statements #

`completion`

is the completion of a measure to all null measurable sets.`measure.of_measurable`

and`outer_measure.to_measure`

are two important ways to define a measure.

## Implementation notes #

Given `μ : measure α`

, `μ s`

is the value of the *outer measure* applied to `s`

.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.

You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient:

`measure.of_measurable`

is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above.`outer_measure.to_measure`

is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable.

To prove that two measures are equal, there are multiple options:

`ext`

: two measures are equal if they are equal on all measurable sets.`ext_of_generate_from_of_Union`

: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general`ext_of_generate_from_of_cover`

`ext_of_generate_finite`

: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of`ext_of_generate_from_of_Union`

using`C ∪ {univ}`

, but is easier to work with.

A `measure_space`

is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`

.

## References #

- https://en.wikipedia.org/wiki/Measure_(mathematics)
- https://en.wikipedia.org/wiki/Complete_measure
- https://en.wikipedia.org/wiki/Almost_everywhere

## Tags #

measure, almost everywhere, measure space, completion, null set, null measurable set

See also `measure_theory.ae_restrict_uIoc_iff`

.

The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets.

If `s`

is a countable set, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`

.

If `s`

is a `finset`

, then the measure of its preimage can be found as the sum of measures
of the fibers `f ⁻¹' {y}`

.

If `s ⊆ t`

, `μ t ≤ μ s`

, `μ t ≠ ∞`

, and `s`

is measurable, then `s =ᵐ[μ] t`

.

Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`

, then
one of the intersections `s i ∩ s j`

is not empty.

Pigeonhole principle for measure spaces: if `s`

is a `finset`

and
`∑ i in s, μ (t i) > μ univ`

, then one of the intersections `t i ∩ t j`

is not empty.

If two sets `s`

and `t`

are included in a set `u`

, and `μ s + μ t > μ u`

,
then `s`

intersects `t`

. Version assuming that `t`

is measurable.

If two sets `s`

and `t`

are included in a set `u`

, and `μ s + μ t > μ u`

,
then `s`

intersects `t`

. Version assuming that `s`

is measurable.

Continuity from below: the measure of the union of a directed sequence of (not necessarily -measurable) sets is the supremum of the measures.

Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the infimum of the measures.

Continuity from below: the measure of the union of an increasing sequence of measurable sets is the limit of the measures.

Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures.

The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures.

One direction of the **Borel-Cantelli lemma**: if (sᵢ) is a sequence of sets such
that `∑ μ sᵢ`

is finite, then the limit superior of the `sᵢ`

is a null set.

Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable.

## Equations

- m.to_measure h = measure_theory.measure.of_measurable (λ (s : set α) (_x : measurable_set s), ⇑m s) _ _

If `u`

is a superset of `t`

with the same (finite) measure (both sets possibly non-measurable),
then for any measurable set `s`

one also has `μ (t ∩ s) = μ (u ∩ s)`

.

The measurable superset `to_measurable μ t`

of `t`

(which has the same measure as `t`

)
satisfies, for any measurable set `s`

, the equality `μ (to_measurable μ t ∩ s) = μ (u ∩ s)`

.
Here, we require that the measure of `t`

is finite. The conclusion holds without this assumption
when the measure is sigma_finite, see `measure_to_measurable_inter_of_sigma_finite`

.

### The `ℝ≥0∞`

-module of measures #

## Equations

- measure_theory.measure.has_zero = {zero := {to_outer_measure := 0, m_Union := _, trimmed := _}}

## Equations

## Equations

- measure_theory.measure.has_add = {add := λ (μ₁ μ₂ : measure_theory.measure α), {to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure, m_Union := _, trimmed := _}}

## Equations

- measure_theory.measure.has_smul = {smul := λ (c : R) (μ : measure_theory.measure α), {to_outer_measure := c • μ.to_outer_measure, m_Union := _, trimmed := _}}

## Equations

- measure_theory.measure.mul_action = function.injective.mul_action measure_theory.measure.to_outer_measure measure_theory.measure.to_outer_measure_injective measure_theory.measure.mul_action._proof_1

## Equations

- measure_theory.measure.add_comm_monoid = function.injective.add_comm_monoid measure_theory.measure.to_outer_measure measure_theory.measure.to_outer_measure_injective measure_theory.measure.zero_to_outer_measure measure_theory.measure.add_to_outer_measure measure_theory.measure.add_comm_monoid._proof_2

Coercion to function as an additive monoid homomorphism.

## Equations

## Equations

- measure_theory.measure.distrib_mul_action = function.injective.distrib_mul_action {to_fun := measure_theory.measure.to_outer_measure _inst_6, map_zero' := _, map_add' := _} measure_theory.measure.to_outer_measure_injective measure_theory.measure.distrib_mul_action._proof_1

## Equations

- measure_theory.measure.module = function.injective.module R {to_fun := measure_theory.measure.to_outer_measure _inst_6, map_zero' := _, map_add' := _} measure_theory.measure.to_outer_measure_injective measure_theory.measure.module._proof_1

### The complete lattice of measures #

Measures are partially ordered.

The definition of less equal here is equivalent to the definition without the
measurable set condition, and this is shown by `measure.le_iff'`

. It is defined
this way since, to prove `μ ≤ ν`

, we may simply `intros s hs`

instead of rewriting followed
by `intros s hs`

.

## Equations

- measure_theory.measure.partial_order = {le := λ (m₁ m₂ : measure_theory.measure α), ∀ (s : set α), measurable_set s → ⇑m₁ s ≤ ⇑m₂ s, lt := preorder.lt._default (λ (m₁ m₂ : measure_theory.measure α), ∀ (s : set α), measurable_set s → ⇑m₁ s ≤ ⇑m₂ s), le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _}

## Equations

## Equations

- measure_theory.measure.complete_semilattice_Inf = {le := partial_order.le measure_theory.measure.partial_order, lt := partial_order.lt measure_theory.measure.partial_order, le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, Inf := has_Inf.Inf measure_theory.measure.has_Inf, Inf_le := _, le_Inf := _}

## Equations

- measure_theory.measure.complete_lattice = {sup := complete_lattice.sup (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), le := complete_lattice.le (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), lt := complete_lattice.lt (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), le_refl := _, le_trans := _, lt_iff_le_not_le := _, le_antisymm := _, le_sup_left := _, le_sup_right := _, sup_le := _, inf := complete_lattice.inf (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), inf_le_left := _, inf_le_right := _, le_inf := _, Sup := complete_lattice.Sup (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), le_Sup := _, Sup_le := _, Inf := complete_lattice.Inf (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), Inf_le := _, le_Inf := _, top := complete_lattice.top (complete_lattice_of_complete_semilattice_Inf (measure_theory.measure α)), bot := 0, le_top := _, bot_le := _}

### Pushforward and pullback #

Lift a linear map between `outer_measure`

spaces such that for each measure `μ`

every measurable
set is caratheodory-measurable w.r.t. `f μ`

to a linear map between `measure`

spaces.

## Equations

- measure_theory.measure.lift_linear f hf = {to_fun := λ (μ : measure_theory.measure α), (⇑f μ.to_outer_measure).to_measure _, map_add' := _, map_smul' := _}

The pushforward of a measure as a linear map. It is defined to be `0`

if `f`

is not
a measurable function.

## Equations

- measure_theory.measure.mapₗ f = dite (measurable f) (λ (hf : measurable f), measure_theory.measure.lift_linear (measure_theory.outer_measure.map f) _) (λ (hf : ¬measurable f), 0)

The pushforward of a measure. It is defined to be `0`

if `f`

is not an almost everywhere
measurable function.

## Equations

- measure_theory.measure.map f μ = dite (ae_measurable f μ) (λ (hf : ae_measurable f μ), ⇑(measure_theory.measure.mapₗ (ae_measurable.mk f hf)) μ) (λ (hf : ¬ae_measurable f μ), 0)

We can evaluate the pushforward on measurable sets. For non-measurable sets, see
`measure_theory.measure.le_map_apply`

and `measurable_equiv.map_apply`

.

Even if `s`

is not measurable, we can bound `map f μ s`

from below.
See also `measurable_equiv.map_apply`

.

Even if `s`

is not measurable, `map f μ s = 0`

implies that `μ (f ⁻¹' s) = 0`

.

Pullback of a `measure`

as a linear map. If `f`

sends each measurable set to a measurable
set, then for each measurable set `s`

we have `comapₗ f μ s = μ (f '' s)`

.

If the linearity is not needed, please use `comap`

instead, which works for a larger class of
functions.

## Equations

- measure_theory.measure.comapₗ f = dite (function.injective f ∧ ∀ (s : set α), measurable_set s → measurable_set (f '' s)) (λ (hf : function.injective f ∧ ∀ (s : set α), measurable_set s → measurable_set (f '' s)), measure_theory.measure.lift_linear (measure_theory.outer_measure.comap f) _) (λ (hf : ¬(function.injective f ∧ ∀ (s : set α), measurable_set s → measurable_set (f '' s))), 0)

Pullback of a `measure`

. If `f`

sends each measurable set to a null-measurable set,
then for each measurable set `s`

we have `comap f μ s = μ (f '' s)`

.

## Equations

- measure_theory.measure.comap f μ = dite (function.injective f ∧ ∀ (s : set α), measurable_set s → measure_theory.null_measurable_set (f '' s) μ) (λ (hf : function.injective f ∧ ∀ (s : set α), measurable_set s → measure_theory.null_measurable_set (f '' s) μ), (⇑(measure_theory.outer_measure.comap f) μ.to_outer_measure).to_measure _) (λ (hf : ¬(function.injective f ∧ ∀ (s : set α), measurable_set s → measure_theory.null_measurable_set (f '' s) μ)), 0)

### Subtype of a measure space #

## Equations

- measure_theory.measure.subtype.measure_space = {to_measurable_space := {measurable_set' := subtype.measurable_space.measurable_set', measurable_set_empty := _, measurable_set_compl := _, measurable_set_Union := _}, volume := measure_theory.measure.comap subtype.val measure_theory.measure_space.volume}

### Restricting a measure #

Restrict a measure `μ`

to a set `s`

as an `ℝ≥0∞`

-linear map.

Restrict a measure `μ`

to a set `s`

.

## Equations

- μ.restrict s = ⇑(measure_theory.measure.restrictₗ s) μ

## Instances for `measure_theory.measure.restrict`

- measure_theory.restrict.is_finite_measure
- measure_theory.is_finite_measure_restrict
- measure_theory.measure.restrict.has_no_atoms
- measure_theory.restrict.sigma_finite
- real.is_finite_measure_restrict_Icc
- real.is_finite_measure_restrict_Ico
- real.is_finite_measure_restrict_Ioc
- real.is_finite_measure_restrict_Ioo
- measure_theory.ae_fin_strongly_measurable.sigma_finite_restrict
- measure_theory.measure.restrict.measure_theory.is_finite_measure

This lemma shows that `restrict`

and `to_outer_measure`

commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures.

If `t`

is a measurable set, then the measure of `t`

with respect to the restriction of
the measure to `s`

equals the outer measure of `t ∩ s`

. An alternate version requiring that `s`

be measurable instead of `t`

exists as `measure.restrict_apply'`

.

Restriction of a measure to a subset is monotone both in set and in measure.

Restriction of a measure to a subset is monotone both in set and in measure.

If `s`

is a measurable set, then the outer measure of `t`

with respect to the restriction of
the measure to `s`

equals the outer measure of `t ∩ s`

. This is an alternate version of
`measure.restrict_apply`

, requiring that `s`

is measurable instead of `t`

.

The restriction of the pushforward measure is the pushforward of the restriction. For a version
assuming only `ae_measurable`

, see `restrict_map_of_ae_measurable`

.

If two measures agree on all measurable subsets of `s`

and `t`

, then they agree on all
measurable subsets of `s ∪ t`

.

This lemma shows that `Inf`

and `restrict`

commute for measures.

### Extensionality results #

Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `Union`

).

**Alias** of the reverse direction of `measure_theory.measure.ext_iff_of_Union_eq_univ`

.

Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `bUnion`

).

**Alias** of the reverse direction of `measure_theory.measure.ext_iff_of_bUnion_eq_univ`

.

Two measures are equal if they have equal restrictions on a spanning collection of sets
(formulated using `sUnion`

).

**Alias** of the reverse direction of `measure_theory.measure.ext_iff_of_sUnion_eq_univ`

.

Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `sUnion`

.

Two measures are equal if they are equal on the π-system generating the σ-algebra,
and they are both finite on a increasing spanning sequence of sets in the π-system.
This lemma is formulated using `Union`

.
`finite_spanning_sets_in.ext`

is a reformulation of this lemma.

The dirac measure.

## Equations

## Instances for `measure_theory.measure.dirac`

## Equations

Sum of an indexed family of measures.

## Equations

- measure_theory.measure.sum f = (measure_theory.outer_measure.sum (λ (i : ι), (f i).to_outer_measure)).to_measure _

## Instances for `measure_theory.measure.sum`

If `f`

is a map with countable codomain, then `μ.map f`

is a sum of Dirac measures.