From 46e8b0c5e914c0283a08b0f08aa3cc7c381f47b8 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 28 Jan 2025 13:07:16 -0800 Subject: add kiwix; yasnippet macros; a couple new entries; update website --- mindmap/recursion.org | 77 ++------------------------------------------------- 1 file changed, 2 insertions(+), 75 deletions(-) (limited to 'mindmap/recursion.org') diff --git a/mindmap/recursion.org b/mindmap/recursion.org index 80fb92d..6dc3942 100644 --- a/mindmap/recursion.org +++ b/mindmap/recursion.org @@ -49,81 +49,8 @@ by trying to replace unknown variables by trying to evaluate $f(x)$ one number d 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 Describe Recursion -In stem, a factorial implementation might look like this: -#+begin_src stem :exports both -factorial [ dup 0 <= [ 1 + ] [ dup 1 - factorial * ] if ] def -5 factorial . -#+end_src - -#+RESULTS: -: 120 -and in stem, we can print out the [[id:52d255d2-114c-42f4-b362-f0b4a2f7b83d][stack]] every step of the way with the builtin word ~?~: -#+begin_src stem :exports both -factorial-debug [ dup 0 <= [ 1 + ] [ ? "\n" . dup 1 - factorial-debug ? "\n" . * ] if ] def -5 factorial-debug . -#+end_src - -#+RESULTS: -#+begin_example -5 - -5 -4 - -5 -4 -3 - -5 -4 -3 -2 - -5 -4 -3 -2 -1 - -5 -4 -3 -2 -1 -1 - -5 -4 -3 -2 -1 - -5 -4 -3 -2 - -5 -4 -6 - -5 -24 - -120 -#+end_example -as you can see, the stack is slowly built up to have all of the numbers needed, and then when we reach the basecase (the base case being the condition -that doesn't cause recursion in the if statement), in which case we "go back up" by multiplying and going back up the stack. This procedure of using a stack -is present in all programming languages, although in stem the operations are transparent as the stack is accessible by regular program users. In short, we keep -on going down and down until we hit the bottom, base case, in which case we have all the pieces we need in order to go back up again, where the stack stores -the information from most recent tasks to be done and we work back up in order to do the less recent tasks. - -This concept is important in programming because it allows one to build definitions in an intuitive way, simply by -specifying the base case and specifying the case that is not the base case. Such an algorithm absolves oneself from having -to design complicated patterns, as instead the entire computation emerges out of simple rules. - -In general, we see recursive definitions and design patterns in nature in the form of fractals. +* Programming Describes Recursion +In emacs-lisp, a factorial implementation may look like the following: * Self Reference Problems A big part of [[id:654280d8-82e8-4a0e-a914-bd32181c101b][infinite]] [[id:8f265f93-e5fd-4150-a845-a60ab7063164][recursion]] has to do with self reference problems. For instance, Russel's paradox with respect to set theory: does a set that contains all sets that do not contain themselves contain itself? -- cgit