Documentation

Cslib.Languages.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 Cslib.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 Cslib.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 Cslib.SKI.Polynomial.elimVar_correct {n : } (Γ : SKI.Polynomial (n + 1)) {ys : List SKI} (hys : ys.length = n) (z : SKI) :
              RedSKI.MRed ((Γ.elimVar.eval ys hys).app z) (Γ.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 Cslib.SKI.Polynomial.toSKI_correct {n : } (Γ : SKI.Polynomial n) (xs : List SKI) (hxs : xs.length = n) :
                RedSKI.MRed (Γ.toSKI.applyList xs) (Γ.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

                  A SKI term representing R

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

                    A SKI term representing B

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

                      A SKI term representing C

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

                        A SKI term representing RotR

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

                          A SKI term representing RotL

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

                            Self application: δ := λ x. x x

                            Equations
                            Instances For

                              A SKI term representing δ

                              Equations
                              Instances For
                                theorem Cslib.SKI.del_def (x : SKI) :
                                RedSKI.MRed (Del.app x) (x.app x)

                                A SKI term representing H

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

                                  A SKI term representing Y

                                  Equations
                                  Instances For
                                    theorem Cslib.SKI.Y_def (f : SKI) :
                                    RedSKI.MRed (Y.app f) ((H.app f).app (H.app f))
                                    theorem Cslib.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 Cslib.SKI.ThAux_def (x y : SKI) :
                                          RedSKI.MRed ((ThAux.app x).app y) (y.app ((x.app x).app y))

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

                                          Equations
                                          Instances For
                                            theorem Cslib.SKI.Th_correct (f : SKI) :
                                            RedSKI.MRed (Th.app f) (f.app (Th.app f))

                                            A SKI term representing Θ

                                            Church Booleans #

                                            def Cslib.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 Cslib.SKI.isBool_trans (u : Bool) (a a' : SKI) (h : RedSKI.MRed a a') (ha' : IsBool u a') :
                                              IsBool u a

                                              Standard true: TT := λ x y. x

                                              Equations
                                              Instances For

                                                Standard false: FF := λ x y. y

                                                Equations
                                                Instances For

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

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

                                                    Neg := λ a. Cond FF TT a

                                                    Equations
                                                    Instances For
                                                      theorem Cslib.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 Cslib.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

                                                            A SKI term representing Or

                                                            Equations
                                                            Instances For
                                                              theorem Cslib.SKI.or_def (a b : SKI) :
                                                              theorem Cslib.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

                                                                    Unpaired f ⟨x, y⟩ := f x y, cf Nat.unparied.

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

                                                                      A term representing Unpaired

                                                                      Equations
                                                                      Instances For
                                                                        theorem Cslib.SKI.unpaired_correct (f x y : SKI) :
                                                                        RedSKI.MRed ((SKI.Unpaired.app f).app ((MkPair.app x).app y)) ((f.app x).app y)

                                                                        Pair f g x := ⟨f x, g x⟩, cf Primrec.Pair.

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

                                                                          A SKI term representing Pair

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