Algorithmic notation and more on two's-complement.

c-declarations
Joshua Potter 2024-02-27 09:09:51 -07:00
parent a1447e824c
commit cf0daeab7d
14 changed files with 738 additions and 312 deletions

View File

@ -80,7 +80,8 @@
"lattice-path-chessboard-colored.png",
"lattice-path-before-recurrence.png",
"lattice-path-after-recurrence.png",
"merge-sort.gif"
"merge-sort.gif",
"theta-notation.png"
],
"File Hashes": {
"algorithms/index.md": "cd7c7ba91fb2f961c9f2437777e8e2ac",
@ -124,7 +125,7 @@
"algorithms/loop-invariants.md": "cbefc346842c21a6cce5c5edce451eb2",
"algorithms/loop-invariant.md": "29f9f9090a3109890d333a78acc18b50",
"algorithms/running-time.md": "5efc0791097d2c996f931c9046c95f65",
"algorithms/order-growth.md": "5fb2e3ccfc3710be7396a37da7c4f162",
"algorithms/order-growth.md": "d5481b2611a39f255cbd0bb8a4120a70",
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
"algorithms/sorting/selection-sort.md": "fcd0dc2ebaabd0a4db1baf7e7ef9f7a9",
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
@ -172,7 +173,7 @@
"algorithms/binary-search.md": "dbbaf8d4be7aabef1ed232c1906b4c99",
"_journal/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
"_journal/2024-02/2024-02-16.md": "e701902e369ec53098fc2deed4ec14fd",
"binary/integer-encoding.md": "bb73ce7edf88620fb4b59f33850277e2",
"binary/integer-encoding.md": "f4e553365bf596ddc7d24cfb12b63fab",
"combinatorics/index.md": "9a85e8858c50c9797243d6d01e1dcbe7",
"_journal/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
"_journal/2024-02/2024-02-17.md": "7c37cb10515ed3d2f5388eaf02a67048",
@ -180,11 +181,11 @@
"combinatorics/additive-principle.md": "e968028670f95ee9a7c5499ff7cb6792",
"_journal/2024-02-19.md": "30d16c5373deb9cb128d2e7934ae256a",
"_journal/2024-02/2024-02-18.md": "67e36dbbb2cac699d4533b5a2eaeb629",
"combinatorics/permutations.md": "89ac52a1a02629718555ea1652fa3b66",
"combinatorics/combinations.md": "7a22b15ca1bf0160680509c1f442f2d0",
"combinatorics/permutations.md": "7ff83dd8784eb08fc9389d38adc8862c",
"combinatorics/combinations.md": "a080e43827e792e100fcc8df2f280a4b",
"_journal/2024-02-20.md": "b85ba0eeeb16e30a602ccefabcc9763e",
"_journal/2024-02/2024-02-19.md": "df1a9ab7ab89244021b3003c84640c78",
"combinatorics/inclusion-exclusion.md": "4d5ba716bc90cd378c7c4c816b224c75",
"combinatorics/inclusion-exclusion.md": "ca5c967be774ce204f1ca47cc8df14b8",
"_journal/2024-02-21.md": "b9d944ecebe625da5dd72aeea6a916a2",
"_journal/2024-02/2024-02-20.md": "af2ef10727726200c4defe2eafc7d841",
"algebra/radices.md": "0fcd901c798eaed8075ff1375e2429dd",
@ -192,7 +193,7 @@
"_journal/2024-02/2024-02-21.md": "f423137ae550eb958378750d1f5e98c7",
"_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd",
"_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b",
"c17/strings.md": "9edfc287cbe2ad6539b88793b0af731e",
"c17/strings.md": "6bc3f41f111a7386b1abb2a196f1c683",
"c17/index.md": "78576ee41d0185df82c59999142f4edb",
"c17/escape-sequences.md": "ebc63c6cdfbe60bbc2708c1b0c8da8bb",
"c17/declarations.md": "46b135d583a992991c889d518fec1c0f",
@ -201,8 +202,10 @@
"_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7",
"_journal/2024-02-25.md": "fb1a48208c11d12262facc647749ca6f",
"_journal/2024-02/2024-02-24.md": "ee92fd63ebbda5f8ffa0abd06700ead1",
"_journal/2024-02-26.md": "67582808809eeb149c134d8dd021edd6",
"_journal/2024-02/2024-02-25.md": "426be827fe8483e4ab432304a2aa6df3"
"_journal/2024-02-26.md": "ccbee662c1b2c42027bce1ed6f9a5ac4",
"_journal/2024-02/2024-02-25.md": "426be827fe8483e4ab432304a2aa6df3",
"_journal/2024-02-27.md": "275c99a69ac426820df1803a462154ba",
"_journal/2024-02/2024-02-26.md": "417b84be5d96f9d8adcdedca3b68b141"
},
"fields_dict": {
"Basic": [

View File

@ -1,14 +0,0 @@
---
title: "2024-02-26"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] Sheet Music (10 min.)
- [ ] OGS (1 Life & Death Problem)
- [ ] Korean (Read 1 Story)
- [ ] Interview Prep (1 Practice Problem)
- [ ] Log Work Hours (Max 3 hours)
* Added flashcards on two's-complement addition.
* Consolidated `integer-encoding.md` with `shifts.md`.

View File

@ -0,0 +1,11 @@
---
title: "2024-02-27"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] Sheet Music (10 min.)
- [x] Go (1 Life & Death Problem)
- [ ] Korean (Read 1 Story)
- [ ] Interview Prep (1 Practice Problem)
- [ ] Log Work Hours (Max 3 hours)

View File

@ -0,0 +1,29 @@
---
title: "2024-02-26"
---
- [x] Anki Flashcards
- [x] KoL
- [ ] Sheet Music (10 min.)
- [x] OGS (1 Life & Death Problem)
- [ ] Korean (Read 1 Story)
- [x] Interview Prep (1 Practice Problem)
- [x] Log Work Hours (Max 3 hours)
* Added flashcards on two's-complement addition.
* Consolidated `integer-encoding.md` with `shifts.md`.
* Added notes on $\Theta$-notation.
* Read chapter 2 of "Designing Data-Intensive Applications".
* 101weiqi (serial numbers)
* Q-265171
* Q-40523
* Q-267801
* Q-368844
* Q-61135
* Q-12528
* Q-122965
* Q-77762
* Leetcode
* [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)
* [Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)
* [Remove Duplicates From Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/)

View File

@ -5,7 +5,7 @@ title: "{{date:YYYY-MM-DD}}"
- [ ] Anki Flashcards
- [ ] KoL
- [ ] Sheet Music (10 min.)
- [ ] OGS (1 Life & Death Problem)
- [ ] Go (1 Life & Death Problem)
- [ ] Korean (Read 1 Story)
- [ ] Interview Prep (1 Practice Problem)
- [ ] Log Work Hours (Max 3 hours)

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -91,6 +91,258 @@ Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambri
<!--ID: 1707344177515-->
END%%
%%ANKI
Basic
How do we simplify $\Theta(an^2 + bn + c)$?
Back: As $\Theta(n^2)$.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221765-->
END%%
%%ANKI
Basic
Explain why asymptotic notation is useful for *both* running times and space usage.
Back: Asymptotic notation represents functions in a general sense.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221769-->
END%%
%%ANKI
Basic
*Which* running time are algorithm designers typically concerned with?
Back: Worst-case running time.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221774-->
END%%
%%ANKI
Basic
In asymptotic notation, how is constant space usage denoted?
Back: Space usage is $O(1)$.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221778-->
END%%
%%ANKI
Basic
How could we replace equality $f(n) = \Theta(g(n))$ to be less "abusive"?
Back: Replace $=$ with $\in$.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221783-->
END%%
%%ANKI
Basic
How is equality abused in $f(n) = \Theta(g(n))$?
Back: Here $=$ actually refers to set membership.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221788-->
END%%
%%ANKI
Basic
How could we replace $1$ in $\Theta(1)$ to be less "abusive"?
Back: Replace $1$ with $n^0$.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221793-->
END%%
%%ANKI
Basic
*Why* does Cormen et al. consider $\Theta(1)$ to be a minor abuse?
Back: This expression does not indicate what variable is tending to infinity.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221797-->
END%%
## $\Theta$-notation
![[theta-notation.png]]
$\Theta$-notation refers to a strict lower- and upper-bound. It is defined as set $$\Theta(g(n)) = \{ f(n) \mid \exists c_1, c_2, n_0 > 0, \forall n \geq n_0, 0 \leq c_1g(x) \leq f(n) \leq c_2g(n) \}$$
%%ANKI
Basic
What kind of mathematical object is $\Theta(n)$?
Back: A set.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221801-->
END%%
%%ANKI
Basic
Using typical identifiers found in $\Theta(g(n))$, what values do $c_1$, $c_2$, and $n_0$ take on?
Back: Positive constants.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221806-->
END%%
%%ANKI
Basic
What names are usually given to the existentially quantified identifers in $\Theta(g(n))$'s definition?
Back: $c_1$, $c_2$, and $n_0$.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221811-->
END%%
%%ANKI
Basic
What name is usually given to the universally quantified identifer in $\Theta(g(n))$'s definition?
Back: $n$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221815-->
END%%
%%ANKI
Cloze
Using typical identifiers, $f(n) = \Theta(g(n))$ satisfies {$0$} $\leq$ {$c_1g(n)$} $\leq$ {$f(n)$} $\leq$ {$c_2g(n)$}.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221818-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the lower bound of $c_1g(n)$ in $\Theta(g(n))$?
Back: $0$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221822-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the upper bound of $c_1g(n)$ in the definition of $\Theta(g(n))$?
Back: $f(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221826-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the lower bound of $f(n)$ in the definition of $\Theta(g(n))$?
Back: $c_1g(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221830-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the upper bound of $f(n)$ in the definition of $\Theta(g(n))$?
Back: $c_2g(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221834-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the lower bound of $c_2g(n)$ in $\Theta(g(n))$?
Back: $f(n)$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221839-->
END%%
%%ANKI
Basic
Using typical identifiers, what is the upper bound of $c_2g(n)$ in $\Theta(g(n))$?
Back: N/A
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221844-->
END%%
%%ANKI
Cloze
Given $f(n) = \Theta(g(n))$, we say {1:$g(n)$} is an asymptotically {2:tight} bound for {1:$f(n)$}.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221851-->
END%%
%%ANKI
Basic
Which notation corresponds to asymptotically tight bounds?
Back: $\Theta$-notation.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221857-->
END%%
%%ANKI
Basic
Every member of $\Theta(g(n))$ is expected to be asymptotically what?
Back: Nonnegative.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221864-->
END%%
%%ANKI
What does it mean for function $f(n)$ to be asymptotically nonnegative?
Back: $f(n) \geq 0$ whenever $n$ is sufficiently large.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
END%%
%%ANKI
Basic
What does it mean for function $f(n)$ to be asymptotically positive?
Back: $f(n) > 0$ whenever $n$ is sufficiently large.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221871-->
END%%
%%ANKI
Basic
What condition must $g(n)$ satisfy such that otherwise $\Theta(g(n))$ is empty?
Back: $g(n)$ must be asymptotically nonnegative.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221876-->
END%%
%%ANKI
Basic
What does $\Theta(-n)$ evaluate to?
Back: $\varnothing$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221881-->
END%%
%%ANKI
Basic
*Why* is it $\Theta(-n) = \varnothing$?
Back: Because $-n$ is not asymptotically nonnegative.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221886-->
END%%
%%ANKI
Basic
How is $\Theta(g(n))$ defined?
Back: $\{ \exists c_1, c_2, n_0 > 0, \forall n \geq n_0, 0 \leq c_1g(n) \leq f(n) \leq c_2g(n) \}$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221892-->
END%%
%%ANKI
Basic
Using the typical identifiers, what values of $n$ are in the matrix of $\Theta(g(n))$'s definition?
Back: $n \geq n_0$
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221898-->
END%%
%%ANKI
Basic
Which asymptotic notation is this image demonstrating?
![[theta-notation.png]]
Back: $\Theta$-notation
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221904-->
END%%
%%ANKI
Basic
What values does the $y$-axis implicitly range over in the following?
![[theta-notation.png]]
Back: Nonnegative values.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221909-->
END%%
## References
* Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).

View File

@ -822,7 +822,395 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program
<!--ID: 1708701087982-->
END%%
## Shifting
## Arithmetic
### Addition
Addition of two unsigned or two two's-complement numbers operate in much the same way as grade-school arithmetic. Digits are added one-by-one and overflows "carried" to the next summation. Overflows are truncated; the final carry bit is discarded in the underlying bit adder.
%%ANKI
Basic
*Why* is adding $w$-bit integral types equal to $w$-bit truncation?
Back: The underlying bit adder discards any final carry bit.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678721-->
END%%
%%ANKI
Basic
Why should you generally prefer `x < y` over `x - y < 0`?
Back: The former avoids possible underflows.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678725-->
END%%
%%ANKI
Basic
How is `x - y < 0` rewritten more safely?
Back: `x < y`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678728-->
END%%
%%ANKI
Basic
What hardware-level advantage does two's-complement introduce over other signed encodings?
Back: The same circuits can be used for unsigned and two's-complement addition.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678732-->
END%%
%%ANKI
Basic
What representational-level advantage does two's-complement introduce over other signed encodings?
Back: `0` is encoded in only one way.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678736-->
END%%
Unsigned addition of $w$-bit integral types, denoted $+_w^u$, behaves like so:
$$x +_w^u y = \begin{cases}
x + y - 2^w & \text{if } x + y \geq 2^w \\
x + y & \text{otherwise}
\end{cases}$$
This is more simply expressed as $x +_w^u y = (x + y) \bmod 2^w$.
%%ANKI
Basic
What kind of overflows does unsigned addition potentially exhibit?
Back: Positive overflow.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678739-->
END%%
%%ANKI
Basic
Why is unsigned addition overflow *not* UB?
Back: Because the C standard enforces unsigned encoding of `unsigned` data types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1708799678742-->
END%%
%%ANKI
Basic
What does $+_w^u$ denote?
Back: Unsigned addition of $w$-bit integral types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678745-->
END%%
%%ANKI
Basic
Unsigned addition overflow is equivalent to what bit-level manipulation tactic?
Back: Truncation.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678748-->
END%%
%%ANKI
Basic
What is the result of $x +_w^u y$?
Back: $(x + y) \bmod 2^w$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678751-->
END%%
%%ANKI
Basic
*Why* does $x +_w^u y = (x + y) \bmod 2^w$?
Back: Because discarding any carry bit is equivalent to truncating the sum to $w$ bits.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678755-->
END%%
%%ANKI
Cloze
Without using modular arithmetic, $x +_w^u y =$ {$x + y$} if {$x + y < 2^w$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678758-->
END%%
%%ANKI
Cloze
Without using modular arithmetic, $x +_w^u y =$ {$x + y - 2^w$} if {$x + y \geq 2^w$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678761-->
END%%
%%ANKI
Basic
How do you detect whether unsigned addition $s \coloneqq x +_w^u y$ overflowed?
Back: Overflow occurs if and only if $s < x$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678765-->
END%%
%%ANKI
Basic
How would you complete the body of this function?
```c
/* Determine whether arguments can be added without overflow */
int uadd_ok(unsigned x, unsigned y);
```
Back:
```c
return (x + y) >= x;
```
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678769-->
END%%
%%ANKI
Basic
Does unsigned overflow detection depend on the left or right operand of $s \coloneqq x +_w^u y$?
Back: Either.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678772-->
END%%
%%ANKI
Basic
Why can we compare $s$ to $x$ or $y$ when detecting overflow of $s \coloneqq x +_w^u y$?
Back: Because unsigned addition is commutative.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678776-->
END%%
%%ANKI
Basic
Given integer $0 < x < 2^w$, what is $x$'s unsigned additive inverse?
Back: $2^w - x$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708808252010-->
END%%
%%ANKI
Basic
Which unsigned integer is its own additive inverse?
Back: $0$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708808252017-->
END%%
%%ANKI
Basic
What bitwise operations yield the additive inverse of an unsigned number $x$?
Back: `~x + 1`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784783-->
END%%
%%ANKI
Basic
Given unsigned integer `x`, what is the value of `x + ~x`?
Back: $UMax$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784788-->
END%%
Two's-complement addition, denoted $+_w^t$ operates similarly:
$$x +_w^u y = \begin{cases}
x + y - 2^w & \text{if } x + y \geq 2^{w-1} \\
x + y + 2^w & \text{if } x + y < -2^{w-1} \\
x + y & \text{otherwise}
\end{cases}$$
Unlike with unsigned addition, there is no simpler modulus operation that can be applied.
%%ANKI
Basic
What kind of overflows does two's-complement addition potentially exhibit?
Back: Positive and negative overflow.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376220-->
END%%
%%ANKI
Basic
Why is two's-complement addition overflow UB?
Back: Because the C standard does not mandate any particular signed integer encoding.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1708964376225-->
END%%
%%ANKI
Basic
What does $+_w^t$ denote?
Back: Two's-complement addition of $w$-bit integral types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376228-->
END%%
%%ANKI
Basic
*Why* doesn't two's-complement addition perform modular arithmetic?
Back: Because negative values are representable.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376231-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y - 2^w$} if {$x + y \geq 2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376235-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y + 2^w$} if {$x + y < -2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376238-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y$} if {$-2^{w-1} \leq x + y < 2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376242-->
END%%
%%ANKI
Basic
How do we detect $x +_w^t y$ positive overflowed?
Back: This happens iff $x > 0$, $y > 0$, and $x +_w^t y \leq 0$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376246-->
END%%
%%ANKI
Basic
How do we detect $x +_w^t y$ negative overflowed?
Back: This happens iff $x < 0$, $y < 0$, and $x +_w^t y \geq 0$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376250-->
END%%
%%ANKI
Basic
How can we write $x +_w^t y$ in terms of unsigned addition?
Back: $x +_w^t y = U2T_w(T2U_w(x) +_w^u T2U_w(y))$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376254-->
END%%
%%ANKI
*Why* are we able to characterize $+_w^t$ in terms of $+_w^u$?
Back: Because two's-complement addition has the same bit-level representation as unsigned addition.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
END%%
%%ANKI
Basic
How would you complete the body of this function?
```c
/* Determine whether arguments can be added without overflow */
int tadd_ok(int x, int y);
```
Back:
```c
int pos_over = x > 0 && y > 0 && (x + y) <= 0;
int neg_over = x < 0 && y < 0 && (x + y) >= 0;
return !pos_over && !neg_over;
```
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376259-->
END%%
%%ANKI
Basic
Given integer $-2^{w-1} < x < 2^{w-1}$, what is $x$'s two's-complement additive inverse?
Back: $-x$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709040965774-->
END%%
%%ANKI
Basic
What is the additive inverse of $TMin$?
Back: $TMin$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709040965804-->
END%%
%%ANKI
Basic
What is the additive inverse of $TMax$?
Back: $-TMax$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709040965810-->
END%%
%%ANKI
Basic
Which two's-complement integer is its own additive inverse?
Back: $TMin$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709040965815-->
END%%
%%ANKI
Basic
What bitwise operations yield the additive inverse of two's-complement number $x$?
Back: `~x + 1`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784791-->
END%%
%%ANKI
Basic
Given two's-complement integer `x`, what is the value of `x + ~x`?
Back: $-1$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784794-->
END%%
%%ANKI
Basic
What "splitting" approach to $x$'s two's-complement negation does Bryant et al. describe?
Back: Find the rightmost $1$ in $x$'s bit string representation and complement the bits to its left.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784797-->
END%%
%%ANKI
Basic
Where do we "split" $x$'s binary representation to perform two's-complement negation?
Back: At the rightmost $1$ in $x$'s binary representation.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784800-->
END%%
%%ANKI
Basic
Using *just* `~`, what is the two's-complement negation of $\langle x_{w-1}, \ldots, x_{k+1}, 1, 0, \ldots, 0\rangle$?
Back: $\langle \textasciitilde x_{w-1}, \ldots, \textasciitilde x_{k+1}, 1, 0, \ldots, 0 \rangle$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784803-->
END%%
%%ANKI
Basic
*Why* does complementing and adding one yield integer $x$'s additive inverse?
Back: `x + ~x` yields a bit string of all `1`s. Adding `1` to this overflows.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709042784806-->
END%%
%%ANKI
Basic
What decimal value does two's-complement `~x` evaluate to?
Back: `-x - 1`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1709044103781-->
END%%
### Shifting
Left shift operations (`<<`) drop the `k` most significant bits and fills the right end of the result with `k` zeros. Right shift operations (`>>`) are classified in two ways:
@ -1006,292 +1394,8 @@ Tags: c17
<!--ID: 1707873410780-->
END%%
## Arithmetic
### Addition
Addition of two unsigned or two two's-complement numbers operate in much the same way as grade-school arithmetic. Digits are added one-by-one and overflows "carried" to the next summation. Overflows are truncated; the final carry bit is discarded in the underlying bit adder.
%%ANKI
Basic
*Why* is adding $w$-bit integral types equal to $w$-bit truncation?
Back: The underlying bit adder discards any final carry bit.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678721-->
END%%
%%ANKI
Basic
Why should you generally prefer `x < y` over `x - y < 0`?
Back: The former avoids possible underflows.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678725-->
END%%
%%ANKI
Basic
How is `x - y < 0` rewritten more safely?
Back: `x < y`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678728-->
END%%
%%ANKI
Basic
What hardware-level advantage does two's-complement introduce over other signed encodings?
Back: The same circuits can be used for unsigned and two's-complement addition.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678732-->
END%%
%%ANKI
Basic
What representational-level advantage does two's-complement introduce over other signed encodings?
Back: `0` is encoded in only one way.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678736-->
END%%
Unsigned addition of $w$-bit integral types, denoted $+_w^u$, behaves like so:
$$x +_w^u y = \begin{cases}
x + y - 2^w & \text{if } x + y \geq 2^w \\
x + y & \text{otherwise}
\end{cases}$$
This is more simply expressed as $x +_w^u y = (x + y) \bmod 2^w$.
%%ANKI
Basic
What kind of overflows does unsigned addition potentially exhibit?
Back: Positive overflow.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678739-->
END%%
%%ANKI
Basic
Why is unsigned addition overflow *not* UB?
Back: Because the C standard enforces unsigned encoding of `unsigned` data types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1708799678742-->
END%%
%%ANKI
Basic
What does $+_w^u$ denote?
Back: Unsigned addition of $w$-bit integral types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678745-->
END%%
%%ANKI
Basic
Unsigned addition overflow is equivalent to what bit-level manipulation tactic?
Back: Truncation.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678748-->
END%%
%%ANKI
Basic
What is the result of $x +_w^u y$?
Back: $(x + y) \bmod 2^w$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678751-->
END%%
%%ANKI
Basic
*Why* does $x +_w^u y = (x + y) \bmod 2^w$?
Back: Because discarding any carry bit is equivalent to truncating the sum to $w$ bits.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678755-->
END%%
%%ANKI
Cloze
Without using modular arithmetic, $x +_w^u y =$ {$x + y$} if {$x + y < 2^w$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678758-->
END%%
%%ANKI
Cloze
Without using modular arithmetic, $x +_w^u y =$ {$x + y - 2^w$} if {$x + y \geq 2^w$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678761-->
END%%
%%ANKI
Basic
How do you detect whether unsigned addition $s \coloneqq x +_w^u y$ overflowed?
Back: Overflow occurs if and only if $s < x$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678765-->
END%%
%%ANKI
Basic
How would you complete the body of this function?
```c
/* Determine whether arguments can be added without overflow */
int uadd_ok(unsigned x, unsigned y);
```
Back:
```c
return (x + y) >= x;
```
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678769-->
END%%
%%ANKI
Basic
Does unsigned overflow detection depend on the left or right operand of $s \coloneqq x +_w^u y$?
Back: Either.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678772-->
END%%
%%ANKI
Basic
Why can we compare $s$ to $x$ or $y$ when detecting overflow of $s \coloneqq x +_w^u y$?
Back: Because unsigned addition is commutative.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708799678776-->
END%%
%%ANKI
Basic
Given integer $0 < x < 2^w$, what is $x$'s unsigned additive inverse?
Back: $2^w - x$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708808252010-->
END%%
%%ANKI
Basic
Which unsigned integer is its own additive inverse?
Back: $0$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708808252017-->
END%%
Two's-complement addition, denoted $+_w^t$ operates similarly:
$$x +_w^u y = \begin{cases}
x + y - 2^w & \text{if } x + y \geq 2^{w-1} \\
x + y + 2^w & \text{if } x + y < -2^{w-1} \\
x + y & \text{otherwise}
\end{cases}$$
Unlike with unsigned addition, there is no simpler modulus operation that can be applied.
%%ANKI
Basic
What kind of overflows does two's-complement addition potentially exhibit?
Back: Positive and negative overflow.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376220-->
END%%
%%ANKI
Basic
Why is two's-complement addition overflow UB?
Back: Because the C standard does not mandate any particular signed integer encoding.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1708964376225-->
END%%
%%ANKI
Basic
What does $+_w^t$ denote?
Back: Two's-complement addition of $w$-bit integral types.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376228-->
END%%
%%ANKI
Basic
*Why* doesn't two's-complement addition perform modular arithmetic?
Back: Because negative values are representable.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376231-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y - 2^w$} if {$x + y \geq 2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376235-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y + 2^w$} if {$x + y < -2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376238-->
END%%
%%ANKI
Cloze
$x +_w^t y =$ {$x + y$} if {$-2^{w-1} \leq x + y < 2^{w-1}$}.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376242-->
END%%
%%ANKI
Basic
How do we detect $x +_w^t y$ positive overflowed?
Back: This happens iff $x > 0$, $y > 0$, and $x +_w^t y \leq 0$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376246-->
END%%
%%ANKI
Basic
How do we detect $x +_w^t y$ negative overflowed?
Back: This happens iff $x < 0$, $y < 0$, and $x +_w^t y \geq 0$.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376250-->
END%%
%%ANKI
Basic
How can we write $x +_w^t y$ in terms of unsigned addition?
Back: $x +_w^t y = U2T_w(T2U_w(x) +_w^u T2U_w(y))$
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376254-->
END%%
%%ANKI
*Why* are we able to characterize $+_w^t$ in terms of $+_w^u$?
Back: Because two's-complement addition has the same bit-level representation as unsigned addition.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
END%%
%%ANKI
Basic
How would you complete the body of this function?
```c
/* Determine whether arguments can be added without overflow */
int tadd_ok(int x, int y);
```
Back:
```c
int pos_over = x > 0 && y > 0 && (x + y) <= 0;
int neg_over = x < 0 && y < 0 && (x + y) >= 0;
return !pos_over && !neg_over;
```
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
<!--ID: 1708964376259-->
END%%
## References
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
* Ronald L. Graham, Donald Ervin Knuth, and Oren Patashnik, *Concrete Mathematics: A Foundation for Computer Science*, 2nd ed (Reading, Mass: Addison-Wesley, 1994).
* “Twos-Complement.” In *Wikipedia*, January 9, 2024. [https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561](https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561).
* “Twos-Complement.” In *Wikipedia*, January 9, 2024. [https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561](https://en.wikipedia.org/w/index.php?title=Two%27s_complement&oldid=1194543561).

View File

@ -46,6 +46,15 @@ END%%
The syntax for the format placeholder is `%[flags][width][.precision][length]specifier`.
%%ANKI
Basic
What four optional parts make up a `printf` argument?
Back: Flags, width, precision, and length.
Reference: “Printf,” in *Wikipedia*, January 18, 2024, [https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962](https://en.wikipedia.org/w/index.php?title=Printf&oldid=1196716962).
Tags: printf
<!--ID: 1708974221761-->
END%%
%%ANKI
Basic
Which header file contains basic `printf` functionality?

View File

@ -528,6 +528,38 @@ Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n
<!--ID: 1708368078753-->
END%%
%%ANKI
Basic
What is a degree-0 polynomial?
Back: A constant.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221746-->
END%%
%%ANKI
Basic
What name is given to a degree-0 polynomial?
Back: A constant.
Reference: Thomas H. Cormen et al., *Introduction to Algorithms*, 3rd ed (Cambridge, Mass: MIT Press, 2009).
<!--ID: 1708974221749-->
END%%
%%ANKI
Basic
What name is given to a degree-1 polynomial?
Back: A monomial.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708974221752-->
END%%
%%ANKI
Basic
What name is given to a degree-2 polynomial?
Back: A binomial.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708974221755-->
END%%
%%ANKI
Basic
What is a binomial?

View File

@ -45,7 +45,7 @@ END%%
%%ANKI
Basic
What concept does PIE typically refer to?
What concept does PIE refer to?
Back: The **p**rinciple of **i**nclusion/**e**xclusion.
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708438356477-->

View File

@ -64,7 +64,7 @@ END%%
%%ANKI
Basic
How is $n!$ written recursively?
Back: As $n(n - 1)!$.
Back: $n(n - 1)!$
Reference: Oscar Levin, *Discrete Mathematics: An Open Introduction*, 3rd ed., n.d., [https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf](https://discrete.openmathbooks.org/pdfs/dmoi3-tablet.pdf).
<!--ID: 1708451749781-->
END%%