|
| 1 | +# formal-homework |
| 2 | + |
| 3 | +`formal-homework` is a small [Typst](https://typst.app) package that provides an easy way to start writing formal homework documents. |
| 4 | + |
| 5 | + |
| 6 | +## Usage |
| 7 | + |
| 8 | +First, create a new `.typ` file and import this package at the top: |
| 9 | + |
| 10 | +```typst |
| 11 | +#import "@preview/formal-homework:0.1.0": hw, q, a, br |
| 12 | +``` |
| 13 | + |
| 14 | +The entirety of the homework portion of your document will be contained in `hw()[]`, including the title page. Call it and pass the following (optional) parameters: |
| 15 | + |
| 16 | +- `title-text` -> Text to be used as title of document |
| 17 | + |
| 18 | +- `number` -> Number of the homework, only used if `title_text` is omitted |
| 19 | + |
| 20 | +- `author` -> Your name |
| 21 | + |
| 22 | +- `class` -> Name of the class/course that the homework is for |
| 23 | + |
| 24 | +- `due-date` -> Date that the homework is due |
| 25 | + |
| 26 | +```typst |
| 27 | +#hw( |
| 28 | + number: 5, |
| 29 | + author: "George P. Burdell", |
| 30 | + class: "CS 2050", |
| 31 | + due-date: "January 1, 1970" |
| 32 | +)[ |
| 33 | + Your content goes here. |
| 34 | +] |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +New Computer Modern is the default font, aiming for semblance to vanilla LaTeX, which professors likely prefer. To revert it, insert `#set text(font: "libertinus serif")` into the body of `#hw()[]`. |
| 40 | + |
| 41 | +The content of the document is laid out with the remaining macros: `#q[]`, `#a[]`, and `#br()` |
| 42 | + |
| 43 | +`#q[]` -> Contains the question, automatically enumerated |
| 44 | +`#a[]` -> Contains the answer, bordered with a black box |
| 45 | +`#br()` -> Shortcut for `#pagebreak()`, may be used to keep questions on their own page |
| 46 | + |
| 47 | +Note that `#q[]`s may embed `#a[]`, which is often useful for multi-part questions. An exhaustive example is provided below. |
| 48 | + |
| 49 | +```typst |
| 50 | +
|
| 51 | +#q[ |
| 52 | + Let $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m,n) = 2^(m - 1) (2n - 1)$. Prove that $f$ is bijective. |
| 53 | +] |
| 54 | +
|
| 55 | +#a[ |
| 56 | + *Lemma:* #h(0.5em) We proceed directly to show that the product of an even integer and an odd integer is an even integer. |
| 57 | +
|
| 58 | + Let $x$ be an odd integer. By definition of odd integer, $x = 2k + 1$ for some integer $k$. Let $y$ be an even integer. By definition of even integer, $y = 2j$ for some integer $j$. We show that the product of $x$ and $y$ is even. |
| 59 | +
|
| 60 | + $ |
| 61 | + x y &= (2k + 1)(2j) \ |
| 62 | + &= 4 k j + 2 j \ |
| 63 | + &= 2 (2 k j + j) \ |
| 64 | + $ |
| 65 | +
|
| 66 | + Since integers are closed under multiplication and addition, the expression $2 k j + j$ is an integer. Let that expression be assigned the variable $z$. Since $x y = 2z$, the product of $x$ and $y$ is an even integer. Therefore, the product of an even integer and an odd integer is an even integer. #sym.qed |
| 67 | +
|
| 68 | + *Proof:* #h(0.5em) We proceed directly to show that the function $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$ is bijective. |
| 69 | +
|
| 70 | + Let $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$. To show that $f$ is bijective, we must show injectivity and surjectivity. |
| 71 | +
|
| 72 | + *Injectivity Proof:* #h(0.5em) To show that $f$ is injective, we show that if $f(a,b) = f(c,d)$ for arbitrary $(a,b), (c,d) in (ZZ^+ times ZZ^+)$, then $(a,b) = (c,d)$. |
| 73 | +
|
| 74 | + Assume that for arbitrary $(a,b), (c,d) in (ZZ^+ times ZZ^+)$, $f(a,b) = f(c,d)$. |
| 75 | +
|
| 76 | + $ |
| 77 | + f(a,b) &= 2^(a - 1) (2b - 1) \ |
| 78 | + f(c,d) &= 2^(c - 1) (2d - 1) \ |
| 79 | + $ |
| 80 | + $ |
| 81 | + &=> 2^(a - 1) (2b - 1) = 2^(c - 1) (2d - 1) \ |
| 82 | + &= 2^(a - c) (2b - 1) = 2d - 1 \ |
| 83 | + $ |
| 84 | +
|
| 85 | + By Lemma, the product of an even integer and a positive integer is an even integer. Since $2b - 1$ and $2d - 1$ are odd integers, $2^(a - c)$ cannot be even. If $2^(a - c)$ was even, then $2d - 1$ would be even by Lemma, which is a contradiction. Thus, $2^(a - c)$ must be odd, and the only power of two that is odd is $2^0 = 1$. It follows that $2^(a - c) = 2^0$, so $a = c$. |
| 86 | +
|
| 87 | + Since $a = c$, we plug $a$ back into $f(a,b) = f(c,d)$ for $c$. |
| 88 | +
|
| 89 | + $ |
| 90 | + 2^(a - 1) (2b - 1) &= 2^(a - 1) (2d - 1) \ |
| 91 | + 2b - 1 &= 2d - 1 \ |
| 92 | + 2b &= 2d \ |
| 93 | + b &= d |
| 94 | + $ |
| 95 | +
|
| 96 | + Since $a = c$ and $b = d$, we have shown that if $f(a,b) = f(c,d)$, then $(a,c) = (c,d)$. Therefore, $f$ is injective. |
| 97 | +
|
| 98 | + *Surjectivity Proof:* #h(0.5em) To show that $f$ is surjective, we prove that for an arbitrary positive integer $z$, there exists an element $(x, y) in (ZZ^+ times ZZ^+)$ such that $z = f(x, y)$. |
| 99 | +
|
| 100 | + Let $z$ be an arbitrary positive integer. By the Fundamental Theorem of Arithmetic, $z$ may be uniquely written as $z = 2^p q$, where $p$ is a non-negative integer and $q$ is an odd positive integer. By the definition of odd positive integers, $q$ may be expressed as $q = 2k + 1$, where $k$ is a non-negative integer. Expressing $z$ in terms of $p$ and $k$ gives $z = 2^p (2k + 1)$. Define the variables $x = p + 1$ and $y = k + 1$. By the closure of integers under addition, $x$ and $y$ must be integers. Since $p$ and $q$ are positive, $x$ and $y$ must be positive. Therefore, $z$ may be expressed as a function of $x$ and $y$, and $(x,y)$ is an element of $ZZ^+ times ZZ^+$ by definition of Cartesian product. |
| 101 | +
|
| 102 | + Therefore, since we have shown that the function $f: ZZ^+ times ZZ^+ -> ZZ^+$ such that $f(m, n) = 2^(m - 1) (2n - 1)$ is injective and surjective, $f$ is bijective by definition of bijectivity. #sym.qed |
| 103 | +] |
| 104 | +
|
| 105 | +#br() |
| 106 | +
|
| 107 | +#q[ |
| 108 | + Determine whether the following sets are finite, countably infinite, or uncountably infinite. If finite, find it's cardinality. If countable, construct an injection from it to $NN $ (you do not have to prove that your function is an injection). |
| 109 | +
|
| 110 | + + The set of all multiples of 6. |
| 111 | +
|
| 112 | + #a[Countably infinite. For $s = 6k$, where $k in ZZ$, let $f(s) = |s| + 1$.] |
| 113 | +
|
| 114 | + + The set of all even prime numbers. |
| 115 | +
|
| 116 | + #a[Finite. The only even prime is 2; this set has a cardinality of 1.] |
| 117 | +
|
| 118 | + + The set of finite binary strings. Note: a binary string consists of $0 $s and $1 $s, for example: $1 0 1 1 $ and $0 0 1 0 0 0 0 1 1 $ are binary strings. |
| 119 | +
|
| 120 | + #a[Countably infinite. Let $f$ be a function that takes a binary string as input and outputs the base 10 conversion of a 1 followed by the binary string. ] |
| 121 | +
|
| 122 | + + The set of all infinite binary strings. |
| 123 | +
|
| 124 | + #a[Uncountably infinite.] |
| 125 | +
|
| 126 | + + The set of all real numbers between $e $ and $pi $ (inclusive). |
| 127 | +
|
| 128 | + #a[Uncountably infinite.] |
| 129 | +
|
| 130 | + + The set of all integers between $e $ and $pi $ (inclusive). |
| 131 | +
|
| 132 | + #a[Finite. This set has a cardinality of 1, with its only element being 3.] |
| 133 | +
|
| 134 | +] |
| 135 | +``` |
| 136 | + |
| 137 | +   |
| 138 | + |
0 commit comments