From 677877e4ceead19c8e34c5e21c58e7a84042d24b Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Mon, 25 Nov 2024 09:28:11 -0700 Subject: [PATCH] Pigeonhole principle, pointers. --- .../plugins/obsidian-to-anki-plugin/data.json | 12 +- notes/_journal/2024-11-25.md | 12 + notes/_journal/{ => 2024-11}/2024-11-23.md | 0 notes/_journal/2024-11/2024-11-24.md | 11 + notes/c17/types/derived.md | 254 +++++++++++++++++- notes/set/cardinality.md | 192 ++++++++++++- 6 files changed, 474 insertions(+), 7 deletions(-) create mode 100644 notes/_journal/2024-11-25.md rename notes/_journal/{ => 2024-11}/2024-11-23.md (100%) create mode 100644 notes/_journal/2024-11/2024-11-24.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 58f9351..733dada 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -265,7 +265,7 @@ "algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2", "algorithms/loop-invariant.md": "3b390e720f3b2a98e611b49a0bb1f5a9", "algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65", - "algorithms/order-growth.md": "434073572a080e423c1bf464806c6d65", + "algorithms/order-growth.md": "b50d02ccb785d9e50210f4c29836af70", "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "algorithms/sorting/selection-sort.md": "73415c44d6f4429f43c366078fd4bf98", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", @@ -800,7 +800,7 @@ "c17/basic-types.md": "7c6653bf6dc24c2f2aa72fc95c4f7875", "c17/types/simple.md": "44d56a2998f3bba578f14672c8b0ee3c", "c17/types/enumerated.md": "e1f70a30677c776b7b44ac3e0ff4e76d", - "c17/types/derived.md": "3776627765547e91086735ab834c2de1", + "c17/types/derived.md": "9d3a800fb7c944a9391f495c6978c99e", "c17/types/basic.md": "5064e21e683c0218890058882e06b6f3", "c17/types/index.md": "14b651bcfc8b2d62ffd200a74a9a2a6b", "_journal/2024-08-25.md": "e73a8edbd027d0f1a39289540eb512f2", @@ -950,10 +950,14 @@ "_journal/2024-11/2024-11-21.md": "951b6034d60a40dbd8201c50abf0dbb9", "_journal/2024-11/2024-11-20.md": "951b6034d60a40dbd8201c50abf0dbb9", "_journal/2024-11/2024-11-19.md": "d879f57154cb27cb168eb1f1f430e312", - "set/cardinality.md": "499e758bc0929af06736fa2974aade60", + "set/cardinality.md": "c334d969afe9248c691cb6d3623c958a", "geometry/area.md": "3c6e53a64ad3150d8f81f6e4a63da61a", "_journal/2024-11-23.md": "911f82ab8aede5ecdb96493aef64b0b9", - "_journal/2024-11/2024-11-22.md": "51117030e2364dbce3a8d507dead86ae" + "_journal/2024-11/2024-11-22.md": "51117030e2364dbce3a8d507dead86ae", + "_journal/2024-11-24.md": "225661114ad1b605132873e83acdf777", + "_journal/2024-11/2024-11-23.md": "1649e2f050cfb45a0c8cf52be29f625f", + "_journal/2024-11-25.md": "7f06ceccab35f6119f71d2e26174f142", + "_journal/2024-11/2024-11-24.md": "894b021e6335d4e6947448c8d362c083" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-11-25.md b/notes/_journal/2024-11-25.md new file mode 100644 index 0000000..cff9b71 --- /dev/null +++ b/notes/_journal/2024-11-25.md @@ -0,0 +1,12 @@ +--- +title: "2024-11-25" +--- + +- [ ] Anki Flashcards +- [x] KoL +- [ ] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Notes on the [[cardinality#Pigeonhole Principle|pigeonhole principle]]. +* Notes on pointers and function pointers. \ No newline at end of file diff --git a/notes/_journal/2024-11-23.md b/notes/_journal/2024-11/2024-11-23.md similarity index 100% rename from notes/_journal/2024-11-23.md rename to notes/_journal/2024-11/2024-11-23.md diff --git a/notes/_journal/2024-11/2024-11-24.md b/notes/_journal/2024-11/2024-11-24.md new file mode 100644 index 0000000..389949b --- /dev/null +++ b/notes/_journal/2024-11/2024-11-24.md @@ -0,0 +1,11 @@ +--- +title: "2024-11-24" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Notes on the [[derived#NULL|NULL]] macro. \ No newline at end of file diff --git a/notes/c17/types/derived.md b/notes/c17/types/derived.md index aec0362..5f7c67c 100644 --- a/notes/c17/types/derived.md +++ b/notes/c17/types/derived.md @@ -528,6 +528,47 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co END%% +Evaluation of an array `A` returns `&A[0]`, i.e. a [[#Pointers|pointer]] to the first array element. This is called **array decay**. + +%%ANKI +Basic +What is the effect of array decay? +Back: Evaluation of an array `A` returns `&A[0]`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What name is given to the implicit conversion of an array to a pointer? +Back: Array decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +According to Gustedt, what C feature explains why are there no "array values"? +Back: Array-to-pointer decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why can't arrays directly be made arguments to functions? +Back: Because array arguments decay to pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +In a function declaration, any array parameter rewrites to {a pointer}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + #### Fixed-Length A fixed-length array (FLA) has a predetermined size. Their stack allocations can be computed at compilation time. @@ -1270,9 +1311,220 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co END%% +### NULL + +The `NULL` macro refers to a **null pointer constant**, an ICE with value `0` or such an expression cast to type `void*`. The following table lists some valid values `NULL` can take on: + +| Expansion | Type | +| -------------------------- | -------------------- | +| `0U` | `unsigned` | +| `0` | `signed` | +| `\0` | `signed` | +| Enum constant of value `0` | `signed` | +| `0UL` | `unsigned long` | +| `0L` | `signed long` | +| `0ULL` | `unsigned long long` | +| `0LL` | `signed long long` | +| `(void*)0` | `void*` | + +%%ANKI +Basic +How are null pointer constants defined in terms of ICEs? +Back: As any ICE with value `0` or such an expression cast to type `void*`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What *must* the `NULL` macro expand to? +Back: Any null pointer constant. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are ICEs? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, and `0UL`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are null pointer constants? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, `0UL`, and `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list could `NULL` be identical to? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, `0UL`, and `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are pointer constants? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: Just `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why does Gustedt discourage use of `NULL`? +Back: The type of value it expands to is implementation-specific. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is wrong with the following invocation? +```c +printf("%d, %p", 1, NULL); +``` +Back: `NULL` may not refer to a pointer type. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What value must `NULL` have for the following to be correct? +```c +printf("%d, %p", 1, NULL); +``` +Back: `(void*)0` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Functions + +A function `f` without a following opening `(` is converted to a pointer to its start. This is called **function decay**. + +%%ANKI +Basic +What is the effect of function decay? +Back: Evaluation of a function `f` without a following opening `(` is converted to a pointer to its start. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What name is given to the implicit conversion of a function to a pointer? +Back: Function decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +According to Gustedt, what C feature explains why are there no "function values"? +Back: Function-to-pointer decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why can't functions directly be made arguments to functions? +Back: Because function arguments decay to pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +{1:Function pointers} are to {2:`(...)`} whereas {2:pointers} are to {1:`[...]`}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +f(3); +``` +Back: Decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(&f)(3); +``` +Back: Address of, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(*f)(3); +``` +Back: Decay, dereference, decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(*&f)(3); +``` +Back: Address of, dereference, decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(&*f)(3); +``` +Back: Decay, dereference, address of, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +{1:Pointers} refer to {2:arrays} whereas {2:function pointers} refer to {1:functions}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + ## Bibliography * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. * “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). * Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). -* Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. \ No newline at end of file +* Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. diff --git a/notes/set/cardinality.md b/notes/set/cardinality.md index 3700a22..8c28ab1 100644 --- a/notes/set/cardinality.md +++ b/notes/set/cardinality.md @@ -6,7 +6,7 @@ tags: - set --- -## Overview +## Equinumerosity We say set $A$ is **equinumerous** to set $B$, written ($A \approx B$) if and only if there exists a [[functions#Injections|one-to-one]] function from $A$ [[functions#Surjections|onto]] $B$. @@ -58,7 +58,51 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre END%% -## Equivalence Concept +### Power Sets + +No set is equinumerous to its [[set/index#Power Set Axiom|power set]]. This is typically shown using a diagonalization argument. + +%%ANKI +Basic +What basic set operation produces a new set the original isn't equinumerous to? +Back: The power set operation. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What kind of argument is typically made to prove no set is equinumerous to its power set? +Back: A diagonalization argument. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Who is attributed the discovery of the diagonalization argument? +Back: Georg Cantor. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $g \colon A \rightarrow \mathscr{P}A$. Using a diagonalization argument, what set is *not* in $\mathop{\text{ran}}(g)$? +Back: $\{ x \in A \mid x \not\in g(x) \}$ +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $g \colon A \rightarrow \mathscr{P}A$. *Why* isn't $B = \{x \in A \mid x \not\in g(x) \}$ in $\mathop{\text{ran}}(g)$? +Back: For all $x \in A$, $x \in B \Leftrightarrow x \not\in g(x)$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +### Equivalence Concept For any sets $A$, $B$, and $C$: @@ -143,6 +187,150 @@ Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Pre END%% +## Finiteness + +A set is **finite** if and only if it is equinumerous to some [[natural-numbers|natural number]]. Otherwise it is **infinite**. + +%%ANKI +Basic +How does Enderton define a finite set? +Back: As a set equinumerous to some natural number. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +How does Enderton define an infinite set? +Back: As a set not equinumerous to any natural number. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Is $n \in \omega$ a finite set? +Back: Yes. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +*Why* isn't $n \in \omega$ a finite set? +Back: N/A. It is. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Is $\omega$ a finite set? +Back: No. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +*Why* isn't $\omega$ a finite set? +Back: There is no natural number equinumerous to $\omega$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +### Pigeonhole Principle + +No natural number is equinumerous to a proper subset of itself. More generally, no finite set is equinumerous to a proper subset of itself. + +%%ANKI +Basic +How does Enderton state the pigeonhole principle for $\omega$? +Back: No natural number is equinumerous to a proper subset of itself. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +How does Enderton state the pigeonhole principle for finite sets? +Back: No finite set is equinumerous to a proper subset of itself. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $m \in n \in \omega$. What principle precludes $m \approx n$? +Back: The pigeonhole principle. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $S$ be a set and $n \in \omega$ such that $S \approx n$. For $m \in \omega$, when might $S \approx m$? +Back: *Only* if $m = n$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What is the generalization of the pigeonhole principle for $\omega$? +Back: The pigeonhole principle for finite sets. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What is the specialization of the pigeonhole principle for finite sets? +Back: The pigeonhole principle for $\omega$. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +What name is given to the following theorem? $$\text{No finite set is equinumerous to a proper subset of itself.}$$ +Back: The pigeonhole principle. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $S$ be a finite set and $f \colon S \rightarrow S$ be injective. Is $f$ a bijection? +Back: Yes. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $S$ be a finite set and $f \colon S \rightarrow S$ be injective. *Why* must $f$ be surjective? +Back: Otherwise $f$ is a bijection between $S$ and a proper subset of $S$, a contradiction. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $S$ be a finite set and $f \colon S \rightarrow S$ be surjective. Is $f$ a bijection? +Back: Yes. +Reference: Herbert B. Enderton, *Elements of Set Theory* (New York: Academic Press, 1977). + +END%% + +%%ANKI +Basic +Let $S$ be a finite set and $f \colon S \rightarrow S$ be surjective. *Why* must $f$ be injective? +Back: Otherwise $f$ is a bijection between a proper subset of $S$ and $S$, a contradiction. +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