This commit is contained in:
Mark 2023-10-05 11:23:03 -07:00
parent 18a6856380
commit dfadd23e63
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
5 changed files with 23 additions and 32 deletions

View File

@ -29,7 +29,7 @@ $$
Functions are left-associative: If $A$ and $B$ are functions, $(A~B~\star)$ is equivalent to $((A~B)~\star)$. Functions are left-associative: If $A$ and $B$ are functions, $(A~B~\star)$ is equivalent to $((A~B)~\star)$.
As usual, we'll use parentheses to group terms if we want to override this order: $(A~(B~\star)) \neq (A~B~\star)$ \par As usual, we'll use parentheses to group terms if we want to override this order: $(A~(B~\star)) \neq (A~B~\star)$ \par
In this handout, all types of parentheses ( $(), [],$ etc ) are equivalent. In this handout, all types of parentheses ( $(), [~],$ etc ) are equivalent.
\vfill \vfill

View File

@ -38,20 +38,20 @@ Write functions $\text{AND}$, $\text{OR}$, and $\text{XOR}$ that satisfy the fol
\end{center} \end{center}
\begin{solution} \begin{solution}
There's more than one way to do this, of course, but make sure the kids understand how the solutions below work. There's more than one way to do this, of course.
\begin{align*} \begin{align*}
\text{AND} &= \lm ab . (a~b~F) = \lm ab . aba \\ \text{AND} &= \lm ab . (a~b~F) = \lm ab . aba \\
\text{OR} &= \lm ab . (a~T~b) = \lm ab . aab \\ \text{OR} &= \lm ab . (a~T~b) = \lm ab . aab \\
\text{XOR} &= \lm ab . (a~ (\text{NOT}~b) ~b) \text{XOR} &= \lm ab . (a~ (\text{NOT}~b) ~b)
\end{align*} \end{align*}
It may be worth mentioning that OR $= \lm ab.(M~a~b)$ is also a solution. Another clever solution is $\text{OR} = \lm ab.(M~a~b)$
\end{solution} \end{solution}
\vfill \vfill
\problem{} \problem{}
To complete our boolean algebra, write the boolean equality check EQ. \par To complete our boolean algebra, construct the boolean equality check EQ. \par
What inputs should it take? What outputs should it produce? What inputs should it take? What outputs should it produce?
\begin{solution} \begin{solution}

View File

@ -1,6 +1,6 @@
\section{Numbers} \section{Numbers}
Since the only objects we have in $\lm$-calculus are functions, it's natural to think of quantities as \textit{adverbs} (once, twice, thrice,...) rather than \textit{nouns} (one, two, three ...) Since the only objects we have in $\lm$ calculus are functions, it's natural to think of quantities as \textit{adverbs} (once, twice, thrice,...) rather than \textit{nouns} (one, two, three ...)
\vspace{1ex} \vspace{1ex}
@ -9,7 +9,7 @@ Here's our \textit{don't} function: given a function and an input, don't apply t
$$ $$
0 = \lm fa.a 0 = \lm fa.a
$$ $$
If you look closely, you'll find that $0$ is $\alpha$-equivalent to the false function $F$. If you look closely, you'll find that $0$ is equivalent to the false function $F$.
\problem{} \problem{}
Write $1$, $2$, and $3$. We will call these \textit{Church numerals}.\hspace{-0.5ex}\footnotemark{} \\ Write $1$, $2$, and $3$. We will call these \textit{Church numerals}.\hspace{-0.5ex}\footnotemark{} \\
@ -29,16 +29,8 @@ Write $1$, $2$, and $3$. We will call these \textit{Church numerals}.\hspace{-0.
\vspace{1ex} \vspace{1ex}
The round parentheses are \textit{essential}. Our lambda calculus is left-associative! The round parentheses are \textit{essential}. Our lambda calculus is left-associative! \par
Also, note that zero is false and one is the (two-variable) identity.
\vspace{2ex}
Also, notice that $1$ is very similar to $I$:
$$
I~\heartsuit~\star = 1~\heartsuit~\star
$$
Zero is false, and one is the identity. Isn't that wonderful?
\end{solution} \end{solution}
\vfill \vfill
@ -111,7 +103,6 @@ Define a function ADD that adds two Church numerals.
\vfill \vfill
\problem{} \problem{}
Adding is nice, but we can do better. \par
Design a function MULT that multiplies two numbers. \par Design a function MULT that multiplies two numbers. \par
\hint{The easy solution uses ADD, the elegant one doesn't. Find both!} \hint{The easy solution uses ADD, the elegant one doesn't. Find both!}
@ -139,10 +130,9 @@ $NZ$ does the opposite. $Z$ and $NZ$ should look fairly similar.
\vfill \vfill
\problem{} \problem{}
Data structures will be useful. Design an expression PAIR that constructs two-value tuples. \par Design an expression PAIR that constructs two-value tuples. \par
For example, say $A = \text{PAIR}~1~2$. Then, \par For example, say $A = \text{PAIR}~1~2$. Then, \par
$(A~T)$ should reduce to $1$ \par $(A~T)$ should reduce to $1$ and $(A~F)$ should reduce to $2$.
$(A~F)$ should reduce to $2$
\begin{solution} \begin{solution}
$\text{PAIR} = \lm ab . \lm i . (i~a~b) = \lm abi.iab$ $\text{PAIR} = \lm ab . \lm i . (i~a~b) = \lm abi.iab$
@ -150,7 +140,7 @@ $(A~F)$ should reduce to $2$
\vfill \vfill
From now on, I'll write (PAIR $A$ $B$) as $\langle A,B \rangle$. \par From now on, I'll write (PAIR $A$ $B$) as $\langle A,B \rangle$. \par
Like currying, this is only notation. The underlying $\lm$ logic remains the same. Like currying, this is only notation. The underlying logic remains the same.
\pagebreak \pagebreak
@ -160,7 +150,7 @@ It does exactly what it says on the tin:
\vspace{1ex} \vspace{1ex}
Given an input pair, it should shift its right argument left, then add one. \par Given an input pair, it should shift its second argument left, then add one. \par
$H~\langle 0, 1 \rangle$ should reduce to $\langle 1, 2\rangle$ \par $H~\langle 0, 1 \rangle$ should reduce to $\langle 1, 2\rangle$ \par
$H~\langle 1, 2 \rangle$ should reduce to $\langle 2, 3\rangle$ \par $H~\langle 1, 2 \rangle$ should reduce to $\langle 2, 3\rangle$ \par
$H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$ $H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$
@ -176,7 +166,7 @@ $H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$
\vfill \vfill
\problem{} \problem{}<decrement>
Design a function $D$ that un-does $S$. That means \par Design a function $D$ that un-does $S$. That means \par
$D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \par $D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \par
\hint{$H$ will help you make an elegant solution.} \hint{$H$ will help you make an elegant solution.}

View File

@ -8,12 +8,13 @@ $$
\end{cases} \end{cases}
$$ $$
We cannot re-create this in lambda notation. Functions in lambda calculus are \textit{anonymous}, which means we can't call them before they've been fully defined. We cannot re-create this in lambda calculus, since we aren't given a way to recursively call functions.
\vspace{1ex} \vspace{2mm}
As an example, consider the statement $A = \lm a. A~a$ \par One could think that $A = \lm a. A~a$ is a recursive function. In fact, it is not. \par
This means \say{write $(\lm a.A~a)$ whenever you see $A$.} However, $A$ is \textit{inside} what we're rewriting. We'd fall into infinite recursion before even starting our $\beta$-reduction! Remember that such \say{definitions} aren't formal structures in lambda calculus. \par
They're just shorthand that simplifies notation.
\begin{instructornote} \begin{instructornote}
We're talking about recursion, and \textit{computability} isn't far away. At one point or another, it may be good to give the class a precise definition of \say{computable by lambda calculus:} We're talking about recursion, and \textit{computability} isn't far away. At one point or another, it may be good to give the class a precise definition of \say{computable by lambda calculus:}
@ -29,12 +30,12 @@ This means \say{write $(\lm a.A~a)$ whenever you see $A$.} However, $A$ is \text
\problem{} \problem{}
Write an expression that resolves to itself. \par Write an expression that resolves to itself. \par
\note{Your answer should be short and sweet.} \note{Your answer should be quite short.}
\vspace{1ex} \vspace{1ex}
This expression is often called $\Omega$, after the last letter of the Greek alphabet. \par This expression is often called $\Omega$, after the last letter of the Greek alphabet. \par
$\Omega$ useless on its own, but gives us a starting point for recursion. $\Omega$ useless on its own, but it gives us a starting point for recursion.
\begin{solution} \begin{solution}
$\Omega = M~M = (\lm x . xx) (\lm x . xx)$ $\Omega = M~M = (\lm x . xx) (\lm x . xx)$

View File

@ -9,7 +9,7 @@ Design a recursive factorial function using $Y$.
\problem{} \problem{}
Design a non-recursive factorial function. \par Design a non-recursive factorial function. \par
\note{This one is a lot easier than \ref{Yfac}, but I don't think it will help you solve it.} \note{This one is easier than \ref{Yfac}, but I don't think it will help you solve it.}
\problem{} \problem{}
Using pairs, make a \say{list} data structure. Define a GET function, so that $\text{GET}~L~n$ reduces to the nth item in the list. Using pairs, make a \say{list} data structure. Define a GET function, so that $\text{GET}~L~n$ reduces to the nth item in the list.
@ -17,7 +17,7 @@ $\text{GET}~L~0$ should give the first item in the list, and $\text{GET}~L~1$, t
Lists have a defined length, so you should be able to tell when you're on the last element. Lists have a defined length, so you should be able to tell when you're on the last element.
\problem{} \problem{}
Write POW $a$ $b$, which raises $b$ to the $a$th power. Solve \ref{decrement} without using $H$.
\problem{} \problem{}
Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$. Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
@ -66,7 +66,7 @@ Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
\say{item} is the thing you're storing \par \say{item} is the thing you're storing \par
\say{next...} is another one of these list fragments. \say{next...} is another one of these list fragments.
It doesn't matter what \say{next} is in the last list fragment. A dedicated \say{is last} slot allows us to store ANY function in this list. It doesn't matter what \say{next} is in the last list fragment. A dedicated \say{is last} slot allows us to store arbitrary functions in this list.
\vspace{1ex} \vspace{1ex}