PhysLean Documentation

Init.Data.Iterators.Lemmas.Combinators.FilterMap

theorem Std.Iter.filterMapM_eq_toIter_filterMapM_toIterM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [MonadAttach m] {f : βm (Option γ)} :
theorem Std.Iter.filterM_eq_toIter_filterM_toIterM {α β : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [MonadAttach m] {f : βm (ULift Bool)} :
theorem Std.Iter.mapM_eq_toIter_mapM_toIterM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [MonadAttach m] {f : βm γ} :
theorem Std.Iter.filterMap_eq_toIter_filterMap_toIterM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {f : βOption γ} :
theorem Std.Iter.map_eq_toIter_map_toIterM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {f : βγ} :
theorem Std.Iter.filter_eq_toIter_filter_toIterM {α β : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] {f : βBool} :
theorem Std.Iter.step_filterMapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {f : βIterators.PostconditionT n (Option γ)} [Monad n] [LawfulMonad n] [MonadLiftT m n] :
theorem Std.Iter.step_filterWithPostcondition {α β : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {f : βIterators.PostconditionT n (ULift Bool)} [Monad n] [LawfulMonad n] [MonadLiftT m n] :
theorem Std.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] [MonadAttach n] [LawfulMonad n] [MonadLiftT m n] :
(filterMapM f it).step = match it.step with | IterStep.yield it' out, h => do let __do_liftMonadAttach.attach (f out) match __do_lift with | none, hf => pure (Shrink.deflate (PlausibleIterStep.skip (filterMapM f it') )) | some out', hf => 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.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] [MonadAttach n] [LawfulMonad n] [MonadLiftT m n] :
(filterM f it).step = match it.step with | IterStep.yield it' out, h => do let __do_liftMonadAttach.attach (f out) match __do_lift with | { down := false }, hf => pure (Shrink.deflate (PlausibleIterStep.skip (filterM f it') )) | { down := true }, hf => 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.Iter.step_mapM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {n : Type w → Type w''} {f : βn γ} [Monad n] [MonadAttach n] [LawfulMonad n] :
theorem Std.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.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.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.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.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.Iter.toList_filterMap {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βOption γ} :
      @[simp]
      theorem Std.Iter.toList_mapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [LawfulMonad m] [Iterators.Finite α Id] {f : βIterators.PostconditionT m γ} :
      (mapWithPostcondition f it).toList = List.mapM (fun (x : β) => (f x).run) it.toList
      @[simp]
      theorem Std.Iter.toList_mapM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [Iterators.Finite α Id] {f : βm γ} :
      @[simp]
      theorem Std.Iter.toList_map {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βγ} :
      (map f it).toList = List.map f it.toList
      @[simp]
      theorem Std.Iter.toList_filter {α β : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βBool} :
      @[simp]
      theorem Std.Iter.toList_filterMapWithPostcondition_filterMapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {δ : Type w} [Monad m] [LawfulMonad m] [Monad n] [LawfulMonad n] [MonadLiftT m n] [LawfulMonadLiftT m n] [Iterators.Finite α Id] {f : βIterators.PostconditionT m (Option γ)} {g : γIterators.PostconditionT n (Option δ)} :
      (IterM.filterMapWithPostcondition g (filterMapWithPostcondition f it)).toList = (filterMapWithPostcondition (fun (b : β) => do let __do_liftliftM (f b) match __do_lift with | none => pure none | some fb => g fb) it).toList
      @[simp]
      theorem Std.Iter.toList_mapWithPostcondition_mapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {δ : Type w} [Monad m] [LawfulMonad m] [Monad n] [LawfulMonad n] [MonadLiftT m n] [LawfulMonadLiftT m n] [Iterators.Finite α Id] {f : βIterators.PostconditionT m γ} {g : γIterators.PostconditionT n δ} :
      @[simp]
      theorem Std.Iter.toListRev_filterMap {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βOption γ} :
      @[simp]
      theorem Std.Iter.toListRev_map {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βγ} :
      @[simp]
      theorem Std.Iter.toListRev_filter {α β : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βBool} :
      @[simp]
      theorem Std.Iter.toArray_filterMap {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βOption γ} :
      @[simp]
      theorem Std.Iter.toArray_mapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [LawfulMonad m] [Iterators.Finite α Id] {f : βIterators.PostconditionT m γ} :
      (mapWithPostcondition f it).toArray = Array.mapM (fun (x : β) => (f x).run) it.toArray
      @[simp]
      theorem Std.Iter.toArray_mapM {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [Iterators.Finite α Id] {f : βm γ} :
      @[simp]
      theorem Std.Iter.toArray_map {α β γ : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βγ} :
      @[simp]
      theorem Std.Iter.toArray_filter {α β : Type w} [Iterator α Id β] {it : Iter β} [Iterators.Finite α Id] {f : βBool} :
      @[simp]
      theorem Std.Iter.toArray_filterMapWithPostcondition_filterMapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {δ : Type w} [Monad m] [LawfulMonad m] [Monad n] [LawfulMonad n] [MonadLiftT m n] [LawfulMonadLiftT m n] [Iterators.Finite α Id] {f : βIterators.PostconditionT m (Option γ)} {g : γIterators.PostconditionT n (Option δ)} :
      (IterM.filterMapWithPostcondition g (filterMapWithPostcondition f it)).toArray = (filterMapWithPostcondition (fun (b : β) => do let __do_liftliftM (f b) match __do_lift with | none => pure none | some fb => g fb) it).toArray
      @[simp]
      theorem Std.Iter.toArray_mapWithPostcondition_mapWithPostcondition {α β γ : Type w} [Iterator α Id β] {it : Iter β} {m : Type w → Type w'} {n : Type w → Type w''} {δ : Type w} [Monad m] [LawfulMonad m] [Monad n] [LawfulMonad n] [MonadLiftT m n] [LawfulMonadLiftT m n] [Iterators.Finite α Id] {f : βIterators.PostconditionT m γ} {g : γIterators.PostconditionT n δ} :
      theorem Std.Iter.forIn_filterMapWithPostcondition {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} {β₂ : Type w} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βIterators.PostconditionT n (Option β₂)} {init : γ} {g : β₂γo (ForInStep γ)} :
      forIn (filterMapWithPostcondition f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out).run match __do_lift with | some c => g c acc | none => pure (ForInStep.yield acc)
      theorem Std.Iter.forIn_filterMapM {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} {β₂ : Type w} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadAttach n] [WeaklyLawfulMonadAttach n] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βn (Option β₂)} {init : γ} {g : β₂γo (ForInStep γ)} :
      forIn (filterMapM f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out) match __do_lift with | some c => g c acc | none => pure (ForInStep.yield acc)
      theorem Std.Iter.forIn_filterMap {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {β₂ : Type w} [Monad n] [LawfulMonad n] [Iterators.Finite α Id] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {it : Iter β} {f : βOption β₂} {init : γ} {g : β₂γn (ForInStep γ)} :
      forIn (filterMap f it) init g = forIn it init fun (out : β) (acc : γ) => match f out with | some c => g c acc | none => pure (ForInStep.yield acc)
      theorem Std.Iter.forIn_mapWithPostcondition {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} {β₂ : Type w} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βIterators.PostconditionT n β₂} {init : γ} {g : β₂γo (ForInStep γ)} :
      forIn (mapWithPostcondition f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out).run g __do_lift acc
      theorem Std.Iter.forIn_mapM {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} {β₂ : Type w} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadAttach n] [WeaklyLawfulMonadAttach n] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βn β₂} {init : γ} {g : β₂γo (ForInStep γ)} :
      forIn (mapM f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out) g __do_lift acc
      theorem Std.Iter.forIn_map {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {β₂ : Type w} [Monad n] [LawfulMonad n] [Iterators.Finite α Id] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {it : Iter β} {f : ββ₂} {init : γ} {g : β₂γn (ForInStep γ)} :
      forIn (map f it) init g = forIn it init fun (out : β) (acc : γ) => g (f out) acc
      theorem Std.Iter.forIn_filterWithPostcondition {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βIterators.PostconditionT n (ULift Bool)} {init : γ} {g : βγo (ForInStep γ)} :
      forIn (filterWithPostcondition f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out).run if __do_lift.down = true then g out acc else pure (ForInStep.yield acc)
      theorem Std.Iter.forIn_filterM {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} {o : Type w → Type u_1} [Monad n] [LawfulMonad n] [Monad o] [LawfulMonad o] [MonadAttach n] [WeaklyLawfulMonadAttach n] [MonadLiftT n o] [LawfulMonadLiftT n o] [Iterators.Finite α Id] [IteratorLoop α Id o] [LawfulIteratorLoop α Id o] {it : Iter β} {f : βn (ULift Bool)} {init : γ} {g : βγo (ForInStep γ)} :
      forIn (filterM f it) init g = forIn it init fun (out : β) (acc : γ) => do let __do_liftliftM (f out) if __do_lift.down = true then g out acc else pure (ForInStep.yield acc)
      theorem Std.Iter.forIn_filter {α β γ : Type w} [Iterator α Id β] {n : Type w → Type w''} [Monad n] [LawfulMonad n] [Iterators.Finite α Id] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {it : Iter β} {f : βBool} {init : γ} {g : βγn (ForInStep γ)} :
      forIn (filter f it) init g = forIn it init fun (out : β) (acc : γ) => if f out = true then g out acc else pure (ForInStep.yield acc)
      theorem Std.Iter.foldM_filterMapWithPostcondition {α β γ δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [Monad o] [LawfulMonad n] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βIterators.PostconditionT n (Option γ)} {g : δγo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (filterMapWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let __discrliftM (f b).run match __discr with | some c => g d c | x => pure d) init it
      theorem Std.Iter.foldM_filterMapM {α β γ δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [Monad o] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βn (Option γ)} {g : δγo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (filterMapM f it) = foldM (fun (d : δ) (b : β) => do let __discrliftM (f b) match __discr with | some c => g d c | x => pure d) init it
      theorem Std.Iter.foldM_mapWithPostcondition {m : Type w → Type w'} {α β γ δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [Monad n] [Monad o] [LawfulMonad m] [LawfulMonad n] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βIterators.PostconditionT n γ} {g : δγo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (mapWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let cliftM (f b).run g d c) init it
      theorem Std.Iter.foldM_mapM {α β γ δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [Monad o] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βn γ} {g : δγo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (mapM f it) = foldM (fun (d : δ) (b : β) => do let cliftM (f b) g d c) init it
      theorem Std.Iter.foldM_filterWithPostcondition {α β δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [Monad o] [LawfulMonad n] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βIterators.PostconditionT n (ULift Bool)} {g : δβo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (filterWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let __do_liftliftM (f b).run if __do_lift.down = true then g d b else pure d) init it
      theorem Std.Iter.foldM_filterM {α β δ : Type w} {n : Type w → Type w''} {o : Type w → Type w'''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [Monad o] [LawfulMonad o] [IteratorLoop α Id n] [IteratorLoop α Id o] [LawfulIteratorLoop α Id n] [LawfulIteratorLoop α Id o] [MonadLiftT n o] [LawfulMonadLiftT n o] {f : βn (ULift Bool)} {g : δβo δ} {init : δ} {it : Iter β} :
      IterM.foldM g init (filterM f it) = foldM (fun (d : δ) (b : β) => do let __do_liftliftM (f b) if __do_lift.down = true then g d b else pure d) init it
      theorem Std.Iter.foldM_filterMap {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βOption γ} {g : δγn δ} {init : δ} {it : Iter β} :
      foldM g init (filterMap f it) = foldM (fun (d : δ) (b : β) => match f b with | some c => g d c | x => pure d) init it
      theorem Std.Iter.foldM_map {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βγ} {g : δγn δ} {init : δ} {it : Iter β} :
      foldM g init (map f it) = foldM (fun (d : δ) (b : β) => g d (f b)) init it
      theorem Std.Iter.foldM_filter {α β δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βBool} {g : δβn δ} {init : δ} {it : Iter β} :
      foldM g init (filter f it) = foldM (fun (d : δ) (b : β) => if f b = true then g d b else pure d) init it
      theorem Std.Iter.fold_filterMapWithPostcondition {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βIterators.PostconditionT n (Option γ)} {g : δγδ} {init : δ} {it : Iter β} :
      IterM.fold g init (filterMapWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let __discr(f b).run match __discr with | some c => pure (g d c) | x => pure d) init it
      theorem Std.Iter.fold_filterMapM {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βn (Option γ)} {g : δγδ} {init : δ} {it : Iter β} :
      IterM.fold g init (filterMapM f it) = foldM (fun (d : δ) (b : β) => do let __discrf b match __discr with | some c => pure (g d c) | x => pure d) init it
      theorem Std.Iter.fold_mapWithPostcondition {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βIterators.PostconditionT n γ} {g : δγδ} {init : δ} {it : Iter β} :
      IterM.fold g init (mapWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let c(f b).run pure (g d c)) init it
      theorem Std.Iter.fold_mapM {α β γ δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βn γ} {g : δγδ} {init : δ} {it : Iter β} :
      IterM.fold g init (mapM f it) = foldM (fun (d : δ) (b : β) => do let cf b pure (g d c)) init it
      theorem Std.Iter.fold_filterWithPostcondition {α β δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [LawfulMonad n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βIterators.PostconditionT n (ULift Bool)} {g : δβδ} {init : δ} {it : Iter β} :
      IterM.fold g init (filterWithPostcondition f it) = foldM (fun (d : δ) (b : β) => do let __do_lift(f b).run pure (if __do_lift.down = true then g d b else d)) init it
      theorem Std.Iter.fold_filterM {α β δ : Type w} {n : Type w → Type w''} [Iterator α Id β] [Iterators.Finite α Id] [Monad n] [MonadAttach n] [LawfulMonad n] [WeaklyLawfulMonadAttach n] [IteratorLoop α Id n] [LawfulIteratorLoop α Id n] {f : βn (ULift Bool)} {g : δβδ} {init : δ} {it : Iter β} :
      IterM.fold g init (filterM f it) = foldM (fun (d : δ) (b : β) => do let __do_liftf b pure (if __do_lift.down = true then g d b else d)) init it
      theorem Std.Iter.fold_filterMap {α β γ δ : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {f : βOption γ} {g : δγδ} {init : δ} {it : Iter β} :
      fold g init (filterMap f it) = fold (fun (d : δ) (b : β) => match f b with | some c => g d c | x => d) init it
      theorem Std.Iter.fold_map {α β γ δ : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {f : βγ} {g : δγδ} {init : δ} {it : Iter β} :
      fold g init (map f it) = fold (fun (d : δ) (b : β) => g d (f b)) init it
      theorem Std.Iter.fold_filter {α β δ : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {f : βBool} {g : δβδ} {init : δ} {it : Iter β} :
      fold g init (filter f it) = fold (fun (d : δ) (b : β) => if f b = true then g d b else d) init it
      @[simp]
      theorem Std.Iter.count_map {α β β' : Type w} [Iterator α Id β] [IteratorLoop α Id Id] [Iterators.Finite α Id] [LawfulIteratorLoop α Id Id] {it : Iter β} {f : ββ'} :
      (map f it).count = it.count
      theorem Std.Iter.anyM_filterMapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f : βm (Option β')} {p : β'm (ULift Bool)} :
      IterM.anyM p (filterMapM f it) = IterM.anyM (fun (x : β) => do let __do_liftf x match __do_lift with | some fx => p fx | none => pure { down := false }) (mapM pure it)
      theorem Std.Iter.anyM_eq_anyM_mapM_pure {α β : Type} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [IteratorLoop α Id m] [LawfulIteratorLoop α Id m] {it : Iter β} {p : βm Bool} :
      anyM p it = ULift.down <$> IterM.anyM (fun (x : β) => ULift.up <$> p x) (mapM pure it)

      This lemma expresses Iter.anyM in terms of IterM.anyM. It requires all involved types to live in Type 0.

      theorem Std.Iter.anyM_mapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f : βm β'} {p : β'm (ULift Bool)} :
      IterM.anyM p (mapM f it) = IterM.anyM (fun (x : β) => do let __do_liftf x p __do_lift) (mapM pure it)
      theorem Std.Iter.anyM_filterM {α β : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f p : βm (ULift Bool)} :
      IterM.anyM p (filterM f it) = IterM.anyM (fun (x : β) => do let __do_liftf x if __do_lift.down = true then p x else pure { down := false }) (mapM pure it)
      theorem Std.Iter.anyM_filterMap {α β β' : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βOption β'} {p : β'm Bool} :
      anyM p (filterMap f it) = anyM (fun (x : β) => match f x with | some fx => p fx | none => pure false) it
      theorem Std.Iter.anyM_map {α β β' : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : ββ'} {p : β'm Bool} :
      anyM p (map f it) = anyM (fun (x : β) => p (f x)) it
      theorem Std.Iter.anyM_filter {α β : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βBool} {p : βm Bool} :
      anyM p (filter f it) = anyM (fun (x : β) => if f x = true then p x else pure false) it
      theorem Std.Iter.any_filterMapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm (Option β')} {p : β'Bool} :
      IterM.any p (filterMapM f it) = IterM.anyM (fun (x : β) => do let __do_liftf x match __do_lift with | some fx => pure { down := p fx } | none => pure { down := false }) (mapM pure it)
      theorem Std.Iter.any_mapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm β'} {p : β'Bool} :
      IterM.any p (mapM f it) = IterM.anyM (fun (x : β) => (fun (x : β') => { down := p x }) <$> f x) (mapM pure it)
      theorem Std.Iter.any_filterM {α β : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm (ULift Bool)} {p : βBool} :
      IterM.any p (filterM f it) = IterM.anyM (fun (x : β) => do let __do_liftf x if __do_lift.down = true then pure { down := p x } else pure { down := false }) (mapM pure it)
      theorem Std.Iter.any_filterMap {α β β' : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {it : Iter β} {f : βOption β'} {p : β'Bool} :
      any p (filterMap f it) = any (fun (x : β) => match f x with | some fx => p fx | none => false) it
      theorem Std.Iter.any_map {α β β' : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {it : Iter β} {f : ββ'} {p : β'Bool} :
      any p (map f it) = any (fun (x : β) => p (f x)) it
      theorem Std.Iter.allM_filterMapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f : βm (Option β')} {p : β'm (ULift Bool)} :
      IterM.allM p (filterMapM f it) = IterM.allM (fun (x : β) => do let __do_liftf x match __do_lift with | some fx => p fx | none => pure { down := true }) (mapM pure it)
      theorem Std.Iter.allM_eq_allM_mapM_pure {α β : Type} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [IteratorLoop α Id m] [LawfulIteratorLoop α Id m] {it : Iter β} {p : βm Bool} :
      allM p it = ULift.down <$> IterM.allM (fun (x : β) => ULift.up <$> p x) (mapM pure it)

      This lemma expresses Iter.allM in terms of IterM.allM. It requires all involved types to live in Type 0.

      theorem Std.Iter.allM_mapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f : βm β'} {p : β'm (ULift Bool)} :
      IterM.allM p (mapM f it) = IterM.allM (fun (x : β) => do let __do_liftf x p __do_lift) (mapM pure it)
      theorem Std.Iter.allM_filterM {α β : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] {it : Iter β} {f p : βm (ULift Bool)} :
      IterM.allM p (filterM f it) = IterM.allM (fun (x : β) => do let __do_liftf x if __do_lift.down = true then p x else pure { down := true }) (mapM pure it)
      theorem Std.Iter.allM_filterMap {α β β' : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βOption β'} {p : β'm Bool} :
      allM p (filterMap f it) = allM (fun (x : β) => match f x with | some fx => p fx | none => pure true) it
      theorem Std.Iter.allM_map {α β β' : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : ββ'} {p : β'm Bool} :
      allM p (map f it) = allM (fun (x : β) => p (f x)) it
      theorem Std.Iter.allM_filter {α β : Type w} {m : TypeType w'} [Iterator α Id β] [Iterators.Finite α Id] [Monad m] [IteratorLoop α Id m] [LawfulMonad m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βBool} {p : βm Bool} :
      allM p (filter f it) = allM (fun (x : β) => if f x = true then p x else pure true) it
      theorem Std.Iter.all_filterMapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm (Option β')} {p : β'Bool} :
      IterM.all p (filterMapM f it) = IterM.allM (fun (x : β) => do let __do_liftf x match __do_lift with | some fx => pure { down := p fx } | none => pure { down := true }) (mapM pure it)
      theorem Std.Iter.all_mapM {α β β' : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm β'} {p : β'Bool} :
      IterM.all p (mapM f it) = IterM.allM (fun (x : β) => (fun (x : β') => { down := p x }) <$> f x) (mapM pure it)
      theorem Std.Iter.all_filterM {α β : Type w} {m : Type w → Type w'} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id m] [Monad m] [MonadAttach m] [LawfulMonad m] [WeaklyLawfulMonadAttach m] [LawfulIteratorLoop α Id m] {it : Iter β} {f : βm (ULift Bool)} {p : βBool} :
      IterM.all p (filterM f it) = IterM.allM (fun (x : β) => do let __do_liftf x if __do_lift.down = true then pure { down := p x } else pure { down := true }) (mapM pure it)
      theorem Std.Iter.all_filterMap {α β β' : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {it : Iter β} {f : βOption β'} {p : β'Bool} :
      all p (filterMap f it) = all (fun (x : β) => match f x with | some fx => p fx | none => true) it
      theorem Std.Iter.all_map {α β β' : Type w} [Iterator α Id β] [Iterators.Finite α Id] [IteratorLoop α Id Id] [LawfulIteratorLoop α Id Id] {it : Iter β} {f : ββ'} {p : β'Bool} :
      all p (map f it) = all (fun (x : β) => p (f x)) it