Basic results for the SKI calculus #
Main definition #
Polynomial
: the type of SKI terms with fixed number of "holes" (read: free variables).
Notation #
⬝'
: application between polynomials,&i
: the ith free variable of a polynomial.
Main results #
- Bracket abstraction: an algorithm
Polynomial.toSKI
to convert a polynomial $Γ(x_0, ..., x_{n-1})$ into a term such that (Polynomial.toSKI_correct
)Γ.toSKI ⬝ t₁ ⬝ ... ⬝ tₙ
reduces toΓ(t₁, ..., tₙ)
.
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 #
A polynomial is an SKI terms with free variables.
- term {n : ℕ} : SKI → SKI.Polynomial n
- var {n : ℕ} : Fin n → SKI.Polynomial n
- app {n : ℕ} : SKI.Polynomial n → SKI.Polynomial n → SKI.Polynomial n
Instances For
Application between polynomials
Equations
- SKI.«term_⬝'_» = Lean.ParserDescr.trailingNode `SKI.«term_⬝'_» 100 100 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⬝' ") (Lean.ParserDescr.cat `term 101))
Instances For
Notation by analogy with pointers in C
Equations
- SKI.«term&_» = Lean.ParserDescr.node `SKI.«term&_» 101 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "&") (Lean.ParserDescr.cat `term 101))
Instances For
Equations
- SKI.CoeTermPolynomial n = { coe := SKI.Polynomial.term }
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
- (SKI.Polynomial.term x_1).elimVar = (SKI.Polynomial.term SKI.K).app (SKI.Polynomial.term x_1)
- (SKI.Polynomial.var i).elimVar = if h : ↑i < n then (SKI.Polynomial.term SKI.K).app (SKI.Polynomial.var (Fin.ofNat n ↑i)) else SKI.Polynomial.term SKI.I
- (Γ.app Δ).elimVar = ((SKI.Polynomial.term SKI.S).app Γ.elimVar).app Δ.elimVar
Instances For
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
Instances For
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
Composition: B := λ f g x. f (g x)
Equations
- SKI.BPoly = (SKI.Polynomial.var 0).app ((SKI.Polynomial.var 1).app (SKI.Polynomial.var 2))
Instances For
C := λ f x y. f y x
Equations
- SKI.CPoly = ((SKI.Polynomial.var 0).app (SKI.Polynomial.var 2)).app (SKI.Polynomial.var 1)
Instances For
Rotate right: RotR := λ x y z. z x y
Equations
- SKI.RotRPoly = ((SKI.Polynomial.var 2).app (SKI.Polynomial.var 0)).app (SKI.Polynomial.var 1)
Instances For
Rotate left: RotR := λ x y z. y z x
Equations
- SKI.RotLPoly = ((SKI.Polynomial.var 1).app (SKI.Polynomial.var 2)).app (SKI.Polynomial.var 0)
Instances For
Self application: δ := λ x. x x
Equations
Instances For
H := λ f x. f (x x)
Equations
- SKI.HPoly = (SKI.Polynomial.var 0).app ((SKI.Polynomial.var 1).app (SKI.Polynomial.var 1))
Instances For
Curry's fixed-point combinator: Y := λ f. H f (H f)
Equations
- SKI.YPoly = ((SKI.Polynomial.term SKI.H).app (SKI.Polynomial.var 0)).app ((SKI.Polynomial.term SKI.H).app (SKI.Polynomial.var 0))
Instances For
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).
Instances For
Auxiliary definition for Turing's fixed-point combinator: ΘAux := λ x y. y (x x y)
Equations
- SKI.ΘAuxPoly = (SKI.Polynomial.var 1).app (((SKI.Polynomial.var 0).app (SKI.Polynomial.var 0)).app (SKI.Polynomial.var 1))
Instances For
Church Booleans #
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
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
Pairs #
Unpaired f ⟨x, y⟩ := f x y, cf Nat.unparied
.
Equations
- SKI.UnpairedPoly = ((SKI.Polynomial.var 0).app ((SKI.Polynomial.term SKI.Fst).app (SKI.Polynomial.var 1))).app ((SKI.Polynomial.term SKI.Snd).app (SKI.Polynomial.var 1))
Instances For
A term representing Unpaired
Equations
Instances For
Pair f g x := ⟨f x, g x⟩, cf Primrec.Pair
.
Equations
- SKI.PairPoly = ((SKI.Polynomial.term SKI.MkPair).app ((SKI.Polynomial.var 0).app (SKI.Polynomial.var 2))).app ((SKI.Polynomial.var 1).app (SKI.Polynomial.var 2))