#+author: Preston Pan
#+date: <2023-06-11 Sun>
#+description: My website for all things.
-#+options: num:nil broken-links:t tex:dvipng
#+html_head: <link rel="stylesheet" type="text/css" href="style.css" />
* What is this?
--- /dev/null
+#+TITLE: My Blog
+#+AUTHOR: Preston Pan
+#+DATE: <2023-06-14 Wed>
+#+DESCRIPTION: List of all my blogs in alphabetical order
+#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+language: en
+#+OPTIONS: broken-links:t
+
+* Why?
+I want a place where I can write long form essays about subjects
+without being constrained by any particular form, like in the mindmap.
+** Why not the Journal, then?
+This blog is not going to be for my personal life in any capacity,
+technical or otherwise. Think about the blog like a mix between
+the wiki format of the mindmap and the journal format.
+
+* Blog Articles
+#+begin_src shell :results output raw :exports both
+for f in *;
+do
+ if [[ "$f" == "index.org" ]]; then
+ continue
+ fi
+ printf -- "- [[file:$f][$f]]\n"
+done
+#+end_src
+
+#+RESULTS:
#+description: My doom emacs configuration
#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
-* Configuration
+* config.el Configuration
+This is a doom emacs configuration. If you are not using doom emacs, do not use this document.
** Basic Information
My name, and the org mode directory on my computer, as well as basic editor configuration options.
Below is the old documentation.
"Custom function to create journal header."
(concat
(pcase org-journal-file-type
- (`daily "#+TITLE: Daily Journal\n#+STARTUP: showeverything\n#+DESCRIPTION: My daily journal entry\n#+AUTHOR: Preston Pan\n#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n#+html_head: <script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n#+html_head: <script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>")
+ (`daily "#+TITLE: Daily Journal\n#+STARTUP: showeverything\n#+DESCRIPTION: My daily journal entry\n#+AUTHOR: Preston Pan\n#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n#+html_head: <script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n#+html_head: <script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>\n#+options: broken-links:t")
(`weekly "#+TITLE: Weekly Journal\n#+STARTUP: folded")
(`monthly "#+TITLE: Monthly Journal\n#+STARTUP: folded")
(`yearly "#+TITLE: Yearly Journal\n#+STARTUP: folded"))))
(setq org-roam-directory (file-truename "~/org/website/mindmap"))
(setq org-roam-capture-templates '(("d" "default" plain "%?"
:target (file+head "${title}.org"
- "#+title: ${title}\n#+author: Preston Pan\n#+html_head: <link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n#+html_head: <script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n#+html_head: <script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>")
+ "#+title: ${title}\n#+author: Preston Pan\n#+html_head: <link rel=\"stylesheet\" type=\"text/css\" href=\"../style.css\" />\n#+html_head: <script src=\"https://polyfill.io/v3/polyfill.min.js?features=es6\"></script>\n#+html_head: <script id=\"MathJax-script\" async src=\"https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js\"></script>\n#+options: broken-links:t")
:unnarrowed t)))
#+end_src
*** Publishing
:init (setq epa-pinentry-mode `loopback)
(pinentry-start))
#+end_src
+* packages.el Configuration
+These are some external packages that I use that are not provided by doom modules.
+#+begin_src emacs-lisp :tangle packages.el
+(package! pinentry)
+(package! kbd-mode
+ :recipe (:host github
+ :repo "kmonad/kbd-mode"))
+(package! nasm-mode)
+#+end_src
+
+* init.el Configuration
+This installs all the doom modules that we are going to be configuring:
+#+begin_src emacs-lisp :tangle init.el
+(doom! :input
+ ;;bidi ; (tfel ot) thgir etirw uoy gnipleh
+ chinese
+ japanese
+ ;;layout ; auie,ctsrnm is the superior home row
+
+ :completion
+ company
+ ;;helm ; the *other* search engine for love and life
+ ;;ido ; the other *other* search engine...
+ (ivy +icons +fuzzy)
+ vertico
+
+ :ui
+ ;;deft ; notational velocity for Emacs
+ doom
+ doom-dashboard
+ doom-quit
+ (emoji +unicode)
+ hl-todo
+ hydra
+ indent-guides
+ (ligatures +extra +fira)
+ minimap
+ modeline
+ ;;nav-flash ; blink cursor line after big motions
+ ;;neotree ; a project drawer, like NERDTree for vim
+ ophints
+ (popup +defaults)
+ tabs
+ treemacs
+ unicode
+ (vc-gutter +pretty)
+ vi-tilde-fringe
+ window-select
+ workspaces
+ zen
+
+ :editor
+ (evil +everywhere)
+ file-templates
+ fold
+ (format +onsave)
+ ;;god ; run Emacs commands without modifier keys
+ lispy
+ ;;multiple-cursors ; editing in many places at once
+ ;;objed ; text object editing for the innocent
+ parinfer
+ ;;rotate-text ; cycle region at point between text candidates
+ snippets
+ word-wrap
+
+ :emacs
+ dired
+ electric
+ (ibuffer +icons)
+ undo
+ vc
+
+ :term
+ ;;eshell ; the elisp shell that works everywhere
+ ;;shell ; simple shell REPL for Emacs
+ ;; term ; basic terminal emulator for Emacs
+ vterm
+
+ :checkers
+ syntax
+ (spell +flyspell)
+ grammar
+
+ :tools
+ ;;ansible
+ ;;biblio ; Writes a PhD for you (citation needed)
+ (debugger +lsp)
+ ;;direnv
+ ;;docker
+ editorconfig
+ ein
+ (eval +overlay)
+ gist
+ lookup
+ lsp
+ magit
+ make
+ pass
+ pdf
+ ;;prodigy ; FIXME managing external services & code builders
+ rgb
+ ;;taskrunner ; taskrunner for all your projects
+ ;;terraform ; infrastructure as code
+ tmux
+ tree-sitter
+ ;;upload ; map local to remote projects via ssh/ftp
+
+ :os
+ (:if IS-MAC macos)
+ tty
+
+ :lang
+ ;;agda ; types of types of types of types...
+ ;;beancount ; mind the GAAP
+ (cc +lsp)
+ ;;clojure ; java with a lisp
+ common-lisp
+ ;;coq ; proofs-as-programs
+ ;;crystal ; ruby at the speed of c
+ ;;csharp ; unity, .NET, and mono shenanigans
+ data
+ ;;(dart +flutter) ; paint ui and not much else
+ ;;dhall
+ ;;elixir ; erlang done right
+ ;;elm ; care for a cup of TEA?
+ emacs-lisp
+ ;;erlang ; an elegant language for a more civilized age
+ ess
+ ;;factor
+ ;;faust ; dsp, but you get to keep your soul
+ ;;fortran ; in FORTRAN, GOD is REAL (unless declared INTEGER)
+ ;;fsharp ; ML stands for Microsoft's Language
+ ;;fstar ; (dependent) types and (monadic) effects and Z3
+ ;;gdscript ; the language you waited for
+ (go +lsp)
+ ;;(graphql +lsp) ; Give queries a REST
+ ;;(haskell +lsp) ; a language that's lazier than I am
+ ;;hy ; readability of scheme w/ speed of python
+ ;;idris ; a language you can depend on
+ (json +lsp)
+ ;;(java +lsp) ; the poster child for carpal tunnel syndrome
+ (javascript +lsp)
+ ;;julia ; a better, faster MATLAB
+ ;;kotlin ; a better, slicker Java(Script)
+ (latex +lsp +fold +cdlatex)
+ ;;lean ; for folks with too much to prove
+ ;;ledger ; be audit you can be
+ ;;lua ; one-based indices? one-based indices
+ (markdown +grip)
+ ;;nim ; python + lisp at the speed of c
+ nix
+ ;;ocaml ; an objective camel
+ (org +journal +jupyter +gnuplot +brain +pretty +roam2)
+ ;;php ; perl's insecure younger brother
+ ;;plantuml ; diagrams for confusing people more
+ ;;purescript ; javascript, but functional
+ (python +lsp +tree-sitter)
+ ;;qt ; the 'cutest' gui framework ever
+ ;;racket ; a DSL for DSLs
+ ;;raku ; the artist formerly known as perl6
+ ;;rest ; Emacs as a REST client
+ ;;rst ; ReST in peace
+ ;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
+ (rust +lsp)
+ ;;scala ; java, but good
+ (scheme +guile)
+ (sh +fish +lsp)
+ ;;sml
+ ;;solidity ; do you need a blockchain? No.
+ ;;swift ; who asked for emoji variables?
+ ;;terra ; Earth and Moon in alignment for performance.
+ (web +lsp)
+ (yaml +lsp)
+ ;;zig ; C, but simpler
+
+ :email
+ (mu4e +org)
+ ;;notmuch
+ ;;(wanderlust +gmail)
+
+ :app
+ calendar
+ emms
+ everywhere ; *leave* Emacs!? You must be joking
+ irc ; how neckbeards socialize
+ (rss +org) ; emacs as an RSS reader
+ ;;twitter ; twitter client https://twitter.com/vnought
+
+ :config
+ literate
+ (default +bindings +smartparens))
+#+end_src
#+begin_src shell :results output raw :exports both
for f in *;
do
- if [[ "$f" == "index.org" ]]; then
+ if [[ "$f" == "index.org" || "$f" == "README.org" ]]; then
continue
fi
printf -- "- [[file:$f][$f]]\n"
Key([mod], "f", lazy.spawn("firefox"), desc="Run Firefox"),
Key([mod], "b", lazy.spawn("blender"), desc="Run Blender"),
Key([mod], "p", lazy.spawn("krita"), desc="Run Krita"),
+ Key([mod], "g", lazy.spawn("gimp"), desc="Run GIMP"),
Key([mod], "t", lazy.spawn("torbrowser-launcher"), desc="Run Tor Browser"),
Key([mod], "i", lazy.spawn("emacsclient --eval \"(emacs-everywhere)\""), desc="Emacs Everywhere!"),
])
Key([], 'XF86AudioNext', lazy.spawn("mpc next")),
Key([], 'XF86AudioPrev', lazy.spawn("mpc prev")),
Key([], "XF86AudioPlay", lazy.spawn("mpc toggle"), desc="Play/Pause player"),
+ Key([], "Print", lazy.spawn("scrot '%Y-%m-%d-%s_screenshot_$wx$h.jpg' -e 'mv $f ~/img/scrot")),
])
#+end_src
** Groups
]
#+end_src
** Bar
+Now we define our bar. I only have the need to see the time, current workspace, battery percentage,
+and MPD. Also, you may need to manually change your font size depending on your screen.
#+begin_src python :tangle config.py
widget_defaults = dict(
font="FiraCode Nerd Font",
If you're interested, you can read my [[file:journal/index.org][journal]]. Note that this journal is not my
entire personal life but instead will be a focus on interesting things that I
think of or things that are of a technical nature.
+** [[file:blog/index.org][Blog]]
+My blog contains many longer writings that do not fit into the mindmap format.
+Work in progress; the journal, mindmap, and configs are my biggest focus right now.
** [[file:mindmap/index.org][Mindmap]]
I also have a mindmap, for those of you who are interested in knowing everything.
*** What is a mindmap?
I will also make a github repository for this website, probably,
which means I'm going to make a README.org.
+** 21:20
+I made the repository and everything. Now, all I need to do is finish
+a couple of mindmap articles so that it becomes a cohesive experience.
+The website also still needs a favicon and I might want to add some
+of my music to it.
--- /dev/null
+#+TITLE: Daily Journal
+#+STARTUP: showeverything
+#+DESCRIPTION: My daily journal entry
+#+AUTHOR: Preston Pan
+#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+html_head: <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
+#+html_head: <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
+#+options: broken-links:t
+* Tuesday, 13 June 2023
+** 19:34
+I am leaving for china today. I tried using guix with my arch linux
+system but it was too unstable and I almost broke my system, so I
+of course stopped. I may try nix in the future, but for now, I will
+try to just keep my current setup where it is.
+** 20:35
+Just realized that I need to publish things for the website; also, I
+may want to have a blog where I write non-mindmap related articles.
+I need to get git working with signing with my gpg key as well.
--- /dev/null
+#+TITLE: Daily Journal
+#+STARTUP: showeverything
+#+DESCRIPTION: My daily journal entry
+#+AUTHOR: Preston Pan
+#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+html_head: <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
+#+html_head: <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
+#+options: broken-links:t
+* Wednesday, 14 June 2023
+** 09:40
+Currently, I am on an airplane to Taipei, and I will be at Beijing
+shortly. I'm excited to purchase a mechancal keyboard and maybe
+some other peripherals there. It will probably be cheaper than
+buying them in Canada.
+
+I've slept a little bit, but my sleep quality was poor. However,
+I still don't feel that bad.
+
+Working in my little space in emacs is pretty nice, even on an airplane.
+Like I said, I bought ivpn for a month so i should be able to view the
+internet from outside the firewall. I haven't set up nix yet, but I think
+I will do it in China.
+
+Another thing is that I have been looking at my analytical mechanics book,
+and it is easy compared to when I tried learning it before. Probably because I
+have more experience with multidimensional integrals, fields, and whatnot.
+I plan to do more of it in China.
+
+What's funny is that my literacy 12 exam has to be done in China because they
+don't allow you to do it early. What a pain.
#+begin_src shell :results output raw :exports both
for f in $(ls | sort -r);
do
- if [[ "$f" == "index.org" ]]; then
+ if [[ "$f" == "index.org" || "$f" == "README.org" ]]; then
continue
fi
printf -- "- [[file:$f][$f]]\n"
#+end_src
#+RESULTS:
+- [[file:20230614.org][20230614.org]]
+- [[file:20230613.org][20230613.org]]
- [[file:20230611.org][20230611.org]]
- [[file:20230610.org][20230610.org]]
- [[file:20230609.org][20230609.org]]
#+author: Preston Pan
#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
#+date: <2023-06-10 Sat>
-* One or Two?
-This is placeholder text.
+* is it One or is it Two?
+Is it me, or is it you? Is it false, or is it true? Many things
+can be explained by a bimodal or binary system. Everything, from
+boolean logic to art, any system whose goal is to make a prediction.
+
+** The Great Filter
+No, not the one about aliens dying or something. I'm talking about the
+everyday systems that you use in order to make predictions about the
+world. For example, this one, that wants to explain everything.
+
+*** The problem of explaining everything
+Because this is indeed a system that explains everything, I must also
+demonstrate why it might be impossible to explain everything. I'll
+give the argument in a short set of syllogisms.
- Don't use the back button on your browser
- Everything here is going to be a link to another mindmap page.
- Therefore, if there is a page you want to go back to, you must navigate until you find a loop back to the original page.
+** What Happens if I don't Follow the Rules?
+You're ruining your own fun I guess. These are just the recommended settings
+and if you want to change them then you're free to.
+
+That won't stop me from following you in real life, though. Teehee!
+* How did you make it?
+This section of the website was made with ~org-roam~, an emacs package that allows
+you to make a web of notes, something close to a wiki.
--- /dev/null
+:PROPERTIES:
+:ID: 16b06b82-99cc-4343-b171-fb2166c46a30
+:END:
+#+title: induction
+#+author: Preston Pan
+#+options: num:nil
+#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+options: tex:dvipng
+
+* Placeholder
--- /dev/null
+:PROPERTIES:
+:ID: 654280d8-82e8-4a0e-a914-bd32181c101b
+:END:
+#+title: infinity
+#+author: Preston Pan
+#+options: num:nil
+#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+options: tex:dvipng
+* placeholder text
--- /dev/null
+:PROPERTIES:
+:ID: a6bc601a-7910-44bb-afd5-dffa5bc869b1
+:END:
+#+title: mathematics
+#+author: Preston Pan
+#+html_head: <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
+#+html_head: <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
+#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
+
+* Mathematics is Logic
+With a couple of set theory axioms. One might
+describe it as an extrapolation framework
+without grounding (i.e. a set of implications;
+if p then q, but never specifying if p is a property
+of a real system or not).
--- /dev/null
+:PROPERTIES:
+:ID: 2d6fb5ac-a273-4b33-949c-37380d03c076
+:END:
+#+title: natural number
+#+author: Preston Pan
+#+html_head: <link rel="stylesheet" type="text/css" href="../style.css" />
+#+html_head: <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
+#+html_head: <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
+
+* What is a Natural Number?
+We can formulate the natural numbers from set construction, or by Peano arithmetic.
+I will start with the Peano arithmetic formulation. First, we define an immediate
+successor function $S:\mathbb{N}\rightarrow\mathbb{N}$ which effectively "adds one" (although we haven't defined addition yet),
+and a number we call $0 \in \mathbb{N}$. We then define an axiom:
+\begin{align*}
+\forall n \in \mathbb{N} \; \nexists S(n) \; s.t. S(n) = 0; \\
+\forall n \in \mathbb{N} \; S(n) \in \mathbb{N}.
+\end{align*}
+which is equivalent to saying: adding one to any natural number makes it not equal to zero, and
+any natural number's successor is a natural number. Because zero is a natural number, we can define
+$1 = S(0)$, and by definition $1 \in \mathbb{N}$. Note that it doesn't matter what we call $S(0)$; we just choose
+to name it one because we like working in the base 10 number system.
+
+In a few lines, we should also try to define equality:
+\begin{align*}
+\forall a \in \mathbb{N}, \; a = a; \\
+\forall a, b, c \in \mathbb{N}, \; (a = b) \land (b = c) \rightarrow a = c; \\
+\forall a, b \in \mathbb{N}, \; a = b \rightarrow b = a.
+\end{align*}
+which I already explained just sets up equality in the way we're used to.
+These axioms are probably slightly important for our purposes, and as you can imagine, they generalize past
+natural numbers. Then we define one more axiom:
+\begin{align*}
+\forall a, b \in \mathbb{N}, \; S(a) = S(b) \Leftrightarrow a = b.
+\end{align*}
+simply saying that if we add one to both sides of an equation the equality remains. And we're almost done!
+There is one problem: given our current axioms, we can definitely prove propositions like these:
+\begin{align*}
+S(S(0)) \neq S(0)
+\end{align*}
+however, they don't allow for the ability for us to extrapolate properties of natural numbers /in general/.
+** [[id:16b06b82-99cc-4343-b171-fb2166c46a30][Induction]]
+Let's introduce our last axiom:
+\begin{align*}
+\forall n \in \mathbb{N} \: \forall P(n) \; P(0) \land (P(n) \rightarrow P(S(n))) \rightarrow P(n) \; \forall n \in \mathbb{N}
+\end{align*}
+now, this is the principle of [[id:16b06b82-99cc-4343-b171-fb2166c46a30][induction]] specific to natural numbers. What it is saying is that a property
+$P(n)$ is true for all $n$ if there is a "base case" $P(0)$ which is true, and you can show that $P(1)$ is
+true from $P(0)$, $P(2)$ is true from $P(1)$ and so on to infinity, or more generally $P(S(n))$ is true for every $P(n)$.
+This "base case" essentially bootstraps you into proving it for infinite cases. There is also a general version
+of induction, but the only natural numbers case works for us now.
+*** And so on to [[id:654280d8-82e8-4a0e-a914-bd32181c101b][Infinity]]?
+Wait a second, so how are we defining "to infinity" here? How do we /know/ that $P(x)$ is going to work with every
+$n$ even though we haven't tried it for every single $n$? Well, the answer is we extrapolate. We do the first few loops
+and we assume the logic carries out to any arbitrarily large loop. It's less of defining things in terms of infinity
+and more like playing a game where one person dares the other to go $n$ times, where $n$ is any natural number. They
+can say, "calculate that $P(x)$ is true for $P(6)$!", and the claim is that you can /always/ do that, even if they say
+one million instead of six, or one billion instead of one million. No matter how high the number, you can repeat the process
+$n$ times and get the result that $P(n)$ is true.
+*** [[id:16b06b82-99cc-4343-b171-fb2166c46a30][Induction]] = [[id:8f265f93-e5fd-4150-a845-a60ab7063164][Recursion]]?
+Wait: isn't the idea of a "base case" kind of analogous to the idea of recursion? And comparing $P(S(n)) = P(n + 1)$
+to $P(n)$ kind of looks suspiciously like a recursive function, only, instead of using the base case in order
+to stop the program from running infinitely, we use the base case as a /starting point/ to "run the program to infinity".
+Some connections are beginning to be made…
+*** [[id:8f265f93-e5fd-4150-a845-a60ab7063164][Recursion]] ~ [[id:654280d8-82e8-4a0e-a914-bd32181c101b][Infinity]]?
+It seems one can describe many recursive structures as inherently relating to infinity. I posit that recursive structures
+have a starting point and an ending point -- in the case of the factorial, the starting point is a natural number that is
+an input to the function, and the ending point is when it reaches zero (because the factorial function "iterates down",
+meaning a number is continually subtracted until it reaches a lower bound, meaning what we call the base case has to be always
+lower than the input). It is also conceivable that you can have a recursively defined function that has a base case higher
+than any possible inputs and iterates upwards. In this case, calling zero the "base case" of induction is actually misleading.
+If you model induction as a function, induction /has no base case/, and the input is usually evaluated at zero. Meaning,
+*induction is a special case of recursion where no base case is defined*. Although, I'm not sure actual career mathematicians
+would like my wording of this issue.
+** Set Construction
+Given I've described Peano axioms already, I may as well use them. Although, Peano axioms may also be derived from ZFC set theory
+axioms.
+
+Set $S(x) = \{ x \}$ and $0 = \{\}$. Then set construction describes the process of constructing the natural numbers from the empty set
+by nesting sets together. For example, $1 = \{0\} = \{\{\}\}$, and $2 = \{1\} = \{\{0\}\} = \{\{\{\}\}\}$. Then all natural numbers can be constructed
+recursively expanding the variables.
+*** [[id:8f265f93-e5fd-4150-a845-a60ab7063164][Recursion!]]
+And now there is a clear demonstrated link between Peano axioms and recursive structures.
+** Addition
+Okay, that's all good, but natural numbers don't have a use case if even simple things like addition are not defined.
+Let's do that!
+** Congrats!
+We've just defined a natural number! Every single object that can be described in terms of these axioms is
+also an instance of a natural number.
as [[id:42dbae12-827c-43c4-8dfc-a2cb1e835efa][self-assembly]] and it has deep connections to topics such as [[id:b005fb71-2a16-40f9-9bb6-29138f4719a2][emergence]]. I will first
describe it in a mathematics context, and then a programming context.
For demonstration purposes, I will use [[id:5d2e2f3b-96ac-4196-9baf-4c3d6d349c98][python]].
-* Mathematics Describes Recursion
+* [[id:a6bc601a-7910-44bb-afd5-dffa5bc869b1][Mathematics]] Describes Recursion
For this example, I will be using the factorial. One might define it like so:
\begin{align*}
f: \mathbb{N}\rightarrow\mathbb{N}\ s.t. \\
f(0) = 1 \\
-f(n) = nf(n - 1) \\
+f(n) = nf(n - 1)
\end{align*}
-
+in other words, we want a function defined over [[id:2d6fb5ac-a273-4b33-949c-37380d03c076][natural numbers]] that is one when the input is zero,
+and otherwise multiplies the input with a copy of itself, only the input is one less. Let's try evaluating
+this function at $x = 3$.
+\begin{align*}
+f(3) = 3 * f(3 - 1) = 3 * f(2) \\
+f(2) = 2 * f(1) \\
+f(1) = 1 * f(0) \\
+f(0) = 1
+\end{align*}
+once we substitute $f(0) = 1$ in, you will see it all collapses.
+\begin{align*}
+f(0) = 1 \\
+f(1) = 1 * f(0) = 1 * 1 = 1 \\
+f(2) = 2 * f(1) = 2 * 1 = 2 \\
+f(3) = 3 * f(2) = 3 * 2 = 6
+\end{align*}
+and so the result is multiplying $3 * 2 * 1 * 1 = 6$. If you observe what we did, you'll see that we started
+by trying to replace unknown variables by trying to evaluate $f(x)$ one number down, and eventually we reach
+a "base case" -- zero. As soon as the "base case" occurs, we then "go back up" by replacing all the unknown
+values with known ones -- and that's how we evaluate recursive functions.
* Programming Describes Recursion
+Even if you don't understand programming, it should be clear that this represents the factorial function:
#+begin_src python :exports both
def factorial(x):
- if x <= 0:
+ if x < 0:
+ return None
+ elif x == 0:
return 1
return x * factorial(x - 1)
return factorial(5)
#+RESULTS:
: 120
+
+And it also prints the result that we expect for the factorial of 5. Take note that just like in our mathematics
+example, ~factorial~ calls itself until it reaches a base case, ~x == 0~.
** The stack frame
We are now going to modify the code to be more transparent in the sense that it is going to print
each factorial call out:
#+begin_src python :results output :exports both
def factorial(x):
- if x <= 0:
+ if x < 0:
+ return None
+ elif x == 0:
print(1)
return 1
n = x * factorial(x - 1)
: 24
: 120
-what is happening here? Why is it printing in the reverse order? Well, it is because we are calling
-the factorial function from within itself /before/ we print out the return value, which then
-keeps on happening for each iteration until it reaches the "base case" (the case in which x <= 0).
+what is happening here? Why is it printing in the reverse order? Well, it is the /exact same phenomenon/
+as the "going back up" procedure we did before!
+
+You can model this behavior with a [[id:52d255d2-114c-42f4-b362-f0b4a2f7b83d][stack]], which is why it is called a stack frame. What's interesting is that
+the "going down until you reach the bottom and then building back up" procedure we did to solve $f(3)$ in the
+math section is actually modeled well by a stack. Just look at the far right hand side of all our equations in
+that example: we try but fail to evaluate $f(2)$, then $f(1)$, then $f(0)$. Then, we succeed in evaluating
+$f(0)$, which leads to being able to evaluate $f(1)$, which leads to being able to evaluate $f(2)$. This reverse
+ordering is exactly what we see by pushing a list of items onto a stack then removing them from one. Additionally,
+the second equation block from that section's right hand side is identical to the first few entries we see in the
+results block of this one, and you can see an exact mirroring of the first block in its evaluations of $f(n)$.
+
+So, the "going down" procedure is the same thing as pushing values onto some sort of stack, and the "going back up"
+procedure is exactly the same as popping those values off a stack!
+** Computer Hardware Describes Recursion
+Even though we can analogize pushing and popping off the stack to this recursion, there still isn't a clear definite
+link to the two ideas in hardware. Therefore, I will do a demonstration using assembly.
+
+To start with, we will be comparing an assembly function that takes the factorial to this one in C:
+#+begin_src C :results output :exports both
+#include <stdio.h>
+
+int factorial(int x) {
+ if (x < 0) return -1;
+ else if (x == 0) return 1;
+ return x * factorial(x - 1);
+}
+int main(int argc, char **argv) {
+ printf("factorial of five: %d\n", factorial(5));
+ return 0;
+}
+#+end_src
+
+#+RESULTS:
+: factorial of five: 120
+
+Because C is a compiled language, it is easier to see what is actually happening human-wise. However,
+we will need to write and analyze some assembly in order to figure out what is actually going on.
+
+Assembly language section coming soon! We will be using NASM due to its readability.
+* TODO Recursion Describes…?
-You can model this behavior with a [[id:52d255d2-114c-42f4-b362-f0b4a2f7b83d][stack]], which is why it is called a stack frame. Think about each
-iteration as getting put on the top of the stack waiting to be printed, until the base case is evaluated
-and printed all in one step.
-* Recursion is not Recursion
-* Recursion is [[id:1b1a8cff-1d20-4689-8466-ea88411007d7][duality]]?
+* TODO Recursion is not Recursive
+There are some things
+* TODO Recursion = [[id:1b1a8cff-1d20-4689-8466-ea88411007d7][duality]]?
}
pre,
code {
- font-family: 'Inconsolata', sans-serif;
+ font-family: 'Inconsolata', monospace;
}
h1,
h2,
padding-top: 12px;
font-size: 12px;
}
+
+.example {
+ color: #fdf6e3;
+}
+.src {
+ color: #fdf6e3;
+}
+++ /dev/null
-#!/usr/bin/env sh
-
-cp ~/.config/doom/config.org config/doom.org
-cp ~/.config/fish/config.org config/fish.org
-cp ~/org/elfeed.org config/elfeed.org
-cp ~/.config/qtile/config.org config/qtile.org
-cp ~/.config/qutebrowser/config.org config/qutebrowser.org
-cp ~/.config/kmonad/config.org config/kmonad.org