Lambda edits

This commit is contained in:
2023-10-16 15:06:51 -07:00
parent 790cd77e87
commit b093e368e5
6 changed files with 121 additions and 81 deletions

View File

@ -5,34 +5,19 @@ Do \ref{Yfac} first, then finish the rest in any order.
\problem{}<Yfac>
Design a recursive factorial function using $Y$.
\begin{solution}
$\text{FAC} = \lm yn.[Z~n][1][\text{MULT}~n~(y~(\text{D}~n))]$
To compute the factorial of 5, evaluate $(\text{Y}~\text{FAC}~5)$.
\end{solution}
\vfill
\problem{}
Design a non-recursive factorial function. \par
\note{This one is easier than \ref{Yfac}, but I don't think it will help you solve it.}
\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.
$\text{GET}~L~0$ should give the first item in the list, and $\text{GET}~L~1$, the \textit{second}. \par
Lists have a defined length, so you should be able to tell when you're on the last element.
\problem{}
Solve \ref{decrement} without using $H$.
\problem{}
Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
\begin{solution}
\textbf{Factorial with recursion:}
\vspace{3ex}
$\text{FAC} = \lm yn.[Z~n][1][\text{MULT}~n~(y~(\text{D}~n))]$
\linehack{}
\textbf{Factorial without recursion:}
\vspace{3ex}
$\text{FAC}_0 = \lm p .
\Bigl\langle~~
\Bigl[D~(p~t)\Bigr]
@ -47,12 +32,55 @@ Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
\text{FAC} = \lm n .
\bigl( n~\text{FAC}_0~\langle n, 1 \rangle \bigr)
$
\end{solution}
\linehack{}
\vfill
\textbf{Lists:}
\vspace{3ex}
\problem{}
Solve \ref{decrement} without using $H$.
\begin{solution}
One solution is below. Can you figure out how it works? \par
\vspace{1ex}
$
D_0 =
\lm p . \Bigl[p~T\Bigr]
\Bigl\langle
F ~,~ p~F
\Bigr\rangle
\Bigl\langle
F
~,~
\bigl\langle
p~F~T ~,~ ( (p~F~T)~(P~F~F) )
\bigr\rangle
\Bigr\rangle
$
\vspace{1ex}
$
D = \lm nfa .
\Bigl(
n D_0 \Bigl\langle T, \langle f, a \rangle \Bigr\rangle
\Bigr)~F~F
$
\end{solution}
\vfill
\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.
$\text{GET}~L~0$ should give the first item in the list, and $\text{GET}~L~1$, the \textit{second}. \par
Lists have a defined length, so you should be able to tell when you're on the last element.
\begin{solution}
One possible implementation is
$\Bigl\langle
\langle \text{is last} ~,~ \text{item} \rangle
@ -75,8 +103,27 @@ Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
This will break if $n$ is out of range.
\end{solution}
\vfill
\pagebreak
\problem{}
Write a lambda expression that represents the Fibonacci function: \par
$f(0) = 1$, $f(1) = 1$, $f(n + 2) = f(n + 1) + f(n)$.
\vfill
\problem{}
Write a lambda expression that evaluates to $T$ if a number $n$ is prime, and to $F$ otherwise.
\vfill
\problem{}
Write a MOD $a$ $b$ function that reduces to the remainder of $a \div b$.
\vfill
\problem{Bonus}
Play with \textit{Lamb}, an automatic lambda expression evaluator. \par
\url{https://git.betalupi.com/Mark/lamb}
\url{https://git.betalupi.com/Mark/lamb}
\pagebreak