Documentation

Cslib.Languages.CombinatoryLogic.Evaluation

Evaluation results #

This file formalises evaluation and normal forms of SKI terms.

Main definitions #

Main results #

References #

This file draws heavily from https://gist.github.com/b-mehta/e412c837818223b8f16ca0b4aa19b166.

The predicate that a term has no reducible sub-terms.

Equations
Instances For
    def Cslib.SKI.evalStep (x : SKI) :
    PLift x.RedexFree โŠ• SKI

    One-step evaluation as a function: either it returns a term that has been reduced by one step, or a proof that the term is redex free. Uses normal-order reduction.

    Equations
    Instances For
      theorem Cslib.SKI.evalStep_right_correct (x y : SKI) :
      x.evalStep = Sum.inr y โ†’ x.Red y

      The normal-order reduction implemented by evalStep indeed computes a one-step reduction.

      A term is redex free iff it has no one-step reductions.

      @[implicit_reducible]
      Equations
      theorem Cslib.SKI.redexFree_iff_mred_eq {x : SKI} :
      x.RedexFree โ†” โˆ€ (y : SKI), Relation.ReflTransGen Red x y โ†” x = y

      A term is redex free iff its only many-step reduction is itself.

      theorem Cslib.SKI.mJoin_red_redexFree {x y : SKI} (hy : y.RedexFree) (h : Relation.MJoin Red x y) :
      Relation.ReflTransGen Red x y

      If a term has a common reduct with a normal term, it in fact reduces to that term.

      theorem Cslib.SKI.confluent_redexFree {x y z : SKI} (hxy : Relation.ReflTransGen Red x y) (hxz : Relation.ReflTransGen Red x z) (hz : z.RedexFree) :
      Relation.ReflTransGen Red y z

      If x reduces to both y and z, and z is not reducible, then y reduces to z.

      theorem Cslib.SKI.unique_normal_form {x y z : SKI} (hxy : Relation.ReflTransGen Red x y) (hxz : Relation.ReflTransGen Red x z) (hy : y.RedexFree) (hz : z.RedexFree) :
      y = z

      If x reduces to both y and z, and both y and z are in normal form, then they are equal.

      theorem Cslib.SKI.eq_of_mJoin_red_redexFree {x y : SKI} (h : Relation.MJoin Red x y) (hx : x.RedexFree) (hy : y.RedexFree) :
      x = y

      If x and y are normal and have a common reduct, then they are equal.

      Injectivity for datatypes #

      theorem Cslib.SKI.isBool_injective (x y : SKI) (u v : Bool) (hx : IsBool u x) (hy : IsBool v y) (hxy : Relation.MJoin Red x y) :
      u = v

      Injectivity for booleans.

      def Cslib.SKI.churchK :
      โ„• โ†’ SKI

      A specialisation of Church : Nat โ†’ SKI.

      Equations
      Instances For
        @[simp]
        theorem Cslib.SKI.churchK_size (n : โ„•) :
        (churchK n).size = n + 1
        theorem Cslib.SKI.isChurch_injective (x y : SKI) (n m : โ„•) (hx : IsChurch n x) (hy : IsChurch m y) (hxy : Relation.MJoin Red x y) :
        n = m

        Injectivity for Church numerals

        theorem Cslib.SKI.rice {P : SKI} (hP : โˆ€ (x : SKI), Relation.ReflTransGen Red (P.app x) TT โˆจ Relation.ReflTransGen Red (P.app x) FF) (hxt : โˆƒ (x : SKI), Relation.ReflTransGen Red (P.app x) TT) (hxf : โˆƒ (x : SKI), Relation.ReflTransGen Red (P.app x) FF) :
        False

        Rice's theorem: no SKI term is a non-trivial predicate.

        More specifically, say a term P is a predicate if, for every term x, P ยท x reduces to either TT or FF. A predicate P is trivial if either it always reduces to true, or always to false. This version of Rice's theorem derives a contradiction from the existence of a predicate P and the existence of terms x for which P ยท x is true (P ยท x โ†  TT) and for which P ยท x is false (P ยท x โ†  FF).

        theorem Cslib.SKI.rice' {P : SKI} (hP : โˆ€ (x : SKI), Relation.ReflTransGen Red (P.app x) TT โˆจ Relation.ReflTransGen Red (P.app x) FF) :
        (โˆ€ (x : SKI), Relation.ReflTransGen Red (P.app x) TT) โˆจ โˆ€ (x : SKI), Relation.ReflTransGen Red (P.app x) FF

        Rice's theorem: any SKI predicate is trivial.

        This version of Rice's theorem proves (classically) that any SKI predicate P either is constantly true (ie P ยท x โ†  TT for every x) or is constantly false (P ยท x โ†  FF for every x).