Documentation

Cslib.Computability.CombinatoryLogic.Basic

Basic results for the SKI calculus #

Main definition #

Notation #

Main results #

References #

For a presentation of the bracket abstraction algorithm see: https://web.archive.org/web/19970727171324/http://www.cs.oberlin.edu/classes/cs280/labs/lab4/lab43.html#@l13

Polynomials and the bracket astraction algorithm #

inductive SKI.Polynomial (n : ) :

A polynomial is an SKI terms with free variables.

Instances For

    Application between polynomials

    Equations
    Instances For

      Notation by analogy with pointers in C

      Equations
      Instances For
        def SKI.Polynomial.eval {n : } (Γ : SKI.Polynomial n) (l : List SKI) (hl : l.length = n) :

        Substitute terms for the free variables of a polynomial

        Equations
        Instances For

          A polynomial with no free variables is a term

          Equations
          Instances For

            Inductively define a polynomial Γ' so that (up to the fact that we haven't defined reduction on polynomials) Γ' ⬝ t ⇒* Γ[xₙ ← t].

            Equations
            Instances For
              @[irreducible]
              theorem SKI.Polynomial.elimVar_correct {n : } (Γ : SKI.Polynomial (n + 1)) {ys : List SKI} (hys : ys.length = n) (z : SKI) :
              ((Γ.elimVar.eval ys hys).app z).MRed (Γ.eval (ys ++ [z]) )

              Correctness for the elimVar algorithm, which provides the inductive step of the bracket abstraction algorithm. We induct backwards on the list, corresponding to applying the transformation from the inside out. Since we haven't defined reduction for polynomials, we substitute arbitrary terms for the inner variables.

              Bracket abstraction, by induction using SKI.Polynomial.elimVar

              Equations
              Instances For
                theorem SKI.Polynomial.toSKI_correct {n : } (Γ : SKI.Polynomial n) (xs : List SKI) (hxs : xs.length = n) :
                (Γ.toSKI.applyList xs).MRed (Γ.eval xs hxs)

                Correctness for the toSKI (bracket abstraction) algorithm.

                Basic auxiliary combinators. #

                Each combinator is defined by a polynomial, which is then proved to have the reduction property we want. Before each definition we provide its lambda calculus equivalent. If there is accepted notation for a given combinator, we use that (given everywhere a capital letter), otherwise we choose a descriptive name.

                Reversal: R := λ x y. y x

                Equations
                Instances For
                  def SKI.R :

                  A SKI term representing R

                  Equations
                  Instances For
                    theorem SKI.R_def (x y : SKI) :
                    ((R.app x).app y).MRed (y.app x)

                    Composition: B := λ f g x. f (g x)

                    Equations
                    Instances For
                      def SKI.B :

                      A SKI term representing B

                      Equations
                      Instances For
                        theorem SKI.B_def (f g x : SKI) :
                        (((B.app f).app g).app x).MRed (f.app (g.app x))

                        C := λ f x y. f y x

                        Equations
                        Instances For
                          def SKI.C :

                          A SKI term representing C

                          Equations
                          Instances For
                            theorem SKI.C_def (f x y : SKI) :
                            (((C.app f).app x).app y).MRed ((f.app y).app x)

                            Rotate right: RotR := λ x y z. z x y

                            Equations
                            Instances For

                              A SKI term representing RotR

                              Equations
                              Instances For
                                theorem SKI.rotR_def (x y z : SKI) :
                                (((RotR.app x).app y).app z).MRed ((z.app x).app y)

                                Rotate left: RotR := λ x y z. y z x

                                Equations
                                Instances For

                                  A SKI term representing RotL

                                  Equations
                                  Instances For
                                    theorem SKI.rotL_def (x y z : SKI) :
                                    (((RotL.app x).app y).app z).MRed ((y.app z).app x)

                                    Self application: δ := λ x. x x

                                    Equations
                                    Instances For
                                      def SKI.δ :

                                      A SKI term representing δ

                                      Equations
                                      Instances For
                                        theorem SKI.δ_def (x : SKI) :
                                        (δ.app x).MRed (x.app x)

                                        H := λ f x. f (x x)

                                        Equations
                                        Instances For
                                          def SKI.H :

                                          A SKI term representing H

                                          Equations
                                          Instances For
                                            theorem SKI.H_def (f x : SKI) :
                                            ((H.app f).app x).MRed (f.app (x.app x))

                                            Curry's fixed-point combinator: Y := λ f. H f (H f)

                                            Equations
                                            Instances For
                                              def SKI.Y :

                                              A SKI term representing Y

                                              Equations
                                              Instances For
                                                theorem SKI.Y_def (f : SKI) :
                                                (Y.app f).MRed ((H.app f).app (H.app f))
                                                theorem SKI.Y_correct (f : SKI) :
                                                (Y.app f).CommonReduct (f.app (Y.app f))

                                                The fixed-point property of the Y-combinator

                                                It is useful to be able to produce a term such that the fixed point property holds on-the-nose, rather than up to a common reduct. An alternative is to use Turing's fixed-point combinator (defined below).

                                                Equations
                                                Instances For

                                                  Auxiliary definition for Turing's fixed-point combinator: ΘAux := λ x y. y (x x y)

                                                  Equations
                                                  Instances For

                                                    A term representing ΘAux

                                                    Equations
                                                    Instances For
                                                      theorem SKI.ΘAux_def (x y : SKI) :
                                                      ((ΘAux.app x).app y).MRed (y.app ((x.app x).app y))
                                                      def SKI.Θ :

                                                      Turing's fixed-point combinator: Θ := (λ x y. y (x x y)) (λ x y. y (x x y))

                                                      Equations
                                                      Instances For
                                                        theorem SKI.Θ_correct (f : SKI) :
                                                        (Θ.app f).MRed (f.app (Θ.app f))

                                                        A SKI term representing Θ

                                                        Church Booleans #

                                                        def SKI.IsBool (u : Bool) (a : SKI) :

                                                        A term a represents the boolean value u if it is βη-equivalent to a standard Church boolean.

                                                        Equations
                                                        Instances For
                                                          theorem SKI.isBool_trans (u : Bool) (a a' : SKI) (h : a.MRed a') (ha' : IsBool u a') :
                                                          IsBool u a
                                                          def SKI.TT :

                                                          Standard true: TT := λ x y. x

                                                          Equations
                                                          Instances For
                                                            def SKI.FF :

                                                            Standard false: FF := λ x y. y

                                                            Equations
                                                            Instances For

                                                              Conditional: Cond x y b := if b then x else y

                                                              Equations
                                                              Instances For
                                                                theorem SKI.cond_correct (a x y : SKI) (u : Bool) (h : IsBool u a) :
                                                                (((SKI.Cond.app x).app y).app a).MRed (if u = true then x else y)

                                                                Neg := λ a. Cond FF TT a

                                                                Equations
                                                                Instances For
                                                                  theorem SKI.neg_correct (a : SKI) (ua : Bool) (h : IsBool ua a) :

                                                                  And := λ a b. Cond (Cond TT FF b) FF a

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

                                                                    A SKI term representing And

                                                                    Equations
                                                                    Instances For
                                                                      theorem SKI.and_def (a b : SKI) :
                                                                      ((SKI.And.app a).app b).MRed (((SKI.Cond.app (((SKI.Cond.app TT).app FF).app b)).app FF).app a)
                                                                      theorem SKI.and_correct (a b : SKI) (ua ub : Bool) (ha : IsBool ua a) (hb : IsBool ub b) :
                                                                      IsBool (ua && ub) ((SKI.And.app a).app b)

                                                                      Or := λ a b. Cond TT (Cond TT FF b) b

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

                                                                        A SKI term representing Or

                                                                        Equations
                                                                        Instances For
                                                                          theorem SKI.or_def (a b : SKI) :
                                                                          ((SKI.Or.app a).app b).MRed (((SKI.Cond.app TT).app (((SKI.Cond.app TT).app FF).app b)).app a)
                                                                          theorem SKI.or_correct (a b : SKI) (ua ub : Bool) (ha : IsBool ua a) (hb : IsBool ub b) :
                                                                          IsBool (ua || ub) ((SKI.Or.app a).app b)

                                                                          Pairs #

                                                                          MkPair := λ a b. ⟨a,b⟩

                                                                          Equations
                                                                          Instances For

                                                                            First projection

                                                                            Equations
                                                                            Instances For

                                                                              Second projection

                                                                              Equations
                                                                              Instances For
                                                                                theorem SKI.fst_correct (a b : SKI) :
                                                                                (Fst.app ((MkPair.app a).app b)).MRed a
                                                                                theorem SKI.snd_correct (a b : SKI) :
                                                                                (Snd.app ((MkPair.app a).app b)).MRed b

                                                                                A term representing Unpaired

                                                                                Equations
                                                                                Instances For
                                                                                  theorem SKI.unpaired_def (f p : SKI) :
                                                                                  ((SKI.Unpaired.app f).app p).MRed ((f.app (Fst.app p)).app (Snd.app p))
                                                                                  theorem SKI.unpaired_correct (f x y : SKI) :
                                                                                  ((SKI.Unpaired.app f).app ((MkPair.app x).app y)).MRed ((f.app x).app y)

                                                                                  A SKI term representing Pair

                                                                                  Equations
                                                                                  Instances For
                                                                                    theorem SKI.pair_def (f g x : SKI) :
                                                                                    (((SKI.Pair.app f).app g).app x).MRed ((MkPair.app (f.app x)).app (g.app x))