Documentation

LeanPool.Lean4Itree.ITree.Basic

Coinductive interaction trees #

This module defines the coinductive interaction tree ITree as the final coalgebra (PFunctor.M) of the interaction-tree polynomial functor, together with its constructors (ret, tau, vis), the dependent matcher dMatchOn, injectivity lemmas for the constructors, and the bisimulation equality IEq that is proven to coincide with propositional equality (ieq_iff_eq).

inductive Lean4Itree.ITree.shape (ε : Type u1 → Type v) (ρ : Type u2) :
Type (max (max (u1 + 1) u2) v)

The node shapes of an interaction tree: a returned value, a silent tau step, or a visible effect vis. This is the A-component of the polynomial functor whose M-type is ITree.

Instances For
    def Lean4Itree.ITree.children {ε : Type u1 → Type v} {ρ : Type u2} :
    shape ε ρType u1

    The arity (B-component) of each interaction-tree node shape: a ret node has no children, a tau node has one, and a vis α e node has one child per inhabitant of the response type α.

    Equations
    Instances For

      The interaction-tree polynomial functor, packaging shape and children.

      Equations
      Instances For
        def Lean4Itree.ITree (ε : Type u1 → Type v) (ρ : Type u2) :
        Type (max (max (max (u1 + 1) u2) v) u1)

        Coinductive Interaction Tree defined with PFunctor.M. Equivalent to the following definition:

        coinductive ITree (ε : Type → Type) (ρ : Type)
        | ret (v : ρ)
        | tau (t : ITree ε ρ)
        | vis {α : Type} (e : ε α) (k : αITree ε ρ)
        
        Equations
        Instances For
          @[reducible, inline]
          abbrev Lean4Itree.KTree (ε : Type u1 → Type v) (α : Type u1) (β : Type u2) :
          Type (max (max (max u1 u2) v) (u1 + 1))

          A continuation tree: a function from α into interaction trees, i.e. a Kleisli arrow for the ITree monad.

          Equations
          Instances For
            @[implicit_reducible]
            instance Lean4Itree.ITree.instOfNatChildrenTauZero {ε : Type u_1 → Type u_2} {ρ : Type u_3} :
            OfNat ((P ε ρ).B shape.tau) 0
            Equations
            def Lean4Itree.ITree.ret' {ε : Type u1 → Type v} {ρ : Type u2} {X : Type u} (v : ρ) :
            (P ε ρ) X

            One layer of a ret node in the polynomial functor: returns the value v.

            Equations
            Instances For
              def Lean4Itree.ITree.tau' {ε : Type u1 → Type v} {ρ : Type u2} {X : Type u} (t : X) :
              (P ε ρ) X

              One layer of a tau node in the polynomial functor: a single silent child t.

              Equations
              Instances For
                def Lean4Itree.ITree.vis' {ε : Type u1 → Type v} {ρ : Type u2} {X : Type u} {α : Type u1} (e : ε α) (k : αX) :
                (P ε ρ) X

                One layer of a vis node in the polynomial functor: an effect e with continuation k indexed by the response type.

                Equations
                Instances For
                  @[match_pattern]
                  def Lean4Itree.ITree.ret {ε : Type u1 → Type v} {ρ : Type u2} (v : ρ) :
                  ITree ε ρ

                  The interaction tree that immediately returns the value v.

                  Equations
                  Instances For
                    @[match_pattern]
                    def Lean4Itree.ITree.tau {ε : Type u1 → Type v} {ρ : Type u2} (t : ITree ε ρ) :
                    ITree ε ρ

                    The interaction tree that takes one silent tau step into t.

                    Equations
                    Instances For
                      def Lean4Itree.ITree.tauN {ε : Type u1 → Type v} {ρ : Type u2} (n : ) (t : ITree ε ρ) :
                      ITree ε ρ

                      The interaction tree that takes n silent tau steps into t.

                      Equations
                      Instances For
                        @[match_pattern]
                        def Lean4Itree.ITree.vis {ε : Type u1 → Type v} {ρ : Type u2} {α : Type u1} (e : ε α) (k : αITree ε ρ) :
                        ITree ε ρ

                        The interaction tree that performs the effect e and continues with k.

                        Equations
                        Instances For
                          def Lean4Itree.ITree.trigger {ε : Type u1 → Type v} {α : Type u1} (e : ε α) :
                          ITree ε α

                          The interaction tree that performs the single effect e and returns its response.

                          Equations
                          Instances For
                            theorem Lean4Itree.ITree.ret_inj {ε : Type u1 → Type v} {ρ : Type u2} {x y : ρ} (h : ret x = ret y) :
                            x = y
                            theorem Lean4Itree.ITree.vis_inj_α {ε : Type u_1 → Type u_2} {α1 α2 : Type u_1} {ρ : Type u_3} {k1 : KTree ε α1 ρ} {k2 : KTree ε α2 ρ} {e1 : ε α1} {e2 : ε α2} (h : vis e1 k1 = vis e2 k2) :
                            α1 = α2
                            theorem Lean4Itree.ITree.vis_inj {ε : Type u_1 → Type u_2} {α : Type u_1} {ρ : Type u_3} {e1 e2 : ε α} {k1 k2 : KTree ε α ρ} (h : vis e1 k1 = vis e2 k2) :
                            e1 = e2 k1 = k2
                            theorem Lean4Itree.ITree.tau_inj {ε : Type u_1 → Type u_2} {ρ : Type u_3} {t1 t2 : ITree ε ρ} (h : t1.tau = t2.tau) :
                            t1 = t2
                            def Lean4Itree.ITree.dMatchOn {ε : Type u1 → Type v} {ρ : Type u2} {motive : ITree ε ρSort u} (x : ITree ε ρ) (ret : (v : ρ) → x = ret vmotive x) (tau : (c : ITree ε ρ) → x = c.taumotive x) (vis : (α : Type u1) → (e : ε α) → (k : αITree ε ρ) → x = vis e kmotive x) :
                            motive x

                            Custom dependent match function for ITrees

                            Equations
                            • One or more equations did not get rendered due to their size.
                            Instances For
                              theorem Lean4Itree.ITree.dest_ret {ε : Type u1 → Type v} {ρ : Type u2} {v : ρ} :
                              theorem Lean4Itree.ITree.dest_tau {ε : Type u1 → Type v} {ρ : Type u2} {t : ITree ε ρ} :
                              theorem Lean4Itree.ITree.dest_vis {ε : Type u_1 → Type u_2} {α : Type u_1} {ρ : Type u_3} {e : ε α} {k : KTree ε α ρ} :
                              def Lean4Itree.ITree.infTau {ε : Type u1 → Type v} {ρ : Type u2} :
                              ITree ε ρ

                              Infinite Taus

                              Equations
                              Instances For
                                theorem Lean4Itree.ITree.infTau_eq {ε : Type u1 → Type v} {ρ : Type u2} :
                                inductive Lean4Itree.ITree.State (ε : Type u1 → Type v1) (ρ : Type u2) :
                                Type (max (max (u1 + 1) u2) v1)

                                A coinduction state for traversing interaction trees: either a whole tree (ct) or a continuation tree (kt).

                                Instances For

                                  Notation C[ t ] for the tree state State.ct t.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Notation K[ t ] for the continuation-tree state State.kt t.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Notation K[ α | t ] for the continuation-tree state State.kt t with explicit index type α.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Simplify basic interaction-tree constructors and PFunctor.M.dest_mk.

                                        Equations
                                        Instances For

                                          Substitute the injectivity consequence of an equality h between interaction-tree constructors.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            itree_elim heq where heq is an equality between ITrees tries to to prove False using heq.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              proveUnfoldLemma tries to finish a proof of an unfolding lemma defined by corec' Note you have to first unfold corec' in the appropriate places, possibly by some combination of conv and rw [PFunctor.M.unfold_corec'].

                                              Equations
                                              Instances For
                                                inductive Lean4Itree.ITree.IEqF {ε : Type u1 → Type v} {ρ : Type u2} (sim : ITree ε ρITree ε ρProp) :
                                                ITree ε ρITree ε ρProp

                                                One unfolding of the bisimulation functor: two interaction trees agree at the top constructor, with their immediate subtrees related by sim. The bisimulation equality IEq is the fixed point of IEqF.

                                                Instances For
                                                  theorem Lean4Itree.ITree.IEqF_inv {ε : Type u1 → Type v} {ρ : Type u2} (sim : ITree ε ρITree ε ρProp) (t1 t2 : ITree ε ρ) (h : IEqF sim t1 t2) :
                                                  (∃ (v : ρ), t1 = ret v t2 = ret v) (∃ (α : Type u1) (e : ε α) (k1 : αITree ε ρ) (k2 : αITree ε ρ), (∀ (a : α), sim (k1 a) (k2 a)) t1 = vis e k1 t2 = vis e k2) ∃ (t1' : ITree ε ρ) (t2' : ITree ε ρ), sim t1' t2' t1 = t1'.tau t2 = t2'.tau
                                                  theorem Lean4Itree.ITree.IEqF_monotone {ε : Type u1 → Type v} {ρ : Type u2} (sim sim' : ITree ε ρITree ε ρProp) (hsim : ∀ (t1 t2 : ITree ε ρ), sim t1 t2sim' t1 t2) (t1 t2 : ITree ε ρ) :
                                                  IEqF sim t1 t2IEqF sim' t1 t2
                                                  @[irreducible]
                                                  def Lean4Itree.ITree.IEq {ε : Type u1 → Type v} {ρ : Type u2} (t1 t2 : ITree ε ρ) :

                                                  Custom equality predicate between ITrees

                                                  Equations
                                                  Instances For
                                                    theorem Lean4Itree.ITree.ieq_iff_eq {ε : Type u1 → Type v} {ρ : Type u2} (t1 t2 : ITree ε ρ) :
                                                    t1.IEq t2 t1 = t2
                                                    theorem Lean4Itree.ITree.ieq_rfl {ε : Type u1 → Type v} {ρ : Type u2} {sim : ITree ε ρITree ε ρProp} {hsim : ∀ (t1 t2 : ITree ε ρ), t1.IEq t2sim t1 t2} (t : ITree ε ρ) :
                                                    IEqF sim t t