theorem
Std.Iterators.Iter.filterMapWithPostcondition_eq_toIter_filterMapWithPostcondition_toIterM
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
[Monad m]
{f : β → PostconditionT m (Option γ)}
:
theorem
Std.Iterators.Iter.mapWithPostcondition_eq_toIter_mapWithPostcondition_toIterM
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
[Monad m]
{f : β → PostconditionT m γ}
:
theorem
Std.Iterators.Iter.step_filterMapWithPostcondition
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
{n : Type w → Type w''}
{f : β → PostconditionT n (Option γ)}
[Monad n]
[LawfulMonad n]
[MonadLiftT m n]
:
(filterMapWithPostcondition f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let __do_lift ← (f out).operation
match __do_lift with
| ⟨none, h'⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterMapWithPostcondition f it') ⋯))
| ⟨some out', h'⟩ => pure (Shrink.deflate (PlausibleIterStep.yield (filterMapWithPostcondition f it') out' ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterMapWithPostcondition f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_filterWithPostcondition
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
{n : Type w → Type w''}
{f : β → PostconditionT n (ULift Bool)}
[Monad n]
[LawfulMonad n]
[MonadLiftT m n]
:
(filterWithPostcondition f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let __do_lift ← (f out).operation
match __do_lift with
| ⟨{ down := false }, h'⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterWithPostcondition f it') ⋯))
| ⟨{ down := true }, h'⟩ => pure (Shrink.deflate (PlausibleIterStep.yield (filterWithPostcondition f it') out ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterWithPostcondition f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_mapWithPostcondition
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
{n : Type w → Type w''}
{f : β → PostconditionT n γ}
[Monad n]
[LawfulMonad n]
[MonadLiftT m n]
:
(mapWithPostcondition f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let out' ← (f out).operation
pure (Shrink.deflate (PlausibleIterStep.yield (mapWithPostcondition f it') out'.val ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (mapWithPostcondition f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_filterMapM
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
{n : Type w → Type w''}
{β' : Type w}
{f : β → n (Option β')}
[Monad n]
[LawfulMonad n]
[MonadLiftT m n]
:
(filterMapM f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let __do_lift ← f out
match __do_lift with
| none => pure (Shrink.deflate (PlausibleIterStep.skip (filterMapM f it') ⋯))
| some out' => pure (Shrink.deflate (PlausibleIterStep.yield (filterMapM f it') out' ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterMapM f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_filterM
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
{m : Type w → Type w'}
{n : Type w → Type w''}
{f : β → n (ULift Bool)}
[Monad n]
[LawfulMonad n]
[MonadLiftT m n]
:
(filterM f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let __do_lift ← f out
match __do_lift with
| { down := false } => pure (Shrink.deflate (PlausibleIterStep.skip (filterM f it') ⋯))
| { down := true } => pure (Shrink.deflate (PlausibleIterStep.yield (filterM f it') out ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (filterM f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_mapM
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{n : Type w → Type w''}
{f : β → n γ}
[Monad n]
[LawfulMonad n]
:
(mapM f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => do
let out' ← f out
pure (Shrink.deflate (PlausibleIterStep.yield (mapM f it') out' ⋯))
| ⟨IterStep.skip it', h⟩ => pure (Shrink.deflate (PlausibleIterStep.skip (mapM f it') ⋯))
| ⟨IterStep.done, h⟩ => pure (Shrink.deflate (PlausibleIterStep.done ⋯))
theorem
Std.Iterators.Iter.step_filterMap
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{f : β → Option γ}
:
(filterMap f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ =>
match h' : f out with
| none => PlausibleIterStep.skip (filterMap f it') ⋯
| some out' => PlausibleIterStep.yield (filterMap f it') out' ⋯
| ⟨IterStep.skip it', h⟩ => PlausibleIterStep.skip (filterMap f it') ⋯
| ⟨IterStep.done, h⟩ => PlausibleIterStep.done ⋯
theorem
Std.Iterators.Iter.val_step_filterMap
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{f : β → Option γ}
:
(filterMap f it).step.val = match it.step.val with
| IterStep.yield it' out =>
match f out with
| none => IterStep.skip (filterMap f it')
| some out' => IterStep.yield (filterMap f it') out'
| IterStep.skip it' => IterStep.skip (filterMap f it')
| IterStep.done => IterStep.done
a weaker version of step_filterMap that does not use dependent match
theorem
Std.Iterators.Iter.step_map
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
{f : β → γ}
:
(map f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ => PlausibleIterStep.yield (map f it') (f out) ⋯
| ⟨IterStep.skip it', h⟩ => PlausibleIterStep.skip (map f it') ⋯
| ⟨IterStep.done, h⟩ => PlausibleIterStep.done ⋯
def
Std.Iterators.Iter.step_filter
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
{f : β → Bool}
:
(filter f it).step = match it.step with
| ⟨IterStep.yield it' out, h⟩ =>
if h' : f out = true then PlausibleIterStep.yield (filter f it') out ⋯ else PlausibleIterStep.skip (filter f it') ⋯
| ⟨IterStep.skip it', h⟩ => PlausibleIterStep.skip (filter f it') ⋯
| ⟨IterStep.done, h⟩ => PlausibleIterStep.done ⋯
Equations
- ⋯ = ⋯
Instances For
def
Std.Iterators.Iter.val_step_filter
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
{f : β → Bool}
:
(filter f it).step.val = match it.step.val with
| IterStep.yield it' out => if f out = true then IterStep.yield (filter f it') out else IterStep.skip (filter f it')
| IterStep.skip it' => IterStep.skip (filter f it')
| IterStep.done => IterStep.done
Equations
- ⋯ = ⋯
Instances For
@[simp]
theorem
Std.Iterators.Iter.toList_filterMap
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Option γ}
:
@[simp]
theorem
Std.Iterators.Iter.toList_filter
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Bool}
:
@[simp]
theorem
Std.Iterators.Iter.toListRev_filterMap
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Option γ}
:
@[simp]
theorem
Std.Iterators.Iter.toListRev_filter
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Bool}
:
@[simp]
theorem
Std.Iterators.Iter.toArray_filterMap
{α β γ : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Option γ}
:
@[simp]
theorem
Std.Iterators.Iter.toArray_filter
{α β : Type w}
[Iterator α Id β]
{it : Iter β}
[IteratorCollect α Id Id]
[LawfulIteratorCollect α Id Id]
[Finite α Id]
{f : β → Bool}
:
theorem
Std.Iterators.Iter.foldM_filterMapM
{α β γ δ : Type w}
{m : Type w → Type w'}
{n : Type w → Type w''}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[Monad n]
[LawfulMonad m]
[LawfulMonad n]
[IteratorLoop α Id Id]
[IteratorLoop α Id m]
[IteratorLoop α Id n]
[MonadLiftT m n]
[LawfulMonadLiftT m n]
[LawfulIteratorLoop α Id Id]
[LawfulIteratorLoop α Id m]
[LawfulIteratorLoop α Id n]
{f : β → m (Option γ)}
{g : δ → γ → n δ}
{init : δ}
{it : Iter β}
:
IterM.foldM g init (filterMapM f it) = foldM
(fun (d : δ) (b : β) => do
let __discr ← liftM (f b)
match __discr with
| some c => g d c
| x => pure d)
init it
theorem
Std.Iterators.Iter.foldM_mapM
{α β γ δ : Type w}
{m : Type w → Type w'}
{n : Type w → Type w''}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[Monad n]
[LawfulMonad m]
[LawfulMonad n]
[IteratorLoop α Id m]
[IteratorLoop α Id n]
[LawfulIteratorLoop α Id m]
[LawfulIteratorLoop α Id n]
[MonadLiftT m n]
[LawfulMonadLiftT m n]
{f : β → m γ}
{g : δ → γ → n δ}
{init : δ}
{it : Iter β}
:
IterM.foldM g init (mapM f it) = foldM
(fun (d : δ) (b : β) => do
let c ← liftM (f b)
g d c)
init it
theorem
Std.Iterators.Iter.foldM_filterMap
{α β γ : Type w}
{δ : Type x}
{m : Type x → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id m]
{f : β → Option γ}
{g : δ → γ → m δ}
{init : δ}
{it : Iter β}
:
theorem
Std.Iterators.Iter.foldM_map
{α β γ : Type w}
{δ : Type x}
{m : Type x → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id m]
{f : β → γ}
{g : δ → γ → m δ}
{init : δ}
{it : Iter β}
:
theorem
Std.Iterators.Iter.fold_filterMapM
{α β γ δ : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id Id]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id Id]
[LawfulIteratorLoop α Id m]
{f : β → m (Option γ)}
{g : δ → γ → δ}
{init : δ}
{it : Iter β}
:
IterM.fold g init (filterMapM f it) = foldM
(fun (d : δ) (b : β) => do
let __discr ← f b
match __discr with
| some c => pure (g d c)
| x => pure d)
init it
theorem
Std.Iterators.Iter.fold_mapM
{α β γ δ : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id Id]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id Id]
[LawfulIteratorLoop α Id m]
{f : β → m γ}
{g : δ → γ → δ}
{init : δ}
{it : Iter β}
:
IterM.fold g init (mapM f it) = foldM
(fun (d : δ) (b : β) => do
let __do_lift ← f b
pure (g d __do_lift))
init it
theorem
Std.Iterators.Iter.fold_filterMap
{α β γ : Type w}
{δ : Type x}
[Iterator α Id β]
[Finite α Id]
[IteratorLoop α Id Id]
[LawfulIteratorLoop α Id Id]
{f : β → Option γ}
{g : δ → γ → δ}
{init : δ}
{it : Iter β}
:
theorem
Std.Iterators.Iter.anyM_filterMapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
{it : Iter β}
{f : β → m (Option β')}
{p : β' → m (ULift Bool)}
:
IterM.anyM p (filterMapM f it) = IterM.anyM
(fun (x : β) => do
let __do_lift ← f x
match __do_lift with
| some fx => p fx
| none => pure { down := false })
(mapM pure it)
theorem
Std.Iterators.Iter.anyM_eq_anyM_mapM_pure
{α β : Type}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{p : β → m Bool}
:
This lemma expresses Iter.anyM in terms of IterM.anyM.
It requires all involved types to live in Type 0.
theorem
Std.Iterators.Iter.anyM_mapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
{it : Iter β}
{f : β → m β'}
{p : β' → m (ULift Bool)}
:
IterM.anyM p (mapM f it) = IterM.anyM
(fun (x : β) => do
let __do_lift ← f x
p __do_lift)
(mapM pure it)
theorem
Std.Iterators.Iter.anyM_filterMap
{α β β' : Type w}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → Option β'}
{p : β' → m Bool}
:
theorem
Std.Iterators.Iter.anyM_filter
{α β : Type w}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → Bool}
{p : β → m Bool}
:
theorem
Std.Iterators.Iter.any_filterMapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m (Option β')}
{p : β' → Bool}
:
theorem
Std.Iterators.Iter.any_mapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m β'}
{p : β' → Bool}
:
theorem
Std.Iterators.Iter.any_filterM
{α β : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m (ULift Bool)}
{p : β → Bool}
:
theorem
Std.Iterators.Iter.allM_filterMapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
{it : Iter β}
{f : β → m (Option β')}
{p : β' → m (ULift Bool)}
:
IterM.allM p (filterMapM f it) = IterM.allM
(fun (x : β) => do
let __do_lift ← f x
match __do_lift with
| some fx => p fx
| none => pure { down := true })
(mapM pure it)
theorem
Std.Iterators.Iter.allM_eq_allM_mapM_pure
{α β : Type}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
[IteratorLoop α Id m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{p : β → m Bool}
:
This lemma expresses Iter.allM in terms of IterM.allM.
It requires all involved types to live in Type 0.
theorem
Std.Iterators.Iter.allM_mapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[LawfulMonad m]
{it : Iter β}
{f : β → m β'}
{p : β' → m (ULift Bool)}
:
IterM.allM p (mapM f it) = IterM.allM
(fun (x : β) => do
let __do_lift ← f x
p __do_lift)
(mapM pure it)
theorem
Std.Iterators.Iter.allM_filterMap
{α β β' : Type w}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → Option β'}
{p : β' → m Bool}
:
theorem
Std.Iterators.Iter.allM_filter
{α β : Type w}
{m : Type → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → Bool}
{p : β → m Bool}
:
theorem
Std.Iterators.Iter.all_filterMapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m (Option β')}
{p : β' → Bool}
:
theorem
Std.Iterators.Iter.all_mapM
{α β β' : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m β'}
{p : β' → Bool}
:
theorem
Std.Iterators.Iter.all_filterM
{α β : Type w}
{m : Type w → Type w'}
[Iterator α Id β]
[Finite α Id]
[Monad m]
[IteratorLoop α Id m]
[LawfulMonad m]
[LawfulIteratorLoop α Id m]
{it : Iter β}
{f : β → m (ULift Bool)}
{p : β → Bool}
: