From f8de1e15a8ccef1fda059a6618c87e5e97e250e7 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Fri, 27 Sep 2024 21:02:33 -0600 Subject: [PATCH] Macros and the recursion theorem. --- .../plugins/obsidian-to-anki-plugin/data.json | 21 ++- notes/_journal/2024-09-27.md | 12 ++ notes/_journal/{ => 2024-09}/2024-09-26.md | 2 +- notes/c17/index.md | 16 +- notes/c17/macros.md | 159 ++++++++++++++++++ .../proof-system/natural-deduction.md | 4 +- notes/hashing/addressing.md | 2 +- notes/posix/signals.md | 9 + notes/set/natural-numbers.md | 119 ++++++++++++- 9 files changed, 323 insertions(+), 21 deletions(-) create mode 100644 notes/_journal/2024-09-27.md rename notes/_journal/{ => 2024-09}/2024-09-26.md (87%) create mode 100644 notes/c17/macros.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index f4f3fca..e45481d 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -204,7 +204,9 @@ "graph-induced-subgraph.png", "graph-subgraph.png", "graph-non-subgraph.png", - "bfs.gif" + "bfs.gif", + "closed-addressing.png", + "open-addressing.png" ], "File Hashes": { "algorithms/index.md": "3ac071354e55242919cc574eb43de6f8", @@ -230,7 +232,7 @@ "nix/callPackage.md": "9aeeaa22878434d3c4498cb92cfe230b", "nix/index.md": "4efc7fcc4ea22834ba595497e5fb715c", "posix/index.md": "97b1b8ecb9a953e855a9acf0ab25b8c8", - "posix/signals.md": "f4132369878c683bfac4d7fd863d19ba", + "posix/signals.md": "8cdb56708b187389b5bd4d75e762ec76", "templates/daily.md": "7866014e730e85683155207a02e367d8", "posix/regexp.md": "d7d1b8cde49c405d44c7e1d9343769c0", "journal/2024-02-04.md": "e2b5678fc53d7284b71ed6820c02b954", @@ -317,7 +319,7 @@ "_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd", "_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b", "c17/strings.md": "2da50edd26eae35c81f70e65bbd12d49", - "c17/index.md": "b039549b80bde34fab31b61b5e28e9d4", + "c17/index.md": "02722edf46dd45f732996eaa1980944f", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", "c17/declarations.md": "2d7877915bf8a2772d1e4de636ba52a5", "algorithms/sorting/merge-sort.md": "6506483f7df6507cee0407bd205dbedd", @@ -444,7 +446,7 @@ "_journal/2024-04-16.md": "0bf6e2f2a3afab73d528cee88c4c1a92", "_journal/2024-04/2024-04-15.md": "256253b0633d878ca58060162beb7587", "algebra/polynomials.md": "da56d2d6934acfa2c6b7b2c73c87b2c7", - "algebra/sequences/delta-constant.md": "d9af958375cdf993e4ac3c68c1324ba7", + "algebra/sequences/delta-constant.md": "5c8b3e48d054d332a54b85a439e135b8", "_journal/2024-04-19.md": "a293087860a7f378507a96df0b09dd2b", "_journal/2024-04/2024-04-18.md": "f6e5bee68dbef90a21ca92a846930a88", "_journal/2024-04/2024-04-17.md": "331423470ea83fc990c1ee1d5bd3b3f1", @@ -658,7 +660,7 @@ "_journal/2024-07-13.md": "13b5101306b5542b8a1381a6477378ca", "_journal/2024-07/2024-07-12.md": "8073584fae2fe7bffcd4b69a7cd29058", "hashing/static.md": "3ec6eaee73fb9b599700f5a56b300b83", - "hashing/addressing.md": "01b33abe25aae285e1641fa43470065b", + "hashing/addressing.md": "c068221b70d2e37b8978951e1b91acd9", "ontology/index.md": "0994403dcd84415f1459752129b55f65", "ontology/permissivism.md": "643e815a79bc5c050cde9f996aa44ef5", "ontology/properties.md": "91ece501551c444afcd119d7197958ef", @@ -694,7 +696,7 @@ "formal-system/abstract-rewriting.md": "8424314a627851c5b94be6163f64ba30", "_journal/2024-07-22.md": "d2ca7ce0bbeef76395fee33c9bf36e9d", "_journal/2024-07/2024-07-21.md": "62c2651999371dd9ab10d964dac3d0f8", - "formal-system/proof-system/natural-deduction.md": "88cf72e12f3135312c715497493d21ff", + "formal-system/proof-system/natural-deduction.md": "f105a27843518778cb6662652a9d7aed", "startups/term-sheet.md": "6b6152af78addb3fe818a7fc9d375fbf", "startups/financing-rounds.md": "00a622fda2b4b442901bde2842309088", "_journal/2024-07-23.md": "35e18a1d9a8dd0a97e1d9898bc1d8f01", @@ -773,7 +775,7 @@ "_journal/2024-08/2024-08-21.md": "1637b8ec8475cf3eb4f41d1d86cbf5df", "_journal/2024-08/2024-08-20.md": "e8bec308d1b29e411c6799ace7ef6571", "_journal/2024-08-23.md": "3b2feab2cc927e267263cb1e9c173d50", - "set/natural-numbers.md": "a14465985e87b81ccbe3a5d27159654a", + "set/natural-numbers.md": "676bf8295cf8ea27dbcb2750de4ae197", "_journal/2024-08-24.md": "563fad24740e44734a87d7c3ec46cec4", "_journal/2024-08/2024-08-23.md": "7b5a40e83d8f07ff54cd9708017d029c", "_journal/2024-08/2024-08-22.md": "050235d5dc772b542773743b57ce3afe", @@ -839,7 +841,10 @@ "_journal/2024-09-25.md": "4527ac5c132aaf5adc6e624c5e4aca5e", "_journal/2024-09/2024-09-23.md": "d5589199e01c1794774b310e94d89374", "_journal/2024-09-26.md": "ce334b0576d6d7495150abd5c7e1ce61", - "_journal/2024-09/2024-09-25.md": "c8a3414e27c8ce635fe995c2dfbf6019" + "_journal/2024-09/2024-09-25.md": "c8a3414e27c8ce635fe995c2dfbf6019", + "c17/macros.md": "f7bade849d2cf714cd2ff79c4ed003d4", + "_journal/2024-09-27.md": "dd82b2c5c5389b6a35c4c2fcf857417c", + "_journal/2024-09/2024-09-26.md": "2d3e8325e7ab63168c460f18e7aa1afc" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-09-27.md b/notes/_journal/2024-09-27.md new file mode 100644 index 0000000..8a5aa10 --- /dev/null +++ b/notes/_journal/2024-09-27.md @@ -0,0 +1,12 @@ +--- +title: "2024-09-27" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Notes on [[macros]]. Read Gustedt's take on signed/unsigned integer binary representations. +* Initial notes of the [[natural-numbers#Recursion Theorem|recursion theorem]] (on $\omega$). \ No newline at end of file diff --git a/notes/_journal/2024-09-26.md b/notes/_journal/2024-09/2024-09-26.md similarity index 87% rename from notes/_journal/2024-09-26.md rename to notes/_journal/2024-09/2024-09-26.md index 4e890fa..bf7dbe4 100644 --- a/notes/_journal/2024-09-26.md +++ b/notes/_journal/2024-09/2024-09-26.md @@ -2,7 +2,7 @@ title: "2024-09-26" --- -- [ ] Anki Flashcards +- [x] Anki Flashcards - [x] KoL - [x] OGS - [ ] Sheet Music (10 min.) diff --git a/notes/c17/index.md b/notes/c17/index.md index d01996c..1e19afe 100644 --- a/notes/c17/index.md +++ b/notes/c17/index.md @@ -356,14 +356,6 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co END%% -%%ANKI -Basic -What is the binary representation of a value? -Back: N/A. Binary representations describe types not values. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - %%ANKI Basic What is the object representation of a type? @@ -394,6 +386,14 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co END%% +%%ANKI +Basic +Why might the same value have different binary representations? +Back: Because the binary representation corresponds to the type of the value. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + ## Bibliography * “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). diff --git a/notes/c17/macros.md b/notes/c17/macros.md new file mode 100644 index 0000000..f2854a2 --- /dev/null +++ b/notes/c17/macros.md @@ -0,0 +1,159 @@ +--- +title: Macros +TARGET DECK: Obsidian::STEM +FILE TAGS: c17::macro +tags: + - c17 +--- + +## Overview + +Macros refer to `#define` directives that specify terms that should be textually replaced by the preprocessor during compilation: + +```c +#define NAME ... +``` + +For types that don't have literals that describe their constants, we can use **compound literals** on the replacement side of the macro: + +```c +#define NAME (T){ INIT } +``` + +%%ANKI +Basic +What preprocessor directive is used to define macros? +Back: `#define` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How are compound literals specified in a macro definition, say `MACRO`? +Back: +```c +#define MACRO (T){ INIT } +``` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What term is used to refer to the replacement side of the following macro? +```c +#define MACRO (T){ INIT } +``` +Back: A compound literal. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is the difference between the following two lines? +```c +#define MACRO (T){ INIT } +# define MACRO (T){ INIT } +``` +Back: N/A. They are equivalent. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is the difference between the following two lines? +```c +#define MACRO (T){ INIT } +#define MACRO(T){ INIT } +``` +Back: The first defines a compound literal. The latter defines a function-like macro. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is `T` a reference to in the following compound literal? +```c +#define MACRO (T){ INIT } +``` +Back: A type-specifier. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is `INIT` a reference to in the following compound literal? +```c +#define MACRO (T){ INIT } +``` +Back: An initializer. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why aren't compound literals suitable for ICE? +Back: They are objects, not constants. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How can the following be rewritten so that `MACRO` is an object? +```c +#define MACRO 5 +``` +Back: +```c +#define MACRO (int){5} +``` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is the difference between the following two lines? +```c +#define MACRO 5 +#define MACRO (int){5} +``` +Back: The former is a literal whereas the latter is a compound literal. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why should compound literals be, generally speaking, `const`-qualified? +Back: Doing so gives the optimizer more room to generate good binary code. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How do we write macro definitions that span more than one line? +Back: Ending all but the last line with a `\` character. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Generally speaking, what character should *not* be specified at the end of a macro definition? +Back: `;` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Bibliography + +* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). \ No newline at end of file diff --git a/notes/formal-system/proof-system/natural-deduction.md b/notes/formal-system/proof-system/natural-deduction.md index 4b2c84f..21b89ca 100644 --- a/notes/formal-system/proof-system/natural-deduction.md +++ b/notes/formal-system/proof-system/natural-deduction.md @@ -46,7 +46,7 @@ END%% %%ANKI Basic -How are natural deduction's inference rules categorized into two? +With respect to propositional logic, how are natural deduction's inference rules divided into two categories? Back: As introduction and elimination rules. Reference: Gries, David. *The Science of Programming*. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981. @@ -54,7 +54,7 @@ END%% %%ANKI Basic -With respect to propositional logic, how are natural deduction's inference rules categorized into five? +With respect to propositional logic, how are natural deduction's inference rules divided into five categories? Back: As an introduction and elimination rule per propositional logic operator. Reference: Gries, David. *The Science of Programming*. Texts and Monographs in Computer Science. New York: Springer-Verlag, 1981. diff --git a/notes/hashing/addressing.md b/notes/hashing/addressing.md index 992ea29..5e3d383 100644 --- a/notes/hashing/addressing.md +++ b/notes/hashing/addressing.md @@ -611,7 +611,7 @@ END%% %%ANKI Basic -Consider open addressed hash table with $m$ slots. What condition must every probe sequence satisfy? +Consider an open addressed hash table with $m$ slots. What condition must every probe sequence satisfy? Back: Each sequence must be a permutation of $\langle 0, 1, \ldots, m - 1 \rangle$. Reference: Thomas H. Cormen et al., Introduction to Algorithms, Fourth edition (Cambridge, Massachusett: The MIT Press, 2022). diff --git a/notes/posix/signals.md b/notes/posix/signals.md index 4eea766..d4cbdf5 100644 --- a/notes/posix/signals.md +++ b/notes/posix/signals.md @@ -245,7 +245,16 @@ Tags: c17 END%% +%%ANKI +Basic +What does it mean for a program to (perform a) trap? +Back: It is terminated abruptly before its usual end. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + ## Bibliography * Cooper, Mendel. “Advanced Bash-Scripting Guide,” n.d., 916. * Dowling, “A List of Signals and What They Mean.” +* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). diff --git a/notes/set/natural-numbers.md b/notes/set/natural-numbers.md index 8d853ed..07adb45 100644 --- a/notes/set/natural-numbers.md +++ b/notes/set/natural-numbers.md @@ -838,6 +838,123 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre END%% +## Recursion Theorem + +The recursion theorem guarantees recursively defined functions exist. More formally, let $A$ be a set, $a \in A$, and $F \colon A \rightarrow A$. Then there exists a unique function $h \colon \omega \rightarrow A$ such that, for every $n \in \omega$, $$\begin{align*} h(0) & = a \\ h(n^+) & = F(h(n)) \end{align*}$$ + +%%ANKI +Basic +*Why* is the recursion theorem important? +Back: It guarantees recursively defined functions exist. +Reference: “Recursion,” in _Wikipedia_, September 23, 2024, [https://en.wikipedia.org/w/index.php?title=Recursion#The_recursion_theorem](https://en.wikipedia.org/w/index.php?title=Recursion&oldid=1247328220#The_recursion_theorem). + +END%% + +%%ANKI +Basic +What entities does the recursion theorem presume the existence of? +Back: A set $A$, an element $a \in A$, and a function $F \colon A \rightarrow A$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $a \in A$ and $F \colon A \rightarrow A$. The recursion theorem implies existence of what? +Back: A unique function $h \colon \omega \rightarrow A$ such that $h(0) = a$ and $h(n^+) = F(h(n))$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What function "signature" is considered in the consequent of the recursion theorem? +Back: $h \colon \omega \rightarrow A$ for some set $A$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What function "signature" is considered in the antecedent of the recursion theorem? +Back: $F \colon A \rightarrow A$ for some set $A$ and function $F$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Suppose the recursion theorem proves $h \colon \omega \rightarrow A$ exists. What does $h(0)$ equal? +Back: A fixed member of $A$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +The recursion theorem proves $h \colon \omega \rightarrow A$ exists. What does $h(n^+)$ equal? +Back: $F(h(n))$ for a fixed $F \colon A \rightarrow A$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +*Why* is the recursion theorem named the way it is? +Back: It guarantees recursively defined functions exist. +Reference: “Recursion,” in _Wikipedia_, September 23, 2024, [https://en.wikipedia.org/w/index.php?title=Recursion#The_recursion_theorem](https://en.wikipedia.org/w/index.php?title=Recursion&oldid=1247328220#The_recursion_theorem). + +END%% + +%%ANKI +Basic +The recursion theorem proves $h$ exists. What kind of mathematical entity is $h$? +Back: A function. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +The recursion theorem proves function $h$ exists. What is the domain of $h$? +Back: $\omega$ +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +The recursion theorem proves function $h$ exists. What is the codomain of $h$? +Back: A fixed set. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +The recursion theorem proves $h \colon \omega \rightarrow A$ exists. How do we compute $h(n)$? +Back: By applying $F$ to a fixed initial element $n$ times. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $a \in A$ and $F \colon A \rightarrow A$. Using the recursion theorem, how else is $F(F(F(F(a))))$ expressed? +Back: The recursion theorem implies existence of $h \colon \omega \rightarrow A$ satisfying $h(4) = F(F(F(F(a))))$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Which theorem in set theory implies existence of recursively defined functions? +Back: The recursion theorem (on $\omega$). +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + ## Bibliography -* Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). \ No newline at end of file +* Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). +* “Recursion,” in _Wikipedia_, September 23, 2024, [https://en.wikipedia.org/w/index.php?title=Recursion#The_recursion_theorem](https://en.wikipedia.org/w/index.php?title=Recursion&oldid=1247328220#The_recursion_theorem). \ No newline at end of file