Skip to content

Commit 5b865bf

Browse files
daqnalDaniel Durling
andauthored
formal-homework:0.1.0 (#4239)
Co-authored-by: Daniel Durling <dan@dgd.sh>
1 parent d917492 commit 5b865bf

8 files changed

Lines changed: 919 additions & 0 deletions

File tree

packages/preview/formal-homework/0.1.0/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
![Title page example](images/title.png)
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+
![Proof page 1 example](images/proof1.png) ![Proof page 2 example](images/proof2.png) ![Subquestions example](images/subquestions.png)
138+
89.1 KB
Loading
61.9 KB
Loading
61.9 KB
Loading
16.3 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#let styles = ("1.", "(a)", "(i)")
2+
3+
#let enum-offset = state("offset", 0)
4+
5+
#let q-counter = counter("q")
6+
7+
#let q(body) = [
8+
#q-counter.step()
9+
10+
#context {
11+
let num = q-counter.display("1.")
12+
enum-offset.update(1)
13+
14+
block(width: 100%, above: 0.75em, below: 1em)[
15+
#place(left)[#box(width: 0.5em, align(right, num))]
16+
#pad(left: 1.3em, body)
17+
]
18+
19+
enum-offset.update(0)
20+
}
21+
]
22+
23+
#let a(body) = [
24+
#block(
25+
width: 100%,
26+
// In the future, these should be optional arguments
27+
// fill: none,
28+
// radius: 0pt,
29+
inset: 10pt,
30+
stroke: 1pt + black,
31+
breakable: true,
32+
)[#body]
33+
]
34+
35+
#let br() = pagebreak()
36+
37+
38+
#let hw(
39+
title-text: none,
40+
number: 1,
41+
author: none,
42+
class: none,
43+
due-date: none,
44+
body,
45+
) = {
46+
47+
counter(page).update(0)
48+
49+
set page(
50+
paper: "us-letter",
51+
margin: 1in,
52+
footer: context {
53+
if counter(page).get().first() > 0 [
54+
#align(center)[
55+
#counter(page).display()
56+
]
57+
]
58+
},
59+
)
60+
61+
set text(
62+
size: 12pt,
63+
lang: "en",
64+
font: "New Computer Modern"
65+
)
66+
67+
set enum(
68+
full: true,
69+
numbering: (..nums) => context {
70+
let offset = enum-offset.get()
71+
let depth = nums.pos().len() + offset
72+
let style = styles.at(depth - 1)
73+
numbering(style, nums.pos().last())
74+
}
75+
)
76+
77+
78+
align(horizon + center, block[
79+
#if title-text != none [
80+
#title[#title-text]
81+
] else [
82+
#title[Homework #number Submission]
83+
]
84+
85+
#class
86+
87+
#author
88+
89+
#due-date
90+
])
91+
92+
93+
pagebreak()
94+
95+
body
96+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "formal-homework"
3+
version = "0.1.0"
4+
entrypoint = "lib.typ"
5+
6+
authors = ["<@daqnal>"]
7+
license = "GPL-3.0-or-later"
8+
description = "Submit homeworks with simplicity and formality."
9+
10+
repository = "https://github.com/daqnal/formal-homework"
11+
categories = ["report"]

0 commit comments

Comments
 (0)