Documentation

Cslib.Algorithms.Lean.Sort.Insertion

A Monadic version of Mathlib's List.insertionSort #

This can be instantiated with Id to recover the original, or with TimeM or FreeM for algorithmic analysis.

def List.orderedInsertM {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) (a : α) :
List αm (List α)

A monadic version of List.orderedInsert.

Equations
Instances For
    @[simp]
    theorem List.orderedInsertM_nil {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) (a : α) :
    @[simp]
    theorem List.orderedInsertM_cons {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) (a b : α) (l : List α) :
    orderedInsertM r a (b :: l) = do let __do_liftr a b if __do_lift = true then pure (a :: b :: l) else do let __do_liftorderedInsertM r a l pure (b :: __do_lift)
    @[simp]
    theorem List.orderedInsertM_pure {α : Type} {m : TypeType u_1} [Monad m] [LawfulMonad m] (r : ααBool) (a : α) (xs : List α) :
    orderedInsertM (fun (x y : α) => pure (r x y)) a xs = pure (orderedInsert (fun (x1 x2 : α) => r x1 x2 = true) a xs)
    @[simp]
    theorem List.idRun_orderedInsertM {α : Type} (r : ααId Bool) (a : α) (xs : List α) :
    (orderedInsertM r a xs).run = orderedInsert (fun (x y : α) => (r x y).run = true) a xs
    theorem Cslib.IsMonadHom.map_orderedInsertM {α : Type} {m : TypeType u_1} {n : TypeType u_2} [Monad m] [Monad n] {f : {β : Type} → m βn β} (hf : IsMonadHom m n fun {α : Type} => f) (r : ααm Bool) (a : α) (xs : List α) :
    f (List.orderedInsertM r a xs) = List.orderedInsertM (fun (x y : α) => f (r x y)) a xs
    def List.insertionSortM {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) :
    List αm (List α)

    A monadic version of List.insertionSort.

    Equations
    Instances For
      @[simp]
      theorem List.insertionSortM_nil {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) :
      @[simp]
      theorem List.insertionSortM_cons {α : Type} {m : TypeType u_1} [Monad m] (r : ααm Bool) (b : α) (l : List α) :
      insertionSortM r (b :: l) = do let __do_liftinsertionSortM r l orderedInsertM r b __do_lift
      @[simp]
      theorem List.insertionSortM_pure {α : Type} {m : TypeType u_1} [Monad m] [LawfulMonad m] (xs : List α) (r : ααBool) :
      insertionSortM (fun (x y : α) => pure (r x y)) xs = pure (insertionSort (fun (x1 x2 : α) => r x1 x2 = true) xs)
      @[simp]
      theorem List.idRun_insertionSortM {α : Type} (xs : List α) (r : ααId Bool) :
      (insertionSortM r xs).run = insertionSort (fun (x y : α) => (r x y).run = true) xs
      theorem Cslib.IsMonadHom.map_listInsertionSortM {α : Type} {m : TypeType u_1} {n : TypeType u_2} [Monad m] [Monad n] {f : {β : Type} → m βn β} (hf : IsMonadHom m n fun {α : Type} => f) (r : ααm Bool) (xs : List α) :
      f (List.insertionSortM r xs) = List.insertionSortM (fun (x y : α) => f (r x y)) xs