Skip to content
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
992890f
finite probability spaces & random variables
malarbol Oct 24, 2025
d941a54
constant random variables
malarbol Oct 24, 2025
9df4d7b
fix link
malarbol Oct 24, 2025
b3cad75
Merge branch 'master' into probability-theory
malarbol Oct 24, 2025
c826867
rename module finite-probability-theory
malarbol Oct 24, 2025
6f03269
fix links
malarbol Oct 24, 2025
68bfd70
format
malarbol Oct 24, 2025
e4e361a
typo
malarbol Oct 24, 2025
380bb36
rename measure -> distribution
malarbol Oct 24, 2025
424c0f8
add references
malarbol Oct 24, 2025
58f9c47
fix link
malarbol Oct 24, 2025
76ac71b
zero-is-not-one-R
malarbol Oct 24, 2025
1c306a6
finite probability spaces are inhabited
malarbol Oct 24, 2025
d4082d6
atomic random variables
malarbol Oct 24, 2025
aeb66d1
fix name
malarbol Oct 24, 2025
12c60fd
explicit references sections
malarbol Oct 24, 2025
1538f5d
Update references.bib
malarbol Oct 24, 2025
883489e
rephrase non-empty consequence/hypothesis for finite probability spaces
malarbol Oct 24, 2025
a6de932
re-rephrase
malarbol Oct 24, 2025
ea39ce4
Update src/finite-probability-theory/finite-probability-spaces.lagda.md
malarbol Oct 24, 2025
384d6bc
Update src/finite-probability-theory/finite-probability-spaces.lagda.md
malarbol Oct 25, 2025
745c376
Update src/finite-probability-theory/probability-distributions-on-fin…
malarbol Oct 25, 2025
e040b72
Update src/finite-probability-theory/positive-distributions-on-finite…
malarbol Oct 25, 2025
50ee095
Use Pr instead of \mu
malarbol Oct 25, 2025
782074f
format
malarbol Oct 25, 2025
83646d0
Merge branch 'master' into probability-theory
malarbol Oct 25, 2025
9c465a4
rename real-random-variable
malarbol Oct 25, 2025
9fe7c83
use prop-double-negation-elim-is-inhabited-or-empty
malarbol Oct 25, 2025
ef5c7d0
fix link
malarbol Oct 25, 2025
9143114
fix link
malarbol Oct 25, 2025
cd0fcae
Merge branch 'master' into probability-theory
malarbol Oct 25, 2025
e6366f8
Merge branch 'master' into probability-theory
malarbol Nov 6, 2025
4a98f17
Merge branch 'master' into probability-theory
malarbol Nov 6, 2025
9026548
Merge branch 'master' into probability-theory
malarbol Nov 7, 2025
da98060
Merge branch 'master' into probability-theory
malarbol Nov 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ @misc{Awodey22
keywords = {Mathematics - Category Theory, Mathematics - Logic},
}

@misc{Babai00,
title = {Finite Probablity Spaces},
author = {Babai, L\'aszl\'o},
year = 2000,
month = apr,
url = {https://people.cs.uchicago.edu/~laci/reu02/prob.pdf},
}

@article{BauerTaylor2009,
title = {The {{Dedekind}} Reals in Abstract {{Stone}} Duality},
author = {Bauer, Andrej and Taylor, Paul},
Expand Down
11 changes: 11 additions & 0 deletions src/finite-probability-theory.lagda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Finite probability theory

```agda
module finite-probability-theory where

open import finite-probability-theory.expected-value-random-real-variables-finite-probability-spaces public
open import finite-probability-theory.finite-probability-spaces public
open import finite-probability-theory.positive-distributions-on-finite-types public
open import finite-probability-theory.probability-distributions-on-finite-types public
open import finite-probability-theory.random-real-variables-finite-probability-spaces public
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Expected value of random real variables in finite probability spaces

```agda
module finite-probability-theory.expected-value-random-real-variables-finite-probability-spaces where
```

<details><summary>Imports</summary>

```agda
open import finite-probability-theory.finite-probability-spaces
open import finite-probability-theory.positive-distributions-on-finite-types
open import finite-probability-theory.probability-distributions-on-finite-types
open import finite-probability-theory.random-real-variables-finite-probability-spaces

open import foundation.dependent-pair-types
open import foundation.empty-types
open import foundation.function-types
open import foundation.identity-types
open import foundation.inhabited-types
open import foundation.propositions
open import foundation.sets
open import foundation.subtypes
open import foundation.transport-along-identifications
open import foundation.universe-levels

open import group-theory.sums-of-finite-families-of-elements-abelian-groups

open import real-numbers.addition-real-numbers
open import real-numbers.dedekind-real-numbers
open import real-numbers.multiplication-real-numbers
open import real-numbers.positive-real-numbers
open import real-numbers.rational-real-numbers
open import real-numbers.strict-inequality-real-numbers

open import univalent-combinatorics.finite-types
```

</details>

## Idea

The
{{#concept "expected value" Disambiguation="of a random real variable in a finite probability space" Agda=expected-value-random-real-variable-Finite-Probability-Space}}
of a
[random real variable](finite-probability-theory.random-real-variables-finite-probability-spaces.md)
`X` in a
[finite probability space](finite-probability-theory.finite-probability-spaces.md)
`(Ω , μ)` is the
[sum](group-theory.sums-of-finite-families-of-elements-abelian-groups.md)

$$
∑_{x ∈ Ω} X(x)μ(x).
$$

Our definition follows Definition 2.2 of {{#cite Babai00}}.

## Definitions

### Expected value of a random real variable in a finite probability space
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems probably true of any rational ring, FWIW? It might help variables more usefully expressed in terms of integers and rational numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it too but I think I'd need "rational-positive-distributions" for that (I'd need the coefficients μ(x) to be rational); maybe it would be a good thing to have. I can give it a go or feel free to join in if you want to!

On the other hand, we'll probably have the concept of "real ring" sometimes in the future so we'll be able to consider random variables in real rings then.

Copy link
Collaborator Author

@malarbol malarbol Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed you made quite some progress on real multiplication etc. Do we have the ring of real numbers already or are there still some missing laws? I suspect distributivity must be quite painful 🫤 EDIT: I see distributivity is already there 🎊

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] Do we have the ring of real numbers already or are there still some missing laws? [...]

you're probably working on large rings and such. Let's wait then. I think we need som ring structure on ℝ to follow with more interesting results.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, see #1586. The ring at lzero was originally contributed, but in the end it was concluded to wait for the large ring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. I'll just wait then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, do you mean you will wait with finishing this PR until that one has been merged? If so, please mark this one as a draft.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, do you mean you will wait with finishing this PR until that one has been merged? If so, please mark this one as a draft.

Yes. One of the endgoal is to prove that the space of real random variables is an ℝ-module and the expected value a linear map. For this I'll need more algebraic structure. And I'll need more time to figure out the level-polymorphic construction.

Thanks for your help anyways. Sorry for your time.


```agda
module _
{l : Level} (Ω : Finite-Probability-Space l)
(X : random-real-variable-Finite-Probability-Space Ω)
where

expected-value-random-real-variable-Finite-Probability-Space : ℝ lzero
expected-value-random-real-variable-Finite-Probability-Space =
sum-finite-Ab
( abelian-group-add-ℝ-lzero)
( finite-type-Finite-Probability-Space Ω)
( λ x →
mul-ℝ
( X x)
( real-distribution-Finite-Probability-Space Ω x))
```

## References

{{#bibliography}}
156 changes: 156 additions & 0 deletions src/finite-probability-theory/finite-probability-spaces.lagda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# Finite probability spaces

```agda
module finite-probability-theory.finite-probability-spaces where
```

<details><summary>Imports</summary>

```agda
open import finite-probability-theory.positive-distributions-on-finite-types
open import finite-probability-theory.probability-distributions-on-finite-types

open import foundation.coproduct-types
open import foundation.dependent-pair-types
open import foundation.empty-types
open import foundation.function-types
open import foundation.identity-types
open import foundation.inhabited-types
open import foundation.propositions
open import foundation.sets
open import foundation.subtypes
open import foundation.transport-along-identifications
open import foundation.universe-levels

open import group-theory.sums-of-finite-families-of-elements-abelian-groups

open import real-numbers.addition-real-numbers
open import real-numbers.apartness-real-numbers
open import real-numbers.dedekind-real-numbers
open import real-numbers.positive-real-numbers
open import real-numbers.rational-real-numbers
open import real-numbers.strict-inequality-real-numbers

open import univalent-combinatorics.finite-types
open import univalent-combinatorics.inhabited-finite-types
```

</details>

## Idea

A {{#concept "finite probability space" Agda=Finite-Probability-Space}} is a
[finite type](univalent-combinatorics.finite-types.md) equipped with a
[probability distribution](finite-probability-theory.probability-distributions-on-finite-types.md).

Any finite probability space is [inhabited](foundation.inhabited-types.md).

Our definitions follows {{#cite Babai00}}, although, there it is assumed that
the underlying type is [nonempty](foundation-core.empty-types.md), but this
follows from the condition of having
[total measure](finite-probability-theory.positive-distributions-on-finite-types.md)
equal to 1.

## Definitions

### Finite probability spaces

```agda
Finite-Probability-Space : (l : Level) → UU (lsuc l)
Finite-Probability-Space l =
Σ ( Finite-Type l)
( probability-distribution-Finite-Type)

module _
{l : Level} (Ω : Finite-Probability-Space l)
where

finite-type-Finite-Probability-Space : Finite-Type l
finite-type-Finite-Probability-Space = pr1 Ω

type-Finite-Probability-Space : UU l
type-Finite-Probability-Space =
type-Finite-Type finite-type-Finite-Probability-Space

is-finite-type-Finite-Probability-Space :
is-finite type-Finite-Probability-Space
is-finite-type-Finite-Probability-Space =
is-finite-type-Finite-Type finite-type-Finite-Probability-Space

distribution-Finite-Probability-Space :
positive-distribution-Finite-Type finite-type-Finite-Probability-Space
distribution-Finite-Probability-Space = pr1 (pr2 Ω)

real-distribution-Finite-Probability-Space :
type-Finite-Probability-Space → ℝ lzero
real-distribution-Finite-Probability-Space =
real-positive-distribution-Finite-Type
( finite-type-Finite-Probability-Space)
( distribution-Finite-Probability-Space)

eq-one-total-measure-distribution-Finite-Probability-Space :
( total-measure-positive-distribution-Finite-Type
( finite-type-Finite-Probability-Space)
( distribution-Finite-Probability-Space)) =
one-ℝ
eq-one-total-measure-distribution-Finite-Probability-Space =
pr2 (pr2 Ω)
```

## Properties

### A finite probability space is nonempty

```agda
module _
{l : Level} (Ω : Finite-Probability-Space l)
where

is-nonempty-type-Finite-Probability-Space :
is-nonempty (type-Finite-Probability-Space Ω)
is-nonempty-type-Finite-Probability-Space =
zero-is-not-one-ℝ ∘ absurd-is-empty-Finite-Probability-Space
where

absurd-is-empty-Finite-Probability-Space :
is-empty (type-Finite-Probability-Space Ω) →
zero-ℝ = one-ℝ
absurd-is-empty-Finite-Probability-Space H =
( inv
( is-zero-total-measure-positive-distribution-is-empty-Finite-Type
( finite-type-Finite-Probability-Space Ω)
( distribution-Finite-Probability-Space Ω)
( H))) ∙
( eq-one-total-measure-distribution-Finite-Probability-Space Ω)
```

### A finite probability space is inhabited

```agda
module _
{l : Level} (Ω : Finite-Probability-Space l)
where

is-inhabited-type-Finite-Probability-Space :
is-inhabited (type-Finite-Probability-Space Ω)
is-inhabited-type-Finite-Probability-Space =
rec-coproduct
( id)
( ex-falso ∘ (is-nonempty-type-Finite-Probability-Space Ω))
( is-inhabited-or-empty-is-finite
( is-finite-type-Finite-Probability-Space Ω))

inhabited-type-Finite-Probability-Space : Inhabited-Type l
inhabited-type-Finite-Probability-Space =
( type-Finite-Probability-Space Ω ,
is-inhabited-type-Finite-Probability-Space)

inhabited-finite-type-Finite-Probability-Space : Inhabited-Finite-Type l
inhabited-finite-type-Finite-Probability-Space =
( finite-type-Finite-Probability-Space Ω ,
is-inhabited-type-Finite-Probability-Space)
```

## References

{{#bibliography}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Positive distributions on finite types

```agda
module finite-probability-theory.positive-distributions-on-finite-types where
```

<details><summary>Imports</summary>

```agda
open import foundation.empty-types
open import foundation.function-types
open import foundation.identity-types
open import foundation.universe-levels

open import group-theory.sums-of-finite-families-of-elements-abelian-groups

open import real-numbers.addition-real-numbers
open import real-numbers.dedekind-real-numbers
open import real-numbers.positive-real-numbers
open import real-numbers.rational-real-numbers

open import univalent-combinatorics.finite-types
```

</details>

## Idea

A
{{#concept "positive distribution" Disambiguation="on a finite type" Agda=positive-distribution-Finite-Type}}
on a [finite type](univalent-combinatorics.finite-types.md) is a function into
the [positive real numbers](real-numbers.positive-real-numbers.md).

The **total measure** of a positive-distribution `μ` on a finite type `Ω` is the
[sum](group-theory.sums-of-finite-families-of-elements-abelian-groups.md)

$$
∑_{x ∈ Ω} μ(x).
$$

## Definitions

### Positive distributions on finite types

```agda
module _
{l : Level} (Ω : Finite-Type l)
where

positive-distribution-Finite-Type : UU (lsuc lzero ⊔ l)
positive-distribution-Finite-Type = type-Finite-Type Ω ℝ⁺ lzero

real-positive-distribution-Finite-Type :
positive-distribution-Finite-Type type-Finite-Type Ω ℝ lzero
real-positive-distribution-Finite-Type μ = real-ℝ⁺ ∘ μ
```
Comment on lines 48 to 59
Copy link
Collaborator

@fredrik-bakke fredrik-bakke Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a universe level parameter in your definition here, and consequently everywhere else too

Suggested change
```agda
module _
{l : Level} (Ω : Finite-Type l)
where
positive-distribution-Finite-Type : UU (lsuc lzero ⊔ l)
positive-distribution-Finite-Type = type-Finite-Type Ω → ℝ⁺ lzero
real-positive-distribution-Finite-Type :
positive-distribution-Finite-Type → type-Finite-Type Ω → ℝ lzero
real-positive-distribution-Finite-Type μ = real-ℝ⁺ ∘ μ
```
```agda
module _
{l1 : Level} (l2 : Level) (Ω : Finite-Type l1)
where
positive-distribution-Finite-Type : UU (l1 ⊔ lsuc l2)
positive-distribution-Finite-Type = type-Finite-Type Ω → ℝ⁺ l2
module _
{l1 l2 : Level} (Ω : Finite-Type l1)
where
real-positive-distribution-Finite-Type :
positive-distribution-Finite-Type l2 Ω → type-Finite-Type Ω → ℝ l2
real-positive-distribution-Finite-Type μ = real-ℝ⁺ ∘ μ
```

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't introduce this level parameter now you'll probably hit your face against resizing problems later on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, your definitions should be in terms of at a universe level always. Always maximize the number of universe level parameters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out this way but since we only have the additive abelian group of real numbers at lzero, to define even the simplest thing like the total measure, I needed to restrict to lzero.

I think I'll mark this as a draft and wait for large algebraic structures and re-try this then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The large algebraic structures you need should be in.


### The total measure of a positive distribution on a finite type

```agda
module _
{l : Level} (Ω : Finite-Type l)
: positive-distribution-Finite-Type Ω)
where

total-measure-positive-distribution-Finite-Type : ℝ lzero
total-measure-positive-distribution-Finite-Type =
sum-finite-Ab
( abelian-group-add-ℝ-lzero)
( Ω)
( real-positive-distribution-Finite-Type Ω μ)
```

## Properties

### The total measure of a positive distribution on an empty type is zero

```agda
module _
{l : Level} (Ω : Finite-Type l) (μ : positive-distribution-Finite-Type Ω)
where

is-zero-total-measure-positive-distribution-is-empty-Finite-Type :
is-empty (type-Finite-Type Ω)
total-measure-positive-distribution-Finite-Type Ω μ = zero-ℝ
is-zero-total-measure-positive-distribution-is-empty-Finite-Type H =
eq-zero-sum-finite-is-empty-Ab
( abelian-group-add-ℝ-lzero)
( Ω)
( H)
( real-positive-distribution-Finite-Type Ω μ)
```
Loading