Лямбда-исчисление

реклама
Ìîñêîâñêèé ôèçèêî-òåõíè÷åñêèé èíñòèòóò
Ôàêóëüòåò èííîâàöèé è âûñîêèõ òåõíîëîãèé
Ìàòåìàòè÷åñêàÿ ëîãèêà, âåñíà 2012
Ëÿìáäà-èñ÷èñëåíèå
Ïðèâåäèòå ïðèìåð λ-òåðìà, ê êîòîðîìó ìîæíî ïðèìåíèòü β -ðåäóêöèþ òîëüêî
ïîñëå íåêîòîðîãî ÷èñëà α-êîíâåðñèé. (Ïðè íåïîñðåäñòâåííîì ïðèìåíåíèè β -ðåäóêöèè
äîëæåí ïîëó÷àòüñÿ íåêîððåêòíûé ðåçóëüòàò).
2. Ïðèâåäèòå ê íîðìàëüíîé ôîðìå λ-òåðì ((λa.(λb.ba)c)b)((λc.(cb))(λa.a)).
3. Ïðèâåäèòå ïðèìåð çàìêíóòîãî λ-òåðìà (êîìáèíàòîðà), íå èìåþùåãî íîðìàëüíîé
ôîðìû.
4. Ïðèâåäèòå ïðèìåð çàìêíóòîãî λ-òåðìà, êîòîðûé ïðèâîäèòñÿ ê íîðìàëüíîé ôîðìå
ïðè îäíîì ïîðÿäêå β -ðåäóêöèé, íî íå ïðèâîäèòñÿ ïðè äðóãîì ïîðÿäêå.
5. Îáîçíà÷èì Θ êîìáèíàòîð (λxy.y(xxy))(λxy.y(xxy)). Äîêàæèòå, ÷òî äëÿ ëþáîãî
êîìáèíàòîðà F âûïîëíåíî ðàâåíñòâî ΘF = F (ΘF ) (ò.î., êîìáèíàòîð (ΘF ) ÿâëÿåòñÿ
íåïîäâèæíîé òî÷êîé äëÿ F ).
6. Äîêàæèòå, ÷òî êîìáèíàòîð λf.(λx.f (xx))(λx.f (xx)) òîæå ÿâëÿåòñÿ êîìáèíàòîðîì
íåïîäâèæíîé òî÷êè.
7. Îáîçíà÷èì ÷åðåç L êîìáèíàòîð
1.
λabcdef ghijklmnopqstuvwxyzr.r(thisisaf ixedpointcombinator)
Äîêàæèòå, ÷òî êîìáèíàòîð LLLLLLLLLLLLLLLLLLLLLLLLLL (ïðîèçâåäåíèå 26 êîïèé L) ÿâëÿåòñÿ êîìáèíàòîðîì íåïîäâèæíîé òî÷êè. Óêàçàíèå: Îáðàòèòå âíèìàíèå íà
ïåðåìåííóþ r.
Íóìåðàëàìè ×¼ð÷à äëÿ íàòóðàëüíûõ ÷èñåë 0, 1, 2, 3, . . . íàçûâàþòñÿ êîìáèíàòîðû
0 = λf x.x, 1 = λf x.f x, 2 = λf x.f (f x), 3 = λf x.f (f (f x)), . . .
8.
9.
ò.å.
Ïðèâåäèòå ê íîðìàëüíîé ôîðìå êîìáèíàòîðû (2 3) è (3 2).
Íàéäèòå êîìáèíàòîð F , ÿâëÿþùèéñÿ íåïîäâèæíîé òî÷êîé êàæäîãî íóìåðàëà n,
nF = F
äëÿ âñåõ íàòóðàëüíûõ n.
10. Ïîñòðîéòå λ-òåðì F , äëÿ êîòîðîãî âûïîëíåíî ðàâåíñòâî
F = xF
(ãäå x ïåðåìåííàÿ). Ïðèâîäèòñÿ ëè äàííûé òåðì F ê íîðìàëüíîé ôîðìå?
Ãîâîðÿò, ÷òî êîìáèíàòîð A ïðåäñòàâëÿåò ôóíêöèþ f : Nk → N, åñëè äëÿ ëþáûõ ÷èñåë
n1 , . . . , nk êîìáèíàòîð (An1 n2 . . . nk ) ðàâåí íóìåðàëó ×¼ð÷à äëÿ ÷èñëà f (n1 , . . . , nk ),
åñëè f (n1 , . . . , nk ) îïðåäåëåíî, è íå èìååò íîðìàëüíîé ôîðìû â ïðîòèâíîì ñëó÷àå.
Ïîñòðîéòå êîìáèíàòîðû, êîòîðûå ïðåäñòàâëÿþò ñëåäóþùèå ôóíêöèè íàòóðàëüíûõ ÷èñåë:
11.
1
a)
b)
c)
d)
e)
f)
g)
h)
n 7→ n + 1;
(n, m) 7→ n + m;
(n, m) 7→ n · m;
(n, m) 7→ nm (×åìó ïîëó÷èëîñü ðàâíî 00 ?);
n 7→ (n + 3)2 ;
(n, m)√7→ max{n, m};
n 7→ b√nc;
n 7→ d n e.
12.
Ïðèâåäèòå ê íîðìàëüíîé ôîðìå λ-òåðìû:
a) (λxy.x(xxy))((λxy.x(xxy))(λxy.x(xy))),
b) (λxy.x(xy))((λxy.x(xxxy))(λxy.x(xy))),
c) (λxy.x(xy))(λxy.x(xxxy))(λxy.x(xy)).
Ïîñòðîéòå êîìáèíàòîð äëèíû íå áîëåå 40, ÷èñëî ñèìâîëîâ â íîðìàëüíîé ôîðìå
êîòîðîãî ïðåâûøàåò ÷èñëî ýëåêòðîíîâ â âèäèìîé ÷àñòè Âñåëåííîé.
14. Ïîñòðîéòå êîìáèíàòîðû, êîòîðûå ïðåäñòàâëÿþò ñëåäóþùèå ôóíêöèè íàòóðàëüíûõ ÷èñåë:
n − 1, åñëè n ≥ 1,
a) n 7→
0,
åñëè n = 0,
b) (n, m) 7→ max{n − m, 0}.
13.
15.
÷òî
Îáîçíà÷àåì False = λxy.y è True = λxy.x. Ïîñòðîéòå êîìáèíàòîð IsZero òàêîé,
True, åñëè n = 0,
IsZero(n) =
False, èíà÷å.
Ïîñòðîéòå êîìáèíàòîðû, êîòîðûå ïðåäñòàâëÿþò ñëåäóþùèå ôóíêöèè íàòóðàëüíûõ ÷èñåë:
16.
a)
b)
c)
d)
n 7→ n! (ôàêòîðèàë ÷èñëà),
n 7→ dlog ne,
îñòàòîê îò äåëåíèÿ n íà m,
íåïîëíîå ÷àñòíîå îò äåëåíèÿ n íà m.
Ïðÿìûì âû÷èñëåíèåì ïðèâåäèòå ê íîðìàëüíîé ôîðìå Fac 2 è Fac 3, ãäå Fac êîìáèíàòîð, ïðåäñòàâëÿþùèé ôóíêöèþ n!
18. Ïîñòðîéòå êîìáèíàòîðû, êîòîðûå ïî íóìåðàëó ×¼ð÷à äëÿ ÷èñëà n âû÷èñëÿþò
íóìåðàë ×¼ð÷à äëÿ ÷èñëà ϕn , ãäå

0,
åñëè n = 0,

1,
åñëè n = 1, (÷èñëà Ôèáîíà÷÷è)
a) ϕn =

ϕ
+
ϕ
,
åñëè n > 1;
n−2
 n−1
0,
åñëè n = 0,

1,
åñëè n = 1, (÷èñëà Ôèáîíà÷÷è ïî ìîäóëþ 3)
b) ϕn =

ϕn−1 + ϕn−2 mod 3, åñëè n ≥ 2;
17.
2
c) ϕn =
d) ϕn =






19.
1
åñëè n = 0,
0
åñëè n = 1,
2ϕn−1 + ϕn−2 åñëè n > 1;
2
åñëè n = 0,
3
åñëè n = 1,
ϕn−1 · ϕn−2 åñëè n > 1.
Ïîñòðîéòå êîìáèíàòîð, ïðåäñòàâëÿþùèé â λ-èñ÷èñëåíèè ôóíêöèþ ÷¼òíîñòè:
True, åñëè n ÷¼òíî,
Even(n) =
False, åñëè n íå÷¼òíî.
Ïîñòðîéòå êîìáèíàòîðû GT, LE, EQ òàêèå, ÷òî
True, åñëè n > m,
a) GT n m =
False, èíà÷å;
True, åñëè n ≤ m,
b) LE n m =
False,
èíà÷å;
True, åñëè n = m,
c) EQ n m =
False, èíà÷å.
20.
Ïîñòðîéòå êîìáèíàòîð choose, êîòîðûé ïðåäñòàâëÿåò ôóíêöèþ äâóõ àðãóìåíòîâ
(÷èñëî ñî÷åòàíèé èç n ïî k ), îïðåäåë¼ííóþ äëÿ n ≥ k . Íå çàáóäüòå ïðîâåðèòü, ÷òî
ïðè n < k òåðì (choose n k) íå èìååò íîðìàëüíîé ôîðìû.
22. Ïîñòðîéòå êîìáèíàòîð Prime òàêîé, ÷òî
True, åñëè ÷èñëî n ïðîñòîå,
Prime n =
False, èíà÷å
21.
Cnk
(ïðîâåðêà ÷èñëà íà ïðîñòîòó).
23. Ïîñòðîéòå êîìáèíàòîð NthPrime, êîòîðûé ïî íóìåðàëó ×¼ð÷à n íàõîäèò n-îå
ïðîñòîå ÷èñëî. (Äëÿ îïðåäåë¼ííîñòè ïîòðåáóåì, ÷òîáû NthPrime 0 = 1.)
24. Íàéäèòå êàêóþ-íèáóäü íåïîäâèæíóþ òî÷êó êîìáèíàòîðà ïðèáàâëåíèÿ åäèíèöû
Inc. Åñòü ëè ó íå¼ íîðìàëüíàÿ ôîðìà?
25.  ñòðåëî÷íîé íîòàöèè Êíóòà äëÿ ïîëîæèòåëüíûõ öåëûõ ÷èñåë a, b èñïîëüçóþòñÿ îáîçíà÷åíèÿ a ↑ b = ab (a â ñòåïåíè b), a ↑↑ b = a ↑ (a ↑ (. . . ↑ a) . . .),
{z
}
|
b ðàç
a ↑↑ . . . ↑ b = a ↑↑ . . . ↑(a ↑↑ . . . ↑(. . . ↑↑ . . . ↑ a) . . .);
| {z }
| {z } | {z }
| {z }
n
n−1
n−1
n−1
|
{z
}
a âñòðå÷àåòñÿ b ðàç
n-ûì ÷èñëîì Àêêåðìàíà íàçûâàþò Ackn = n ↑↑ . . . ↑ n. Âû÷èñëèòå ïåðâûå òðè ÷èñëà
| {z }
n
Àêêåðìàíà. Ïîñòðîéòå êîìáèíàòîð Ack, êîòîðûé ïðåîáðàçóåò íóìåðàë n (äëÿ n > 0) â
íóìåðàë, âûðàæàþùèé n-îå ÷èñëî Àêêåðìàíà.
3
Скачать