Documentation

Cslib.Languages.CombinatoryLogic.List

Church-Encoded Lists in SKI Combinatory Logic #

Church-encoded lists for proving SKI ≃ TM equivalence. A list is encoded as λ c n. c a₀ (c a₁ (... (c aₖ n)...)) where each aᵢ is a Church numeral.

Church List Representation #

A term correctly Church-encodes a list of natural numbers.

Equations
Instances For
    theorem Cslib.SKI.isChurchList_trans {ns : List } {cns cns' : SKI} (h : Relation.ReflTransGen Red cns cns') (hcns' : IsChurchList ns cns') :

    IsChurchList is preserved under multi-step reduction of the term.

    structure Cslib.SKI.IsChurchListPair (prev curr : List ) (p : SKI) :

    Both components of a pair are Church lists.

    Instances For
      theorem Cslib.SKI.isChurchListPair_trans {prev curr : List } {p p' : SKI} (hp : Relation.ReflTransGen Red p p') (hp' : IsChurchListPair prev curr p') :
      IsChurchListPair prev curr p

      IsChurchListPair is preserved under reduction.

      Nil: The empty list #

      The SKI term for the empty list.

      Equations
      Instances For

        Reduction: Nil ⬝ c ⬝ n ↠ n.

        The empty list term correctly represents [].

        Cons: Consing an element onto a list #

        The SKI term for list cons.

        Equations
        Instances For
          theorem Cslib.SKI.List.cons_def (x xs c n : SKI) :
          Relation.ReflTransGen Red ((((Cons.app x).app xs).app c).app n) ((c.app x).app ((xs.app c).app n))

          Reduction: Cons ⬝ x ⬝ xs ⬝ c ⬝ n ↠ c ⬝ x ⬝ (xs ⬝ c ⬝ n).

          theorem Cslib.SKI.List.cons_correct {x : } {xs : List } {cx cxs : SKI} (hcx : IsChurch x cx) (hcxs : IsChurchList xs cxs) :
          IsChurchList (x :: xs) ((Cons.app cx).app cxs)

          Cons preserves Church list representation.

          theorem Cslib.SKI.List.singleton_correct {x : } {cx : SKI} (hcx : IsChurch x cx) :

          Singleton list correctness.

          @[simp]

          toChurch (x :: xs) = Cons ⬝ SKI.toChurch x ⬝ toChurch xs.

          toChurch ns correctly represents ns.

          Head: Extract the head of a list #

          The SKI term for list head with default.

          Equations
          Instances For

            Reduction: HeadD ⬝ d ⬝ xs ↠ xs ⬝ K ⬝ d.

            theorem Cslib.SKI.List.headD_correct {d : } {cd : SKI} (hcd : IsChurch d cd) {ns : List } {cns : SKI} (hcns : IsChurchList ns cns) :
            IsChurch (ns.headD d) ((HeadD.app cd).app cns)

            General head-with-default correctness.

            The SKI term for list head (default 0).

            Equations
            Instances For

              Reduction: Head ⬝ xs ↠ xs ⬝ K ⬝ Zero.

              theorem Cslib.SKI.List.head_correct (ns : List ) (cns : SKI) (hcns : IsChurchList ns cns) :
              IsChurch (ns.headD 0) (Head.app cns)

              Head correctness (default 0).

              Tail: Extract the tail of a list #

              Step function for tail: (prev, curr) → (curr, cons h curr)

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

                The step function for computing list tail.

                Equations
                Instances For

                  Reduction of the tail step function.

                  tail xs = Fst (xs TailStep (MkPair Nil Nil))

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

                    The tail of a Church-encoded list.

                    Equations
                    Instances For

                      Reduction: Tail ⬝ xs ↠ Fst ⬝ (xs ⬝ TailStep ⬝ (MkPair ⬝ Nil ⬝ Nil)).

                      @[simp]

                      The initial pair (nil, nil) satisfies the invariant.

                      theorem Cslib.SKI.List.tailStep_correct {x : } {xs : List } {cx p : SKI} (hcx : IsChurch x cx) (hp : IsChurchListPair xs.tail xs p) :
                      IsChurchListPair xs (x :: xs) ((TailStep.app cx).app p)

                      The step function preserves the tail-computing invariant.

                      theorem Cslib.SKI.List.tail_correct (ns : List ) (cns : SKI) (hcns : IsChurchList ns cns) :

                      Tail correctness.

                      Prepending zero to a list (for Code.zero') #

                      Prepend zero to a Church-encoded list.

                      Equations
                      Instances For
                        theorem Cslib.SKI.List.prependZero_correct {ns : List } {cns : SKI} (hcns : IsChurchList ns cns) :

                        Prepending zero preserves Church list representation.

                        Successor on list head (for Code.succ) #

                        theorem Cslib.SKI.List.succHead_correct (ns : List ) (cns : SKI) (hcns : IsChurchList ns cns) :

                        SuccHead correctly computes a singleton containing succ(head ns).