aboutsummaryrefslogtreecommitdiff
path: root/entries/pkoronkevich/tex/fib.tex
diff options
context:
space:
mode:
authorJames Yoo2022-10-24 23:47:51 +0000
committerJames Yoo2022-10-24 23:47:51 +0000
commit03315f012514bdcc5a4f654056f0103abe11eb83 (patch)
tree2b7c6e9233ecb503e7be0d8354483691f9a1e16c /entries/pkoronkevich/tex/fib.tex
parent0921d8222bb883ea86d51c7200a865a5e4dbc469 (diff)
parent7ed13a92711a35a9c263c1f53e33e308653ae727 (diff)
Merging local with remote main
Diffstat (limited to 'entries/pkoronkevich/tex/fib.tex')
-rw-r--r--entries/pkoronkevich/tex/fib.tex29
1 files changed, 29 insertions, 0 deletions
diff --git a/entries/pkoronkevich/tex/fib.tex b/entries/pkoronkevich/tex/fib.tex
new file mode 100644
index 0000000..cef9138
--- /dev/null
+++ b/entries/pkoronkevich/tex/fib.tex
@@ -0,0 +1,29 @@
+\documentclass[11pt]{article}
+\usepackage[fleqn]{amsmath}
+
+\newcommand{\one}{\lambda f . \lambda x . f \ x}
+\newcommand{\two}{\lambda f . \lambda x . f \ (f \ x)}
+\newcommand{\tru}{\lambda x . \lambda y . x}
+\newcommand{\flse}{\lambda x . \lambda y . y}
+\newcommand{\isz}{\lambda n . n \ (\lambda c . \flse) \ \tru}
+\newcommand{\ife}{\lambda p . \lambda a . \lambda b . p \ a \ b}
+\newcommand{\suc}{\lambda n . \lambda f . \lambda x . f \ (n \ f \ x)}
+\newcommand{\plus}{\lambda m . \lambda n . m \ (\suc) \ n}
+\newcommand{\pred}{\lambda n . \lambda f . \lambda x . n \ (\lambda g . \lambda h . h \ (g \ f)) \ (\lambda u . x) \ (\lambda u . u)}
+\newcommand{\sub}{\lambda m . \lambda n . n \ (\pred) \ m}
+\newcommand{\lleq}{\lambda m . \lambda n . \\ \qquad \isz \ ((\sub) \\ \qquad \ m \ n)}
+\newcommand{\fix}{\lambda g . (\lambda x . g \ (x \ x)) \ (\lambda x . g \ (x \ x))}
+\newcommand{\appo}[2]{#1 \ #2}
+\newcommand{\appt}[3]{#1 \ #2 \ #3}
+
+\begin{document}
+\begin{gather*}
+ \fix \\ % recursive function application
+ \quad \lambda r . \lambda n . (\ife) \\ % of fib, which takes itself and n, if expression
+ \quad \ \appt{(\lleq)}{n}{\one} \\ % if n less than or equal to one
+ \quad \ (\one) \\ % if so, return 1
+ \quad \ (\plus) \\ % if not, add
+ \qquad \appo{r}{(\appo{(\pred)}{n})} \\ % the first recursive call, n - 1, to
+ \qquad \appo{r}{(\appt{(\sub)}{n}{\two})} % the second recursive call, n - 2
+\end{gather*}
+\end{document}