-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imported solutions to all exercises.
- Loading branch information
0 parents
commit 964127c
Showing
4 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# See http://github.com/raganwald/homoiconic/tree/master/2008-11-12/combinator_chemistry.md | ||
|
||
** Intro | ||
|
||
sxyz = xz(yz) | ||
kxy = x | ||
|
||
** Exercises | ||
|
||
(ss)kkk = sk(kk)k = kk((kk)k) = kkk = k | ||
kkk(ss) = k(ss) | ||
(kk)(kk)(kk) = k(kk) | ||
(kkk)(kkk)(kkk) = k(kkk)(kkk) = (kkk) = k | ||
|
||
k = k | ||
kk = kk | ||
kkk = k | ||
kkkk = kk | ||
kkkkk = kkk = k | ||
kkkkkk = kkkk = kk | ||
kkkkkkk = kkkkk = kkk = k | ||
|
||
A little more advanced exerciaes: is there a molecule, let us called it I, having the following dynamic: (X refers to any molecule). | ||
|
||
Ix = x I=? | ||
|
||
I = k - | ||
I = s - | ||
I = ks - | ||
I = sk - | ||
I = kk - | ||
I = ss - | ||
I = sss - | ||
I = skk skkx = kx(kx) = x | ||
|
||
Ix = skkx = kx(kx) = x | ||
|
||
** New programming exercises: | ||
|
||
Find combinators M, B, W, L, T such that | ||
|
||
Mx = xx | ||
|
||
*** Solution | ||
|
||
xx = Ix(Ix) = SIIx => M = SII | ||
|
||
** B | ||
Bxyz = x(yz) | ||
|
||
*** Solution | ||
|
||
x(yz) = S?yz, ?z = x. Kxz = x => x(yz) = S(Kx)yz = ((KS)x)(Kx)yz = S(KS)Kxyz | ||
B = S(KS)K | ||
|
||
** W | ||
|
||
Wxy = xyy | ||
|
||
*** Solution | ||
|
||
xyy = (xy)y = | ||
= (xy)(?xy) = (xy)(KIxy) = Sx(KIx)y = Sx((KI)x)y | ||
= SS(KI)xy | ||
|
||
*** Check: | ||
SS(KI)xy = Sx(KIx)y = xy(KIxy) = xy(Iy) = xyy | ||
W = SS(KI) | ||
|
||
** L | ||
Lxy = x(yy) | ||
|
||
*** Solution | ||
|
||
Lxy = x(yy) = (Kxy)(yy) = S(Kx)yy = (KSx)(Kx)yy = S(KS)Kxyy = | ||
S(KS)K(Wxy) | ||
Lxy = x(yy) = x(My) = (Kxy)(My) = S(Kx)My = (KSx)(Kx)My = S(KS)KxMy | ||
|
||
S(Kx)yy = ?xy | ||
|
||
|
||
S(Kx)y = ?x | ||
|
||
Lxy = x(yy) | ||
|
||
x(yy) = Kxy(yy) = S(Kx)My = S(Kx)My = (KSx)(Kx)My = S(KS)KxMy = | ||
(S(KS)Kx)(KMx)y = S(S(KS)K)(KM)xy | ||
|
||
L = S(S(KS)K)(KM) | ||
|
||
*** Check | ||
|
||
S(S(KS)K)(KM)xy = S(KS)Kx(KMx)y = S(KS)KxMy = (KSx)(Kx)My = S(Kx)My = | ||
(Kxy)(My) = x(My) = x(yy) | ||
|
||
*** Another solution | ||
|
||
x(yy) = Bxyy = (Bx)yy = W(Bx)y = BWBxy | ||
|
||
*** check | ||
|
||
BWBxy = W(Bx)y -- dynamics of B | ||
= (Bx)yy -- dynamics of W | ||
= Bxyy | ||
= x(yy) | ||
|
||
** T | ||
|
||
Txy = yx | ||
|
||
*** Solution | ||
|
||
yx = y(Kxy) = (Iy)(Kxy) = SI(Kx)y = (K(SI)x)(Kx)y = S(K(SI))Kxy | ||
|
||
T = S(K(SI))K | ||
|
||
Txy = S(K(SI))Kxy = (K(SI)x)(Kx)y = SI(Kx)y = Iy(Kxy) = yx | ||
|
||
*** Another | ||
|
||
yx = y(Kxy) = SI(Kx)y = B(SI)Kxy | ||
|
||
** C | ||
|
||
Cxyz = xzy | ||
|
||
*** Solution 1 | ||
|
||
xzy = xz(Kyz) = Sx(Ky)z = K(Sx)y(Ky)z = S(K(Sx))Kyz = S((KKx)(Sx))Kyz | ||
= S(S(KK)Sx)Kyz = ((KS)x)((S(KK)S)x)Kyz | ||
= S(KS)(S(KK)S)xK yz = ;; (K = (KKx)) | ||
= S(KS)(S(KK)S)x((KK)x) yz | ||
= S(S(KS)(S(KK)S))(KK)xyz | ||
|
||
C = S(S(KS)(S(KK)S))(KK) | ||
|
||
*** Solution 2 | ||
|
||
xzy = xz(Kyz) = Sx(Ky)z = B(Sx)Kyz = BBSxKyz = BBSx(KKx)yz | ||
= S(BBS)(KK)xyz | ||
|
||
C = S(BBS)(KK) | ||
|
||
** INFINITY | ||
|
||
INFINITY dynamically transform into INFINITY itself. | ||
|
||
*** Solution | ||
|
||
MM = MM, thus, | ||
INFINITY = MM | ||
|
||
** S | ||
|
||
We have seen how to program the blue bird B, the cardinal C and the | ||
Warbler W with the kestrel K and the starling S. Could you define the | ||
starling S from B, W and C? I give you the first line: | ||
|
||
Sxyz = xz(yz) | ||
= Cx(yz)z | ||
= B(Cx)yzz | ||
= (B(Cx)y)zz | ||
= W(B(Cx)y)z | ||
= W(BBCxy)z | ||
= W((BBCx)y)z | ||
= BW(BBCx)yz | ||
= BW((BBC)x)yz | ||
= B(BW)(BBC)xyz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Find file: ~/Projects/combinators/[exercises.txt] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
* Question: is there a systematic method such that giving any behavior like | ||
|
||
Xxyztuv = x(yx)(uvut) (or what you want) | ||
|
||
can generate systematically a corresponding SK or BWCK -combinator? The answer is yes. I let you meditate the question. (This point will be made clear when we will meet the terrible little cousins of the combinators which are the lambda expression, (and which in our context will just abbreviate complex combinators), but I propose to progress and make sure that the SK combinator are Turing Universal. | ||
|
||
I am not yet decided when I really should introduce you to the paradoxical combinators, which are rather crazy. Smullyan call them wise birds, but I guess it is an euphemism! | ||
|
||
Mmhhh... Showing turing-universality through the use of some paradoxical combinator is easy (once we have defined the numbers), but there is a risk you take bad habits! Actually we don't need the paradoxical combinators to prove the turing universality of the SK forest, mmmmh... | ||
|
||
Well actually I will be rather busy so I give you the definition of a paradoxical combinator and I let you search one. | ||
|
||
First show that for any combinator A there is a combinator B such that AB = B. B is called a fixed point of A. (like the center of a wheel C is a fixed point of the rotations of the wheel: RC = C). It is a bit amazing that all combinators have a fixed point and that is what I propose you try to show. Here are hints for different arguments. 1) Show how to find a fixed point of A (Arbitrary combinator) using just B, M and A. (Mx = xx I recall). 2) The same using just the Lark L (Lxy = x(yy) I recall). Now, a paradoxical combinator Y is just a combinator which applied on that A will give the fixed point of A; that is YA will give a B such that AB = B, that is A(YA) gives YA, or more generally Y is a combinator satisfying Yx = x(Yx). | ||
|
||
** Problem: fixed point of A | ||
|
||
Show that for any combinator A there is a combinator B such that AB = B | ||
|
||
*** Solution | ||
|
||
Ax = x, x=? | ||
|
||
Fixpoint of S: | ||
|
||
SX = X. That is, X is such that for all y, | ||
SXy = Xy, that is, for all z | ||
SXyz = Xyz | ||
|
||
let X = MX' | ||
|
||
S(X'X')yz = X'X'yz | ||
(X'X')z(yz) (1) = X'X'yz (2) | ||
|
||
let X' = SX'', then | ||
|
||
(2) = SX''(SX'')yz = X''z(SX''yz) = X''z((X''z)(yz)) | ||
= B(X''z)(X''z)(yz) | ||
|
||
(1) = SX''(SX'')z(yz) = X''z(SX''z)(yz) = B(X''z)(SX'')z(yz) | ||
|
||
Xz(yz) = Xyz | ||
B(Xz)yz = Xyz | ||
|
||
B(Xz)y = Xy. let y = X, then | ||
B(Xz)X = XX = MX | ||
BBXzX = XX = MX | ||
|
||
|
||
|
||
X'X'yz = S(MX')yz = BSMX'yz | ||
X' = BSM | ||
X = M(BSM) | ||
|
||
** Check: | ||
|
||
M(BSM)yz = BSM(BSM)yz = S(M(BSM))yz | ||
|
||
Fixpoint of I: | ||
|
||
Ix = x | ||
|
||
any combinator is a fixpoint of I | ||
|
||
Fixpoint of K | ||
|
||
Kx = x | ||
Kxy = xy = x, that is, x is such that for all y | ||
xy = x | ||
M(BKM)y = BKM(BKM)y = K(M(BKM))y = M(BKM) !!! | ||
|
||
fixpoint of K is M(BKM). indeed, | ||
|
||
K(M(BKM))y = M(BKM); while M(BKM)y = M(BKM) | ||
|
||
|
||
Search X as M(X') | ||
|
||
KXy = Xy = X | ||
|
||
Xy = M(X')y = X'X'y = M(X') | ||
X'X'y = KXy = K(MX')y = BKMX'y | ||
X' = BKM // is that legal? | ||
X = M(BKM) | ||
|
||
|
||
** Fixpoint of B | ||
|
||
BX = X | ||
|
||
BXyz = Xyz | ||
|
||
X = M(BBM) | ||
|
||
Xyz = M(BBM)yz = BBM(BBM)yz = B(M(BBM))yz = BXyz | ||
|
||
X = M(BBM) = BBM(BBM) = B(M(BBM)) = BX | ||
|
||
** Fixpoint of M | ||
|
||
X = M(BMM) | ||
|
||
Xy = M(BMM)y = BMM(BMM)y = M(M(BMM))y | ||
|
||
** Fixpoint of A | ||
|
||
X = M(BAM) = BAM(BAM) = A(M(BAM)) = AX | ||
|
||
* Y | ||
|
||
YA = M(BAM) | ||
|
||
fixpoint of Y is M(BYM), that is, YM(BYM) = Y | ||
BYM(BYM) = BY | ||
M(BYM) = BY | ||
M(BYM)M = BYM | ||
YYM = BYM | ||
|
||
Yx = M(BxM) | ||
|
||
M(BxM) = BM(Bx)M = B(BM)BxM = B(BM)Bx(KMx) = S(B(BM)B)(KM)x | ||
|
||
Y = S(B(BM)B)(KM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
Well, you should be able to solve an exercise like finding a | ||
combinator A such that its dynamics is described by Axyz = | ||
y(yx)zz. Some other day we will make this precise by giving an | ||
algorithm for solving such problem (which solutions exist in all | ||
"sufficiently rich forest like the SK or BWCK forest). With the fixed | ||
point combinators you should be able to solve "recursive equations" | ||
like: find a A such that its dynamics is described recursively by Axyz | ||
= xxA(Ayy)z. How? Just find a B such that Baxyz = xxa(ayy)z (A has | ||
been replaced by a variable a). This is a traditional (non recursive) | ||
exercise. Then YB gives the solution of the recursive equation. (Y is | ||
the traditional name for a paradoxical combinator). Exercise: why? | ||
|
||
** Solution | ||
|
||
B(YB) = YB | ||
B(YB)xyz = xx(YB)(YByy)z = YBxyz | ||
let YB = A, then | ||
Axyz = xxA(Ayy)z | ||
|
||
* exercises | ||
|
||
Find an infinite eliminator E, that is a bird which eliminates all its | ||
variables: Ex = E, Exy = E, etc. | ||
|
||
Find an perpetual permutator, that is a bird which forever permutes | ||
its two inputs: its dynamics is as follow: Pxy =: Pyx =: Pxy =: Pyx | ||
etc. (I recall "=:" is the reduction symbol of the dynamics; it is the | ||
left to right reading of the "dynamics"). | ||
|
||
Etc. I mean: solve the following equations (little letters like x, y z | ||
are put for any combinator, A is put for the precise combinator we are | ||
ask searching for): | ||
|
||
Ax = A | ||
|
||
** solution | ||
|
||
Let's find B such that | ||
|
||
Bax = a | ||
B = K | ||
A = YB = YK = SLLK | ||
|
||
* Ax = xA | ||
|
||
Bax = xa | ||
B = T = B(SI)K | ||
A = YB = YT = SLLT | ||
|
||
* Axy = Ayx | ||
|
||
Baxy = ayx | ||
B = C | ||
A = YB = YC | ||
|
||
* Ax = AAx | ||
|
||
Bax = aax | ||
|
||
aax = (aa)x = Max, so B = M, A = YB = YM | ||
|
||
* A = AA | ||
|
||
Ba = aa | ||
|
||
B = M => A = YM | ||
|
||
* Ax = AA | ||
|
||
Xax = aa | ||
|
||
aa = Ma = K(Ma)x = BKMax | ||
X = BKM | ||
A = YX = YBKM | ||
|
||
* Ax = x(Ax) | ||
|
||
Bax = x(ax) | ||
x(ax) = Ix(ax) = SIax | ||
B = SI => A = YB = YSI |