[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::languages

Title:Languages
Notice:Speaking In Tongues
Moderator:TLE::TOKLAS::FELDMAN
Created:Sat Jan 25 1986
Last Modified:Wed May 21 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:394
Total number of notes:2683

205.0. "Lambda calculus question" by STARZ::LOHMILLER (Contents may settle) Tue Oct 18 1988 19:03

I'm not a frequent visitor to this conference, but I noticed some discussion
of functional languages in previous notes so I hope this is the right place
to post this question.

Does anyone here remember "Lambda Calculus"?  This problem came up in school
a few years ago but I was never able to solve it.  

There is a theorem, although I have not seen the proof, that all lambda
combinators may be written in terms of the following two combinators along
with an arbitrary number of parenthesis for grouping:

	S = Lxyz. x z ( y z )

	K = Lxy. x                                               

(I'm using "L" where most books use the Greek character "lambda".)

For example, the identity combinator, I = Lx. x, may be obtained by writing
                                                                       
	SKK 	= Lz. K z ( K z)

		= Lz . z

		= Lx. x
                                                       
	
I have not been able to find a way to derive the combinator which swaps
it's arguments: Lxy. y x
                        
How is this expression derived?

Has anyone seen the proof of the above mentioned theorem?

    
T.RTitleUserPersonal
Name
DateLines
205.1A proof of the theoremCRLVMS::SCHAFFERTCraig SchaffertFri Oct 21 1988 18:3768
I don't have a reference for the theorem you mentioned, but the proof is fairly
easy.  Here goes.

The set of general lambda expressions is generated as follows:

Start with a set of symbols V, consisting of variables and constants.
(1) Each symbol in V is a lambda expression.
(2) If x is a variable, and A is a lambda expression, then Lx.A is a lambda
    expression.
(3) If A and B are lambda expressions, then (A B) is a lambda expression.

The set of SK-expressions is generated in the same fashion, but combinators S
and K are added to V, and rule (2) is disallowed.  The definitions of S and K
are
    S = Lxyz. x z (y z)
    K = Lxy. x

Note that we omit extraneous parenthesis -- "x y z" is really "((x y) z)".  We
also group lambdas -- "Lxyz." is really "Lx.Ly.Lz.".

THEOREM:  For every lambda expression there is an equivalent SK-expression.

First we need a definition, and a lemma.  Let's call a lambda expression Lx.A,
where A has no uses of rule (2), a "simple" lambda expression.

LEMMA:  For every simple lambda expression, there is an equivalent
        SK-expression.

Proof of Lemma:

Assume false.  Of all the simple expressions that do not have SK-equivalents,
pick one (Lx.A) of minimal length.  So all simple expressions shorter than Lx.A
do have SK-equivalents.

Expression A must have one of two forms: a variable v, or an application
(B C).  It cannot have the form Ly.D because Lx.A is simple.  Case analysis:

(1) A = v where v ~= x:  Lx.A = Lx.v = Kv. So Lx.A has an SK-equivalent.

(2) A = v where v = x: Lx.A = Lx.x = I = SKK. So Lx.A has an SK-equivalent.

(3) A = BC: Lx.A = Lx. B ( C )
                 = Lx. (Lx.B) x ( (Lx.C) x )          since B = (Lx.B)x
                 = Lz. (Lx.B) z ( (Lx.C) z )
                 = S(Lx.B)(Lx.C)

    Now, Lx.B and Lx.C are both shorter than Lx.A, so they have SK-equivalents.
    Denote these by B' and C'.  Lx.A = S(B')(C').  Again, Lx.A has an
    SK-equivalent.

Thus, the Lemma cannot be false.

Proof of Theorem:

Given any general lambda expression E, pick an "innermost" Lx.  That is, find a
contained simple lambda expression.  If there is none, then E is already an
SK-expression.  If you find one, replace it with an SK-equivalent.  This
reduced the number of Lx. constructs by one.  Repeat.  Done.

------------------------------------------------------------------------

Applying the above construction (with shortcuts) we get

    Lxy. x y = S (K(S(SKK))) (S(KK)(SKK))

Presumably this could be simplified, but I'm too lazy at the moment.

                                            -- Craig
205.2Belated thanksSTARZ::LOHMILLERContents may settleFri Nov 18 1988 12:063
    Thanks Craig.  That seems to do the trick.