Final lambda edits

This commit is contained in:
Mark 2023-10-16 18:54:37 -07:00
parent 22535a8183
commit 59498a9bc6
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
5 changed files with 115 additions and 23 deletions

View File

@ -2,12 +2,11 @@
% use [solutions] flag to show solutions. % use [solutions] flag to show solutions.
\documentclass[ \documentclass[
solutions, solutions,
singlenumbering, singlenumbering
shortwarning
]{../../resources/ormc_handout} ]{../../resources/ormc_handout}
\usepackage{url}
\usepackage{mathtools} % for \coloneqq \usepackage{mathtools} % for \coloneqq
\usepackage{hyperref}
% An invisible marker, used to % An invisible marker, used to
% draw arrows in equations. % draw arrows in equations.
@ -37,7 +36,7 @@
\uptitlel{Advanced 2} \uptitlel{Advanced 2}
\uptitler{Fall 2022} \uptitler{Fall 2023}
\title{Lambda Calculus} \title{Lambda Calculus}
\subtitle{Prepared by Mark on \today{}} \subtitle{Prepared by Mark on \today{}}

View File

@ -114,7 +114,13 @@ Reduce the following expressions:
\generic{Currying:} \generic{Currying:}
In lambda calculus, functions are only allowed to take one argument. In lambda calculus, functions are only allowed to take one argument.
However, we can emulate multivariable functions through \textit{currying}. However, we can emulate multivariable functions through \textit{currying}\footnotemark{}\hspace{-1ex}.
\footnotetext{After Haskell Brooks Curry\footnotemark{}\hspace{-1ex}, a logician that contributed to the theory of functional computation.}
\footnotetext{
There are three programming languages named after him: Haskell, Brook, and Curry. \par
Two of these are functional, and one is an oddball GPU language last released in 2007.
}
\vspace{1ex} \vspace{1ex}

View File

@ -1,6 +1,7 @@
\section{Boolean Algebra} \section{Boolean Algebra}
The Kestrel selects its first argument, and the Kite selects its second. This \say{choosing} behavior is similar to something you may have already seen... The Kestrel selects its first argument, and the Kite selects its second. \par
Maybe we can somehow put this \say{choosing} behavior to work...
\vspace{1ex} \vspace{1ex}
@ -18,6 +19,14 @@ Write a function $\text{NOT}$ so that $(\text{NOT} ~ T) = F$ and $(\text{NOT}~F)
\vfill \vfill
\problem{}
How would \say{if} statements work in this model of boolean logic? \par
Say we have a boolean $B$ and two expressions $E_T$ and $E_F$.
Can we write a function that evaluates to $E_T$ if $B$ is true, and to $E_F$ otherwise?
\vfill
\pagebreak
\problem{} \problem{}
Write functions $\text{AND}$, $\text{OR}$, and $\text{XOR}$ that satisfy the following table. Write functions $\text{AND}$, $\text{OR}$, and $\text{XOR}$ that satisfy the following table.
@ -62,5 +71,7 @@ What inputs should it take? What outputs should it produce?
$\text{EQ} = \lm ab . [\text{NOT}~(\text{XOR}~a~b)]$ $\text{EQ} = \lm ab . [\text{NOT}~(\text{XOR}~a~b)]$
\end{solution} \end{solution}
\vfill \vfill
\pagebreak \pagebreak

View File

@ -1,4 +1,77 @@
\section{Recursion} \section{Recursion}
%\iftrue
\iffalse
You now have a choice. Choose wisely --- there's no going back.
\begin{tcolorbox}[
breakable,
colback=white,
colframe=gray,
arc=0pt, outer arc=0pt
]
\raggedright
\textbf{Take the red pill:} You stay on this page and try to solve \ref{thechallenge}. \par
This will take a while, and it's very unlikely you'll finish before class ends.
\vspace{4mm}
I strongly prefer this option. It's not easy, but you'll be very happy if you solve it yourself.
This is a chance to build your own solution to a fundamental problem in this field, just as
Curry, Church, and Turing did when first developing the theory of lambda calculus.
- Mark
\end{tcolorbox}
\begin{tcolorbox}[
breakable,
colback=white,
colframe=gray,
arc=0pt, outer arc=0pt
]
\textbf{Take the blue pill:} You skip this problem and turn the page.
Half of the answer to \ref{thechallenge} will be free, and the rest will be
broken into smaller steps. This is how we usually learn out about interesting
mathematics, both in high school and in university.
\vspace{2mm}
This path isn't as rewarding as the one above, but it is well-paved
and easier to traverse.
\end{tcolorbox}
\problem{}<thechallenge>
Can you find a way to recursively call functions in lambda calculus? \par
Find a way to define a recursive factorial function. \par
\note{$A = (\lm a. A~a)$ doesn't count. You can't use a macro inside itself.}
\vfill
\pagebreak
\fi
Say we want a function that computes the factorial of a positive integer. Here's one way we could define it: Say we want a function that computes the factorial of a positive integer. Here's one way we could define it:
$$ $$
@ -30,7 +103,7 @@ They're just shorthand that simplifies notation.
\problem{} \problem{}
Write an expression that resolves to itself. \par Write an expression that resolves to itself. \par
\note{Your answer should be quite short.} \hint{Your answer should be quite short.}
\vspace{1ex} \vspace{1ex}
@ -45,12 +118,13 @@ $\Omega$ useless on its own, but it gives us a starting point for recursion. \pa
An uninspired mathematician might call the Mockingbird $\omega$, \say{little omega}. An uninspired mathematician might call the Mockingbird $\omega$, \say{little omega}.
\end{solution} \end{solution}
\vfill \vfill
\pagebreak \pagebreak
\definition{} \definition{}
This is the \textit{Y-combinator}. You may notice that it's just $\Omega$ put to work. This is the \textit{Y-combinator}. You may notice that it's just $\Omega$ put to work.
$$ $$
@ -62,26 +136,27 @@ What does this thing do? \par
Evaluate $Y f$. Evaluate $Y f$.
\vfill
\definition{} %\vfill
We say $x$ is a \textit{fixed point} of a function $f$ if $f(x) = x$.
\problem{} %\definition{}
Show that $Y F$ is a fixed point of $F$. %We say $x$ is a \textit{fixed point} of a function $f$ if $f(x) = x$.
\vfill %\problem{}
%Show that $Y F$ is a fixed point of $F$.
\problem{} %\vfill
Let $\theta = (\lm xy . y(xxy))$ and $\Theta = \theta \theta$. \par
Let $N = \Theta F$ for an arbitrary lambda expression $F$. \par
Show that $F N = N$. %\problem{}
%Let $b = (\lm xy . y(xxy))$ and $B = b ~ b$. \par
%Let $N = B F$ for an arbitrary lambda expression $F$. \par
\vfill %Show that $F N = N$.
\problem{Bonus} %\vfill
Find a fixed-point combinator that isn't $Y$ or $\Theta$.
%\problem{Bonus}
%Find a fixed-point combinator that isn't $Y$ or $\Theta$.
\vfill \vfill
\pagebreak \pagebreak

View File

@ -39,7 +39,8 @@ Design a non-recursive factorial function. \par
\problem{} \problem{}
Solve \ref{decrement} without using $H$. Solve \ref{decrement} without using $H$. \par
In \ref{decrement}, we created the \say{decrement} function.
\begin{solution} \begin{solution}
One solution is below. Can you figure out how it works? \par One solution is below. Can you figure out how it works? \par
@ -118,7 +119,7 @@ Write a lambda expression that evaluates to $T$ if a number $n$ is prime, and to
\vfill \vfill
\problem{} \problem{}
Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$. Write a function MOD so that $(\text{MOD}~a~b)$ reduces to the remainder of $a \div b$.
\vfill \vfill