Minor cleanup
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
\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}
|
||||
|
||||
We'll start with zero. If our numbers are \textit{once,} \textit{twice,} and \textit{twice}, it may make sense to make zero \textit{don't}. \\
|
||||
We'll start with zero. If our numbers are \textit{once,} \textit{twice,} and \textit{twice}, it may make sense to make zero \textit{don't}. \par
|
||||
Here's our \textit{don't} function: given a function and an input, don't apply the function to the input.
|
||||
$$
|
||||
0 = \lm fa.a
|
||||
@ -18,13 +18,13 @@ Write $1$, $2$, and $3$. We will call these \textit{Church numerals}.\hspace{-0.
|
||||
\footnotetext{after Alonzo Church, the inventor of lambda calculus and these numerals. He was Alan Turing's thesis advisor.}
|
||||
|
||||
\begin{solution}
|
||||
$1$ calls a function once on its argument: \\
|
||||
$1$ calls a function once on its argument: \par
|
||||
$1 = \lm fa . (f~a)$.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
Naturally, \\
|
||||
$2 = \lm fa . [~f~(f~a)~]$ \\
|
||||
Naturally, \par
|
||||
$2 = \lm fa . [~f~(f~a)~]$ \par
|
||||
$3 = \lm fa . [~f~(f~(f~a))~]$
|
||||
|
||||
\vspace{1ex}
|
||||
@ -49,7 +49,7 @@ What is $(4~I)~\star$?
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
What is $(3~NOT~T)$? \\
|
||||
What is $(3~NOT~T)$? \par
|
||||
How about $(8~NOT~F)$?
|
||||
|
||||
\vfill
|
||||
@ -57,13 +57,13 @@ How about $(8~NOT~F)$?
|
||||
\pagebreak
|
||||
|
||||
\problem{}
|
||||
This handout may remind you of Professor Oleg's handout on Peano's axioms. Good. \\
|
||||
Recall the tools we used to build the natural numbers: \\
|
||||
This handout may remind you of Professor Oleg's handout on Peano's axioms. Good. \par
|
||||
Recall the tools we used to build the natural numbers: \par
|
||||
We had a zero element and a \say{successor} operation so that $1 \coloneqq S(0)$, $2 \coloneqq S(1)$, and so on.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
Create a successor operation for the Church numerals. \\
|
||||
Create a successor operation for the Church numerals. \par
|
||||
\hint{A good signature for this function is $\lm nfa$, or more clearly $\lm n.\lm fa$. Do you see why?}
|
||||
|
||||
\begin{solution}
|
||||
@ -83,14 +83,14 @@ Verify that $S(0) = 1$ and $S(1) = 2$.
|
||||
\pagebreak
|
||||
|
||||
|
||||
Assume that only Church numerals will be passed to the functions in the following problems. \\
|
||||
Assume that only Church numerals will be passed to the functions in the following problems. \par
|
||||
We make no promises about their output if they're given anything else.
|
||||
|
||||
\problem{}
|
||||
Define a function ADD that adds two Church numerals.
|
||||
|
||||
\begin{solution}
|
||||
$\text{ADD} = \lm mn . (m~S~n) = \lm mn . (n~S~m)$ \\
|
||||
$\text{ADD} = \lm mn . (m~S~n) = \lm mn . (n~S~m)$
|
||||
\end{solution}
|
||||
|
||||
\begin{instructornote}
|
||||
@ -111,8 +111,8 @@ Define a function ADD that adds two Church numerals.
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Adding is nice, but we can do better. \\
|
||||
Design a function MULT that multiplies two numbers. \\
|
||||
Adding is nice, but we can do better. \par
|
||||
Design a function MULT that multiplies two numbers. \par
|
||||
\hint{The easy solution uses ADD, the elegant one doesn't. Find both!}
|
||||
|
||||
\begin{solution}
|
||||
@ -126,22 +126,22 @@ Design a function MULT that multiplies two numbers. \\
|
||||
|
||||
|
||||
\problem{}
|
||||
Define the functions $Z$ and $NZ$. $Z$ should reduce to $T$ if its input was zero, and $F$ if it wasn't. \\
|
||||
Define the functions $Z$ and $NZ$. $Z$ should reduce to $T$ if its input was zero, and $F$ if it wasn't. \par
|
||||
$NZ$ does the opposite. $Z$ and $NZ$ should look fairly similar.
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
\begin{solution}
|
||||
$Z\phantom{N} = \lm n .[n~(\lm a.F)~T]$\\
|
||||
$Z\phantom{N} = \lm n .[n~(\lm a.F)~T]$ \par
|
||||
$NZ = \lm n .[n~(\lm a.T)~F]$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Data structures will be useful. Design an expression PAIR that constructs two-value tuples. \\
|
||||
For example, say $A = \text{PAIR}~1~2$. Then, \\
|
||||
$(A~T)$ should reduce to $1$ \\
|
||||
Data structures will be useful. Design an expression PAIR that constructs two-value tuples. \par
|
||||
For example, say $A = \text{PAIR}~1~2$. Then, \par
|
||||
$(A~T)$ should reduce to $1$ \par
|
||||
$(A~F)$ should reduce to $2$
|
||||
|
||||
\begin{solution}
|
||||
@ -149,21 +149,21 @@ $(A~F)$ should reduce to $2$
|
||||
\end{solution}
|
||||
|
||||
\vfill
|
||||
From now on, I'll write (PAIR $A$ $B$) as $\langle A,B \rangle$. \\
|
||||
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.
|
||||
|
||||
\pagebreak
|
||||
|
||||
\problem{}<shiftadd>
|
||||
Write a function $H$, which we'll call \say{shift and add.} \\
|
||||
It does exactly what it says on the tin: \\
|
||||
Write a function $H$, which we'll call \say{shift and add.} \par
|
||||
It does exactly what it says on the tin:
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
Given an input pair, it should shift its right argument left, then add one. \\
|
||||
$H~\langle 0, 1 \rangle$ should reduce to $\langle 1, 2\rangle$ \\
|
||||
$H~\langle 1, 2 \rangle$ should reduce to $\langle 2, 3\rangle$ \\
|
||||
$H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$ \\
|
||||
Given an input pair, it should shift its right argument left, then add one. \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 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$
|
||||
|
||||
\begin{solution}
|
||||
$H = \lm p . \Bigl\langle~(p~F)~,~S(p~F)~\Bigr\rangle$
|
||||
@ -177,8 +177,8 @@ $H~\langle 10, 4 \rangle$ should reduce to $\langle 4, 5\rangle$ \\
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Design a function $D$ that un-does $S$. That means \\
|
||||
$D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \\
|
||||
Design a function $D$ that un-does $S$. That means \par
|
||||
$D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \par
|
||||
\hint{$H$ will help you make an elegant solution.}
|
||||
|
||||
\begin{solution}
|
||||
@ -186,8 +186,8 @@ $D(1) = 0$, $D(2) = 1$, etc. $D(0)$ should be zero. \\
|
||||
\end{solution}
|
||||
|
||||
\begin{solution}
|
||||
Here's a different solution. \\
|
||||
Can you figure out how it works? \\
|
||||
Here's a different solution. \par
|
||||
Can you figure out how it works?
|
||||
|
||||
\vspace{1ex}
|
||||
|
||||
|
Reference in New Issue
Block a user