77
88public import Mathlib.Control.Random
99public import Mathlib.MeasureTheory.Measure.GiryMonad
10- public meta import RandomDo.Util.Upstream
10+ public meta import RandomDo.Util.Analogue
1111
1212/-!
1313# Measurable Space Monad
@@ -38,7 +38,7 @@ section MeasurableSpaceMonad
3838/-- A functor on types with a `MeasurableSpace` instance. The `mMap` operator `<$>ₘ` is overloaded
3939via instances of this class. This class does not require proofs of the `MeasurableSpaceFunctor`
4040axioms. Proofs may be provided or required via the `LawfulMeasurableSpaceFunctor` class. -/
41- @ [upstream Functor]
41+ @ [analogue Functor]
4242class MeasurableSpaceFunctor (f : (α : Type u) → [MeasurableSpace α] → Type v) :
4343 Type (max (u+1 ) v) where
4444 /--
@@ -66,7 +66,7 @@ The `mPure` function is overloaded via `MeasurableSpacePure` instances.
6666
6767`MeasurableSpacePure` is typically accessed via `MeasurableSpaceMonad` instances, which extend it.
6868-/
69- @ [upstream Pure]
69+ @ [analogue Pure]
7070class MeasurableSpacePure (f : (α : Type u) → [MeasurableSpace α] → Type v) where
7171 /-- Given `a : α` where `α` has a `MeasurableSpace` instance, `mPure a : f α` represents an
7272 action that does nothing and returns a -/
@@ -77,7 +77,7 @@ The `>>=ₘ` operator is overloaded via instances of `MeasurableSpaceBind`.
7777
7878`MeasurableSpaceBind` is typically used via `MeasurableSpaceMonad`, which extends it.
7979-/
80- @ [upstream Bind]
80+ @ [analogue Bind]
8181class MeasurableSpaceBind (m : (α : Type u) → [MeasurableSpace α] → Type v) where
8282 /--
8383 Sequences two computations, allowing the second to depend on the value computed by the first.
@@ -91,7 +91,7 @@ class MeasurableSpaceBind (m : (α : Type u) → [MeasurableSpace α] → Type v
9191
9292/-- A monad on types with a `MeasurableSpace` instance. This abstraction allows the user to write
9393code that depends on "random" side-effects -/
94- @ [upstream Monad]
94+ @ [analogue Monad]
9595class MeasurableSpaceMonad (m : (α : Type u) → [MeasurableSpace α] → Type v) :
9696 Type (max (u+1 ) v)
9797 extends MeasurableSpaceFunctor m, MeasurableSpacePure m, MeasurableSpaceBind m where
@@ -100,12 +100,12 @@ class MeasurableSpaceMonad (m : (α : Type u) → [MeasurableSpace α] → Type
100100variable {m : (α : Type u) → [MeasurableSpace α] → Type v} {α β : Type u}
101101 [MeasurableSpace α] [MeasurableSpace β]
102102
103- @ [upstream _root_.bind_congr]
103+ @ [analogue _root_.bind_congr]
104104theorem MeasurableSpaceBind.bind_congr [MeasurableSpaceBind m] {x : m α} {f g : α → m β}
105105 (h : ∀ a, f a = g a) : x >>=ₘ f = x >>=ₘ g := by
106106 simp [funext h]
107107
108- @ [upstream _root_.map_congr]
108+ @ [analogue _root_.map_congr]
109109theorem MeasurableSpaceFunctor.map_congr [MeasurableSpaceFunctor m] {x : m α} {f g : α → β}
110110 (h : ∀ a, f a = g a) : (f <$>ₘ x : m β) = g <$>ₘ x := by
111111 simp [funext h]
@@ -117,7 +117,7 @@ section Lawful
117117open MeasurableSpaceFunctor
118118
119119/-- A `MeasurableSpaceFunctor` satisfies the measurable space functor laws. -/
120- @ [upstream LawfulFunctor]
120+ @ [analogue LawfulFunctor]
121121class LawfulMeasurableSpaceFunctor
122122 (f : (α : Type u) → [MeasurableSpace α] → Type v) [MeasurableSpaceFunctor f]
123123 [∀ α, [MeasurableSpace α] → MeasurableSpace (f α)] : Prop where
@@ -143,10 +143,10 @@ variable {f : (α : Type u) → [MeasurableSpace α] → Type v} [MeasurableSpac
143143 [∀ α, [MeasurableSpace α] → MeasurableSpace (f α)] [LawfulMeasurableSpaceFunctor f]
144144 {α β γ : Type u} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
145145
146- @ [upstream id_map', simp]
146+ @ [analogue id_map', simp]
147147theorem id_mMap' (x : f α) : (fun a => a) <$>ₘ x = x := id_mMap x
148148
149- @ [upstream Functor.map_map, simp]
149+ @ [analogue Functor.map_map, simp]
150150theorem mMap_mMap {g₀ : α → β} {g₁ : β → γ} (x : f α)
151151 (hg₀ : Measurable g₀) (hg₁ : Measurable g₁) :
152152 g₁ <$>ₘ g₀ <$>ₘ x = (fun a => g₁ (g₀ a)) <$>ₘ x :=
@@ -155,7 +155,7 @@ theorem mMap_mMap {g₀ : α → β} {g₁ : β → γ} (x : f α)
155155open MeasurableSpaceBind MeasurableSpacePure MeasurableSpaceFunctor
156156
157157/-- A `MeasurableSpaceMonad` satisfies the measurable space monad laws. -/
158- @ [upstream LawfulMonad]
158+ @ [analogue LawfulMonad]
159159class LawfulMeasurableSpaceMonad
160160 (m : (α : Type u) → [MeasurableSpace α] → Type v) [MeasurableSpaceMonad m]
161161 [∀ α, [MeasurableSpace α] → MeasurableSpace (m α)] : Prop
@@ -198,32 +198,32 @@ variable {m : (α : Type u) → [MeasurableSpace α] → Type v} [MeasurableSpac
198198 [∀ α, [MeasurableSpace α] → MeasurableSpace (m α)] [LawfulMeasurableSpaceMonad m]
199199 {α β γ : Type u} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
200200
201- @ [upstream LawfulApplicative.map_pure, simp]
201+ @ [analogue LawfulApplicative.map_pure, simp]
202202theorem mMap_mPure {f : α → β} (hf : Measurable f) (x : α) :
203203 f <$>ₘ (mPure x : m α) = mPure (f x) := by
204204 rw [← mBind_mPure_comp hf, mPure_mBind _ (by fun_prop)]
205205
206- @ [upstream bind_pure, simp]
206+ @ [analogue bind_pure, simp]
207207theorem mBind_mPure (x : m α) : x >>=ₘ mPure = x := by
208208 change x >>=ₘ (fun a => (mPure (id a))) = x
209209 rw [mBind_mPure_comp (by fun_prop), id_mMap]
210210
211- @ [upstream map_eq_pure_bind]
211+ @ [analogue map_eq_pure_bind]
212212theorem mMap_eq_mPure_mBind {f : α → β} (hf : Measurable f) (x : m α) :
213213 f <$>ₘ x = x >>=ₘ fun a => mPure (f a) := by
214214 rw [← mBind_mPure_comp hf x]
215215
216- @ [upstream bind_pure_unit]
216+ @ [analogue bind_pure_unit]
217217theorem mBind_mPure_unit {x : m PUnit} : (x >>=ₘ fun _ => mPure ⟨⟩) = x := by rw [mBind_mPure]
218218
219- @ [upstream map_bind, simp]
219+ @ [analogue map_bind, simp]
220220theorem mMap_mBind {f : β → γ} (hf : Measurable f) (x : m α)
221221 {g : α → m β} (hg : Measurable g) :
222222 f <$>ₘ (x >>=ₘ g) = x >>=ₘ fun a => f <$>ₘ g a := by
223223 rw [← mBind_mPure_comp hf, mBind_assoc _ hg (by fun_prop)]
224224 simp (disch := fun_prop) [mBind_mPure_comp]
225225
226- @ [upstream bind_map_left, simp]
226+ @ [analogue bind_map_left, simp]
227227theorem mBind_mMap_left {f : α → β} (hf : Measurable f) (x : m α)
228228 {g : β → m γ} (hg : Measurable g) :
229229 ((f <$>ₘ x) >>=ₘ fun b => g b) = (x >>=ₘ fun a => g (f a)) := by
@@ -247,7 +247,7 @@ instance instMeasurableSpace {β : Type u} [mβ : MeasurableSpace β] :
247247/--
248248Monadic iteration in `rdo`-blocks, using the `for x in xs` notation.
249249-/
250- @ [upstream ForIn]
250+ @ [analogue ForIn]
251251class MeasurableSpaceForIn (ρ : Type uρ) (α : outParam (Type uα)) where
252252 /--
253253 Monadically iterates over the contents of a collection `xs`, with a local state `b` and the
@@ -259,7 +259,7 @@ class MeasurableSpaceForIn (ρ : Type uρ) (α : outParam (Type uα)) where
259259/--
260260Monadic iteration in `rdo`-blocks with a membership proof, using the `for h : x in xs` notation.
261261-/
262- @ [upstream ForIn']
262+ @ [analogue ForIn']
263263class MeasurableSpaceForIn' (ρ : Type uρ) (α : outParam (Type uα))
264264 (d : outParam (Membership α ρ)) where
265265 /--
@@ -270,7 +270,7 @@ class MeasurableSpaceForIn' (ρ : Type uρ) (α : outParam (Type uα))
270270 forIn' {β : Type u} [MeasurableSpace β] (xs : ρ) (b : β)
271271 (f : (a : α) → a ∈ xs → β → m (ForInStep β)) : m β
272272
273- @ [upstream instForInOfForIn', simps]
273+ @ [analogue instForInOfForIn', simps]
274274instance (priority := 500 ) instMeasurableSpaceForInOfForIn'
275275 {ρ : Type uρ} {α : Type uα} {d : Membership α ρ} [MeasurableSpaceForIn' m ρ α d] :
276276 MeasurableSpaceForIn m ρ α where
0 commit comments