Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion RandomDo/Measurable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def Vector.measurableEquivTuple {n : ℕ} : Vector α n ≃ᵐ (Fin n → α) wh
ext
simp

instance : MeasurableSpace (Option α) := MeasurableSpace.map some inferInstance
instance instMeasurableSpaceOption : MeasurableSpace (Option α) :=
MeasurableSpace.map some inferInstance

theorem measurableSet_option_iff {s : Set (Option α)} :
MeasurableSet s ↔ MeasurableSet (some ⁻¹' s) := Iff.rfl
Expand Down
12 changes: 6 additions & 6 deletions RandomDo/Monad/ForInInstances.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ section MeasurableSpace

variable {α : Type*} [MeasurableSpace α]

instance : MeasurableSpace (List α) :=
instance instMeasurableSpaceList : MeasurableSpace (List α) :=
MeasurableSpace.comap List.equivSigmaTuple inferInstance

instance : MeasurableSpace (Array α) :=
instance instMeasurableSpaceArray : MeasurableSpace (Array α) :=
MeasurableSpace.comap Array.toList inferInstance

instance {n : ℕ} : MeasurableSpace (Vector α n) :=
instance instMeasurableSpaceVector {n : ℕ} : MeasurableSpace (Vector α n) :=
MeasurableSpace.comap Vector.toArray inferInstance

@[fun_prop]
Expand All @@ -52,7 +52,7 @@ section Array
{β : Type u} [mβ : MeasurableSpace β]
(as : Array α) (b : β) (f : (a : α) → a ∈ as → β → m (ForInStep β)) : m β :=
let sz := as.usize
let rec @[specialize] loop (i : USize) (b : β) : m β := rdo
let rec @[specialize, nolint docBlame] loop (i : USize) (b : β) : m β := rdo
if i < sz then
let a := as.uget i lcProof
match (← f a lcProof b) with
Expand All @@ -67,7 +67,7 @@ section Array
protected def Array.measurableSpaceForIn' [MeasurableSpaceMonad m]
{β : Type u} [mβ : MeasurableSpace β]
(as : Array α) (b : β) (f : (a : α) → a ∈ as → β → m (ForInStep β)) : m β :=
let rec loop (i : Nat) (h : i ≤ as.size) (b : β) : m β := rdo
let rec @[nolint docBlame] loop (i : Nat) (h : i ≤ as.size) (b : β) : m β := rdo
match i, h with
| 0, _ => mPure b
| i+1, h =>
Expand Down Expand Up @@ -97,7 +97,7 @@ variable {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] [Ring α]
protected def List.measurableSpaceForIn' [MeasurableSpaceMonad m]
{β : Type u} [mβ : MeasurableSpace β] (as : @& List α) (init : β)
(f : (a : α) → a ∈ as → β → m (ForInStep β)) : m β :=
let rec @[specialize]
let rec @[specialize, nolint docBlame]
loop : (as' : @& List α) → (b : β) → Exists (fun bs => bs ++ as' = as) → m β
| [], b, _ => mPure b
| a::as', b, h => rdo
Expand Down
2 changes: 2 additions & 0 deletions RandomDo/Monad/Instances.lean
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ open Function
/-- A monad for random number generation. -/
structure RandomM (Ω : Type w) [MeasurableSpace Ω] (P : Measure Ω)
(α : Type u) [MeasurableSpace α] where
/-- Draws a value from a state of the source of randomness, and hands back the state left for the
next draw. -/
sample : Ω → α × Ω
measurePreserving : MeasurePreserving sample P ((Measure.map (Prod.fst ∘ sample) P).prod P)

Expand Down
2 changes: 0 additions & 2 deletions RandomDo/Monad/MeasurableSpace.lean
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ variable {f : (α : Type u) → [MeasurableSpace α] → Type v} [MeasurableSpac
g₁ <$>ₘ g₀ <$>ₘ x = (fun a => g₁ (g₀ a)) <$>ₘ x :=
(comp_mMap x hg₀ hg₁).symm

@[simp] theorem mMap_unit {a : f PUnit} : (fun _ => PUnit.unit) <$>ₘ a = a := by simp

open MeasurableSpaceBind MeasurableSpacePure MeasurableSpaceFunctor

/-- A `MeasurableSpaceMonad` satisfies the measurable space monad laws. -/
Expand Down
1 change: 1 addition & 0 deletions Test/Common.lean
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module

public import RandomDo
public import Mathlib.Probability.Distributions.Bernoulli

set_option linter.style.header false

Expand Down
3 changes: 2 additions & 1 deletion lakefile.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name = "RandomDo"
defaultTargets = ["RandomDo", "Test"]
defaultTargets = ["RandomDo"]
lintDriver = "batteries/runLinter"
testDriver = "Test"

[leanOptions]
pp.unicode.fun = true
Expand Down