Agent Work: HW2: Mathematical Induction and Graphs
Claude Opus 4.6 · COMP 182: Algorithmic Thinking
COMP 182: Algorithmic Thinking
Homework 2: Proofs, Sets, and Functions
---
1 Sets
Problem 1 [10 pts]
The symmetric difference of sets A and B, denoted by A triangle B, is the set containing those elements in A or B, but not in both A and B. For example, for A = {1, 2, 3} and B = {2, 3, 4, 5}, A triangle B = {1, 4, 5}.
(a) Prove that (A triangle B) triangle B = A.
(b) Is the following true: A triangle (B triangle C) = (A triangle B) triangle C? Prove your answer.
---
Problem 2 [5 pts]
Prove that if A and B are two finite sets, then |A intersection B| <= |A union B|. Determine when this relationship is an equality.
---
Problem 3
An ordered pair (a, b) differs from a set of two elements {a, b} since the elements of a set are unordered. But we can represent an ordered pair in terms of sets. Introduce a set-based formulation of ordered pairs and prove that (a, b) = (c, d) under your set-based formulation if and only if a = c and b = d.
---
2 Functions
Problem 1 [5 pts]
Let f(x) = x^2 + 1 and g(x) = x + 2. Compute f compose g and g compose f.
---
Problem 2 [5 pts]
If f and f compose g are one-to-one, does it follow that g is one-to-one? Justify your answer.
---
Problem 3 [10 pts]
Let f be a function from A to B and let S and T be subsets of A (i.e., S, T subset of A). Prove that:
(a) f(S union T) = f(S) union f(T).
(b) f(S intersection T) subset of f(S) intersection f(T).
---
Problem 4
Let A, B, and C be three sets such that there exist bijections f : A -> B and g : A -> C. Prove that there is a bijection h : B -> C by defining h and proving that it is indeed a bijection.
---
Problem 5
Let A and B be two finite sets of the same size. Prove that if f : A -> B is injective, then it is also surjective.
---
Problem 6
Let A and B be two infinite sets such that there exists a bijection between them. Consider an injective function f : A -> B. Is f necessarily surjective? Prove your answer.
---
3 Relations [25 points]
Problem 1
Let R1 be the relation defined on the set of ordered pairs of positive integers such that (a, b) R1 (c, d) if and only if ad = bc. Is R1 an equivalence relation? Prove your answer.
---
Problem 2
Let R1 and R2 be two equivalence relations. Is R1 intersection R2 an equivalence relation? Prove your answer.
---
Problem 3
A relation R on a set A is called *circular* if (a, b) in R and (b, c) in R implies (c, a) in R for all a, b, c in A. Prove or disprove: A relation is an equivalence relation if and only if it is reflexive and circular.
---
Problem 4
Give a partially ordered set, or poset, that has:
(a) a minimal element but no maximal element.
(b) neither a maximal nor a minimal element.
---
Problem 5 [8 pts]
Let (A, <=) be a partially ordered set that has no minimal element and A is not empty. Can A be finite?
---
# COMP182 Homework 2
## Student Responses
<!-- Write your solutions below. Add sections for each problem as needed. -->
<!-- Use proper mathematical notation where applicable. -->
[Your solutions here]
COMP182 Homework 2: Proofs, Sets, and Functions
Student Responses
---
1 Sets
Problem 1
(a) Prove that (A △ B) △ B = A.
Proof. We show both inclusions by element chasing.
Recall that x ∈ X △ Y if and only if x is in exactly one of X and Y, i.e., (x ∈ X and x ∉ Y) or (x ∉ X and x ∈ Y).
(⊆) Let x ∈ (A △ B) △ B. Then x is in exactly one of (A △ B) and B.
- Case 1: x ∈ (A △ B) and x ∉ B. Since x ∈ A △ B, either x ∈ A \ B or x ∈ B \ A. Since x ∉ B, we must have x ∈ A \ B, so x ∈ A.
- Case 2: x ∉ (A △ B) and x ∈ B. Since x ∉ A △ B, the element x is not in exactly one of A and B—it is either in both or in neither. Since x ∈ B, we must have x ∈ A ∩ B, so x ∈ A.
In both cases, x ∈ A.
(⊇) Let x ∈ A. We consider two sub-cases:
- Case 1: x ∈ A and x ∉ B. Then x ∈ A \ B ⊆ A △ B. Since x ∉ B, we have x ∈ (A △ B) \ B ⊆ (A △ B) △ B.
- Case 2: x ∈ A and x ∈ B. Then x ∈ A ∩ B, so x ∉ A △ B (since x is in both sets, not exactly one). Since x ∈ B and x ∉ A △ B, we have x ∈ B \ (A △ B) ⊆ (A △ B) △ B.
In both cases, x ∈ (A △ B) △ B.
Since both inclusions hold, (A △ B) △ B = A. ∎
---
(b) Is A △ (B △ C) = (A △ B) △ C? Yes, this is true.
Proof. We show that x ∈ A △ (B △ C) if and only if x is in an odd number of the sets A, B, C, and likewise for (A △ B) △ C.
Note that x ∈ X △ Y iff x is in exactly one of X, Y.
For the left side, x ∈ A △ (B △ C) iff x is in exactly one of A and (B △ C). Enumerating all membership combinations for A, B, C:
| x ∈ A? | x ∈ B? | x ∈ C? | x ∈ B △ C? | x ∈ A △ (B △ C)? |
|---|---|---|---|---|
| Yes | No | No | No | Yes |
| Yes | Yes | No | Yes | No |
| Yes | No | Yes | Yes | No |
| Yes | Yes | Yes | No | Yes |
| No | No | No | No | No |
| No | Yes | No | Yes | Yes |
| No | No | Yes | Yes | Yes |
| No | Yes | Yes | No | No |
So x ∈ A △ (B △ C) iff x belongs to an odd number of the sets {A, B, C}.
For the right side, x ∈ (A △ B) △ C iff x is in exactly one of (A △ B) and C:
| x ∈ A? | x ∈ B? | x ∈ C? | x ∈ A △ B? | x ∈ (A △ B) △ C? |
|---|---|---|---|---|
| Yes | No | No | Yes | Yes |
| Yes | Yes | No | No | No |
| Yes | No | Yes | Yes | No |
| Yes | Yes | Yes | No | Yes |
| No | No | No | No | No |
| No | Yes | No | Yes | Yes |
| No | No | Yes | No | Yes |
| No | Yes | Yes | Yes | No |
This is exactly the same set of rows marked "Yes"—precisely those where x belongs to an odd number of {A, B, C}.
Since both sides consist of exactly those elements belonging to an odd number of A, B, C, we have A △ (B △ C) = (A △ B) △ C. ∎
---
Problem 2
Prove that |A ∩ B| ≤ |A ∪ B| for finite sets A, B.
Proof. Since every element in A ∩ B is in both A and B, it is certainly in A ∪ B. Thus A ∩ B ⊆ A ∪ B. For finite sets, if S ⊆ T then |S| ≤ |T| (since an injective function from S to T is given by the inclusion map, and for finite sets an injection implies the domain is no larger than the codomain). Therefore |A ∩ B| ≤ |A ∪ B|. ∎
When is there equality? We have |A ∩ B| = |A ∪ B| if and only if A = B.
*Proof:* Since A ∩ B ⊆ A ∪ B, equality of cardinalities for finite sets implies A ∩ B = A ∪ B (a finite subset of a finite set with the same cardinality must equal the whole set). Now A ∩ B = A ∪ B implies:
- A ⊆ A ∪ B = A ∩ B ⊆ A, so A = A ∩ B, meaning A ⊆ B.
- Similarly B ⊆ A.
- Therefore A = B.
Conversely, if A = B, then A ∩ B = A = A ∪ B, so equality holds.
---
Problem 3
Set-based formulation of ordered pairs.
We use the Kuratowski definition: define the ordered pair as
> (a, b) := {{a}, {a, b}}.
Theorem. (a, b) = (c, d) if and only if a = c and b = d.
Proof.
(⇐) If a = c and b = d, then {{a}, {a, b}} = {{c}, {c, d}} immediately.
(⇒) Suppose {{a}, {a, b}} = {{c}, {c, d}}. We consider two cases.
Case 1: a = b. Then (a, b) = {{a}, {a, a}} = {{a}, {a}} = {{a}}. So {{a}} = {{c}, {c, d}}. A set with one element equals a set with two listed elements only if those two elements are the same, so {c} = {c, d} = {a}. From {c} = {a} we get c = a. From {c, d} = {a} and c = a, we get d = a = b. Thus a = c and b = d.
Case 2: a ≠ b. Then {a} ≠ {a, b} (since {a, b} has two distinct elements). The set {{a}, {a, b}} has exactly two elements. Since it equals {{c}, {c, d}}, which also has at most two elements, we consider which elements correspond:
- Sub-case 2a: {a} = {c} and {a, b} = {c, d}. From {a} = {c}, we get a = c. Then {a, b} = {a, d}, which (since a ≠ b) gives b = d.
- Sub-case 2b: {a} = {c, d} and {a, b} = {c}. From {a, b} = {c}, both a and b equal c, so a = b = c. But this contradicts a ≠ b.
In all cases, a = c and b = d. ∎
---
2 Functions
Problem 1
Let f(x) = x² + 1 and g(x) = x + 2.
f ∘ g: (f ∘ g)(x) = f(g(x)) = f(x + 2) = (x + 2)² + 1 = x² + 4x + 4 + 1 = x² + 4x + 5.
g ∘ f: (g ∘ f)(x) = g(f(x)) = g(x² + 1) = (x² + 1) + 2 = x² + 3.
---
Problem 2
Claim: If f and f ∘ g are one-to-one, then g is one-to-one.
Proof. Suppose g(x₁) = g(x₂) for some x₁, x₂ in the domain of g. Then:
f(g(x₁)) = f(g(x₂))
which means (f ∘ g)(x₁) = (f ∘ g)(x₂). Since f ∘ g is one-to-one, this implies x₁ = x₂.
Therefore g is one-to-one. ∎
---
Problem 3
Let f : A → B and S, T ⊆ A.
(a) Prove that f(S ∪ T) = f(S) ∪ f(T).
Proof.
(⊆) Let y ∈ f(S ∪ T). Then y = f(x) for some x ∈ S ∪ T. Either x ∈ S or x ∈ T (or both).
- If x ∈ S, then y = f(x) ∈ f(S).
- If x ∈ T, then y = f(x) ∈ f(T).
In either case, y ∈ f(S) ∪ f(T).
(⊇) Let y ∈ f(S) ∪ f(T). Then y ∈ f(S) or y ∈ f(T).
- If y ∈ f(S), then y = f(x) for some x ∈ S. Since S ⊆ S ∪ T, we have x ∈ S ∪ T, so y ∈ f(S ∪ T).
- If y ∈ f(T), then y = f(x) for some x ∈ T ⊆ S ∪ T, so y ∈ f(S ∪ T).
Since both inclusions hold, f(S ∪ T) = f(S) ∪ f(T). ∎
---
(b) Prove that f(S ∩ T) ⊆ f(S) ∩ f(T).
Proof. Let y ∈ f(S ∩ T). Then y = f(x) for some x ∈ S ∩ T. Since x ∈ S ∩ T, we have x ∈ S and x ∈ T. Therefore:
- y = f(x) ∈ f(S) (since x ∈ S), and
- y = f(x) ∈ f(T) (since x ∈ T).
So y ∈ f(S) ∩ f(T). This proves f(S ∩ T) ⊆ f(S) ∩ f(T). ∎
*Note:* Equality does not hold in general. For a counterexample, let A = {1, 2}, B = {3}, f(1) = f(2) = 3, S = {1}, T = {2}. Then S ∩ T = ∅, so f(S ∩ T) = ∅, but f(S) ∩ f(T) = {3} ∩ {3} = {3} ≠ ∅.
---
Problem 4
Claim: There exists a bijection h : B → C.
Proof. Since f : A → B is a bijection, it has an inverse f⁻¹ : B → A, which is also a bijection. Define
> h = g ∘ f⁻¹ : B → C.
We show h is a bijection by verifying it is both injective and surjective.
Injective: Suppose h(b₁) = h(b₂) for b₁, b₂ ∈ B. Then g(f⁻¹(b₁)) = g(f⁻¹(b₂)). Since g is injective (as it is a bijection), f⁻¹(b₁) = f⁻¹(b₂). Since f⁻¹ is injective (as it is a bijection), b₁ = b₂. So h is injective.
Surjective: Let c ∈ C. Since g is surjective, there exists a ∈ A with g(a) = c. Let b = f(a) ∈ B. Then f⁻¹(b) = a, so h(b) = g(f⁻¹(b)) = g(a) = c. So h is surjective.
Since h is both injective and surjective, h is a bijection from B to C. ∎
---
Problem 5
Claim: If A and B are finite sets with |A| = |B| and f : A → B is injective, then f is surjective.
Proof. Since f is injective, distinct elements of A map to distinct elements of B. Therefore the image f(A) = {f(a) : a ∈ A} has exactly |A| distinct elements, i.e., |f(A)| = |A|.
Since f(A) ⊆ B and both are finite with |f(A)| = |A| = |B|, the subset f(A) must equal all of B (a finite set cannot have a proper subset of the same cardinality). Therefore f(A) = B, which means f is surjective. ∎
---
Problem 6
Claim: No, an injective function f : A → B between infinite sets with a bijection between them is not necessarily surjective.
Counterexample. Let A = B = ℕ = {0, 1, 2, 3, ...} (the natural numbers). The identity function id : ℕ → ℕ is a bijection, so a bijection between A and B exists.
Define f : ℕ → ℕ by f(n) = 2n.
- f is injective: If f(n₁) = f(n₂), then 2n₁ = 2n₂, so n₁ = n₂.
- f is not surjective: The element 1 ∈ ℕ is not in the image of f, since 2n = 1 has no solution in ℕ.
Therefore, the existence of a bijection between two infinite sets does not guarantee that every injection between them is a surjection. ∎
---
3 Relations
Problem 1
Claim: R₁ defined on ordered pairs of positive integers by (a, b) R₁ (c, d) iff ad = bc is an equivalence relation.
Proof.
Reflexive: For any (a, b), we need (a, b) R₁ (a, b), i.e., ab = ba. This holds since multiplication of integers is commutative.
Symmetric: Suppose (a, b) R₁ (c, d), so ad = bc. Then cb = da (the same equation rearranged), which means (c, d) R₁ (a, b).
Transitive: Suppose (a, b) R₁ (c, d) and (c, d) R₁ (e, f). Then:
- ad = bc ... (1)
- cf = de ... (2)
We need to show af = be.
Multiply (1) by f: adf = bcf. Multiply (2) by b: bcf = bde.
Therefore adf = bde. Since d is a positive integer (d > 0), we can divide both sides by d:
af = be.
This gives (a, b) R₁ (e, f). Therefore R₁ is transitive.
Since R₁ is reflexive, symmetric, and transitive, it is an equivalence relation. ∎
*Remark:* The equivalence class of (a, b) corresponds to the rational number a/b, and the relation captures exactly when two fractions are equal: a/b = c/d iff ad = bc.
---
Problem 2
Claim: If R₁ and R₂ are equivalence relations on a set A, then R₁ ∩ R₂ is an equivalence relation on A.
Proof.
Reflexive: For all a ∈ A, since R₁ is reflexive, (a, a) ∈ R₁, and since R₂ is reflexive, (a, a) ∈ R₂. Therefore (a, a) ∈ R₁ ∩ R₂.
Symmetric: Suppose (a, b) ∈ R₁ ∩ R₂. Then (a, b) ∈ R₁ and (a, b) ∈ R₂. By symmetry of R₁, (b, a) ∈ R₁. By symmetry of R₂, (b, a) ∈ R₂. Therefore (b, a) ∈ R₁ ∩ R₂.
Transitive: Suppose (a, b) ∈ R₁ ∩ R₂ and (b, c) ∈ R₁ ∩ R₂. Then:
- (a, b) ∈ R₁ and (b, c) ∈ R₁, so by transitivity of R₁, (a, c) ∈ R₁.
- (a, b) ∈ R₂ and (b, c) ∈ R₂, so by transitivity of R₂, (a, c) ∈ R₂.
Therefore (a, c) ∈ R₁ ∩ R₂.
Since R₁ ∩ R₂ is reflexive, symmetric, and transitive, it is an equivalence relation. ∎
---
Problem 3
Definition. A relation R on A is *circular* if (a, b) ∈ R and (b, c) ∈ R implies (c, a) ∈ R.
Claim: A relation R on A is an equivalence relation if and only if it is reflexive and circular.
Proof.
(⇒) Suppose R is an equivalence relation (reflexive, symmetric, transitive). Clearly R is reflexive. To show R is circular: suppose (a, b) ∈ R and (b, c) ∈ R. By transitivity, (a, c) ∈ R. By symmetry, (c, a) ∈ R. So R is circular.
(⇐) Suppose R is reflexive and circular. We show R is symmetric and transitive.
Symmetric: Suppose (a, b) ∈ R. Since R is reflexive, (b, b) ∈ R. Applying the circular property to (a, b) ∈ R and (b, b) ∈ R, we get (b, a) ∈ R. So R is symmetric.
Transitive: Suppose (a, b) ∈ R and (b, c) ∈ R. By the circular property, (c, a) ∈ R. By symmetry (proved above), (a, c) ∈ R. So R is transitive.
Since R is reflexive, symmetric, and transitive, R is an equivalence relation. ∎
---
Problem 4
(a) A poset with a minimal element but no maximal element.
Example: (ℕ, ≤) where ℕ = {0, 1, 2, 3, ...} with the usual ordering.
- Minimal element: 0 is minimal because there is no n ∈ ℕ with n < 0.
- No maximal element: For any n ∈ ℕ, we have n < n + 1, so n is not maximal.
---
(b) A poset with neither a maximal nor a minimal element.
Example: (ℤ, ≤) where ℤ = {..., -2, -1, 0, 1, 2, ...} with the usual ordering.
- No minimal element: For any n ∈ ℤ, we have n - 1 < n, so n is not minimal.
- No maximal element: For any n ∈ ℤ, we have n < n + 1, so n is not maximal.
---
Problem 5
Can a non-empty finite partially ordered set have no minimal element?
No.
Proof. Let (A, ≤) be a non-empty finite partially ordered set. Suppose for contradiction that A has no minimal element. Pick any element a₁ ∈ A. Since a₁ is not minimal, there exists a₂ ∈ A with a₂ < a₁ (i.e., a₂ ≤ a₁ and a₂ ≠ a₁). Since a₂ is not minimal, there exists a₃ ∈ A with a₃ < a₂. Continuing inductively, we obtain an infinite sequence
a₁ > a₂ > a₃ > a₄ > ⋯
All elements in this sequence are distinct: if i < j, then by transitivity of ≤ we have aⱼ ≤ aⱼ₋₁ ≤ ⋯ ≤ aᵢ₊₁ ≤ aᵢ, so aⱼ ≤ aᵢ. Also aⱼ ≠ aᵢ (since each step is strict: aₖ₊₁ < aₖ, and if aⱼ = aᵢ, then aᵢ ≤ aⱼ = aᵢ₊₁ ≤ ... ≤ aᵢ₊₁, which combined with aᵢ₊₁ < aᵢ gives aᵢ ≤ aᵢ₊₁ and aᵢ₊₁ < aᵢ, a contradiction).
So the sequence a₁, a₂, a₃, ... consists of infinitely many distinct elements of A. But A is finite, so it cannot contain infinitely many distinct elements. This is a contradiction.
Therefore, every non-empty finite partially ordered set must have a minimal element, and A cannot be finite. ∎
COMP 182 Homework 2 — Grading Report
---
1 Sets
Problem 1(a) [5/5 pts]
The student provides an excellent element-chasing proof with both set inclusions (⊆ and ⊇). The case analysis is thorough and correct:
- ⊆ direction: Correctly handles both cases (x ∈ A△B and x ∉ B; x ∉ A△B and x ∈ B), properly deducing x ∈ A in each.
- ⊇ direction: Correctly splits on whether x ∈ B or x ∉ B, and shows x ∈ (A△B)△B in both cases.
Clear, rigorous, and complete.
Problem 1(b) [5/5 pts]
The student correctly identifies the statement as true and provides a complete truth-table enumeration proof. The key insight—that both sides equal the set of elements belonging to an odd number of {A, B, C}—is correct and clearly demonstrated with two exhaustive tables covering all 8 membership combinations. This is a valid and thorough approach.
Problem 2 [5/5 pts]
- Proof (3/3): Correctly argues A ∩ B ⊆ A ∪ B (every element in the intersection is in both sets, hence in the union), and invokes the fact that subset implies ≤ for finite cardinalities. Well justified.
- Equality condition (2/2): Correctly states equality holds iff A = B, and provides a complete proof in both directions (A ∩ B = A ∪ B ⟹ A = B, and A = B ⟹ A ∩ B = A ∪ B).
Problem 3 [ungraded]
Uses the standard Kuratowski definition (a, b) := {{a}, {a, b}} and provides a thorough proof with proper case analysis (a = b and a ≠ b). Excellent treatment.
---
2 Functions
Problem 1 [5/5 pts]
- f ∘ g = x² + 4x + 5 ✓ (2.5/2.5)
- g ∘ f = x² + 3 ✓ (2.5/2.5)
Both compositions computed correctly with work shown.
Problem 2 [5/5 pts]
The student gives a clean, direct proof: assumes g(x₁) = g(x₂), applies f to both sides to get (f ∘ g)(x₁) = (f ∘ g)(x₂), then uses injectivity of f ∘ g to conclude x₁ = x₂. This is correct and properly justified. (The direct proof is arguably more elegant than the contradiction approach in the reference solution.)
Problem 3(a) [5/5 pts]
Both directions proved correctly:
- ⊆: Correctly argues from y = f(x) with x ∈ S ∪ T to y ∈ f(S) ∪ f(T) via case split.
- ⊇: Correctly argues from y ∈ f(S) ∪ f(T) to y ∈ f(S ∪ T) using S ⊆ S ∪ T and T ⊆ S ∪ T.
Problem 3(b) [5/5 pts]
Correct one-direction proof of f(S ∩ T) ⊆ f(S) ∩ f(T). The student also provides a useful counterexample showing equality need not hold—a nice bonus insight that demonstrates deep understanding.
Problem 4 [ungraded]
Defines h = g ∘ f⁻¹ and proves both injectivity and surjectivity rigorously. Matches the reference solution perfectly.
Problem 5 [ungraded]
Uses the pigeonhole/cardinality argument (|f(A)| = |A| = |B|, so f(A) = B). Correct and well-written.
Problem 6 [ungraded]
Provides f(n) = 2n on ℕ as a counterexample—injective but not surjective (1 has no preimage). Valid alternative to the reference's f(n) = n + 10.
---
3 Relations
Problem 1 [9/9 pts]
- Reflexivity (3/3): Correctly shows ab = ba by commutativity.
- Symmetry (3/3): Correctly rearranges ad = bc to cb = da.
- Transitivity (3/3): Clever approach—multiplies equation (1) by f and equation (2) by b, yielding adf = bde, then divides by d (valid since d is a positive integer, hence d > 0). Clean and correct.
The remark connecting equivalence classes to rational numbers shows excellent mathematical insight.
Problem 2 [ungraded]
All three properties (reflexivity, symmetry, transitivity) proved correctly with clear reasoning. Matches the reference solution.
Problem 3 [ungraded]
Both directions proved correctly:
- (⇒) Uses transitivity + symmetry to derive circularity.
- (⇐) Derives symmetry from reflexivity + circularity, then transitivity from circularity + the just-proved symmetry.
Matches the reference solution exactly.
Problem 4 [8/8 pts]
- (a) (4/4): (ℕ, ≤) — minimal element 0, no maximal. Correct with justification.
- (b) (4/4): (ℤ, ≤) — neither minimal nor maximal. Correct with justification.
Problem 5 [8/8 pts]
Correctly answers No and provides a rigorous proof by contradiction: constructs an infinite strictly descending chain a₁ > a₂ > a₃ > ⋯, argues all elements are distinct (using antisymmetry), contradicting finiteness of A. Well-structured and complete.
---
Summary
| Problem | Score | Max |
|---|---|---|
| Sets 1(a) | 5 | 5 |
| Sets 1(b) | 5 | 5 |
| Sets 2 | 5 | 5 |
| Functions 1 | 5 | 5 |
| Functions 2 | 5 | 5 |
| Functions 3 | 10 | 10 |
| Relations 1 | 9 | 9 |
| Relations 4 | 8 | 8 |
| Relations 5 | 8 | 8 |
| Total | 60 | 60 |
Overall Comments: This is an outstanding submission. Every graded problem receives full marks. The proofs are uniformly rigorous, well-organized, and clearly written. The student demonstrates strong command of proof techniques (element chasing, contradiction, direct proof, case analysis) and goes beyond the minimum in several places (e.g., the counterexample in Functions 3(b), the remark connecting R₁ to rational numbers). The ungraded problems are also solved correctly and thoroughly.
Total: 60/60
diff --git a/writeup.md b/writeup.md
index 9eb4c4d..c679c03 100644
--- a/writeup.md
+++ b/writeup.md
@@ -1,9 +1,330 @@
-# COMP182 Homework 2
+# COMP182 Homework 2: Proofs, Sets, and Functions
## Student Responses
-<!-- Write your solutions below. Add sections for each problem as needed. -->
-<!-- Use proper mathematical notation where applicable. -->
+---
-[Your solutions here]
+## 1 Sets
+### Problem 1
+
+**(a)** Prove that (A △ B) △ B = A.
+
+**Proof.** We show both inclusions by element chasing.
+
+Recall that x ∈ X △ Y if and only if x is in exactly one of X and Y, i.e., (x ∈ X and x ∉ Y) or (x ∉ X and x ∈ Y).
+
+**(⊆)** Let x ∈ (A △ B) △ B. Then x is in exactly one of (A △ B) and B.
+
+- **Case 1:** x ∈ (A △ B) and x ∉ B. Since x ∈ A △ B, either x ∈ A \ B or x ∈ B \ A. Since x ∉ B, we must have x ∈ A \ B, so x ∈ A.
+- **Case 2:** x ∉ (A △ B) and x ∈ B. Since x ∉ A △ B, the element x is not in exactly one of A and B—it is either in both or in neither. Since x ∈ B, we must have x ∈ A ∩ B, so x ∈ A.
+
+In both cases, x ∈ A.
+
+**(⊇)** Let x ∈ A. We consider two sub-cases:
+
+- **Case 1:** x ∈ A and x ∉ B. Then x ∈ A \ B ⊆ A △ B. Since x ∉ B, we have x ∈ (A △ B) \ B ⊆ (A △ B) △ B.
+- **Case 2:** x ∈ A and x ∈ B. Then x ∈ A ∩ B, so x ∉ A △ B (since x is in both sets, not exactly one). Since x ∈ B and x ∉ A △ B, we have x ∈ B \ (A △ B) ⊆ (A △ B) △ B.
+
+In both cases, x ∈ (A △ B) △ B.
+
+Since both inclusions hold, (A △ B) △ B = A. ∎
+
+---
+
+**(b)** Is A △ (B △ C) = (A △ B) △ C? **Yes**, this is true.
+
+**Proof.** We show that x ∈ A △ (B △ C) if and only if x is in an odd number of the sets A, B, C, and likewise for (A △ B) △ C.
+
+Note that x ∈ X △ Y iff x is in exactly one of X, Y.
+
+For the left side, x ∈ A △ (B △ C) iff x is in exactly one of A and (B △ C). Enumerating all membership combinations for A, B, C:
+
+| x ∈ A? | x ∈ B? | x ∈ C? | x ∈ B △ C? | x ∈ A △ (B △ C)? |
+|---------|--------|--------|------------|-------------------|
+| Yes | No | No | No | Yes |
+| Yes | Yes | No | Yes | No |
+| Yes | No | Yes | Yes | No |
+| Yes | Yes | Yes | No | Yes |
+| No | No | No | No | No |
+| No | Yes | No | Yes | Yes |
+| No | No | Yes | Yes | Yes |
+| No | Yes | Yes | No | No |
+
+So x ∈ A △ (B △ C) iff x belongs to an odd number of the sets {A, B, C}.
+
+For the right side, x ∈ (A △ B) △ C iff x is in exactly one of (A △ B) and C:
+
+| x ∈ A? | x ∈ B? | x ∈ C? | x ∈ A △ B? | x ∈ (A △ B) △ C? |
+|---------|--------|--------|------------|-------------------|
+| Yes | No | No | Yes | Yes |
+| Yes | Yes | No | No | No |
+| Yes | No | Yes | Yes | No |
+| Yes | Yes | Yes | No | Yes |
+| No | No | No | No | No |
+| No | Yes | No | Yes | Yes |
+| No | No | Yes | No | Yes |
+| No | Yes | Yes | Yes | No |
+
+This is exactly the same set of rows marked "Yes"—precisely those where x belongs to an odd number of {A, B, C}.
+
+Since both sides consist of exactly those elements belonging to an odd number of A, B, C, we have A △ (B △ C) = (A △ B) △ C. ∎
+
+---
+
+### Problem 2
+
+**Prove that** |A ∩ B| ≤ |A ∪ B| for finite sets A, B.
+
+**Proof.** Since every element in A ∩ B is in both A and B, it is certainly in A ∪ B. Thus A ∩ B ⊆ A ∪ B. For finite sets, if S ⊆ T then |S| ≤ |T| (since an injective function from S to T is given by the inclusion map, and for finite sets an injection implies the domain is no larger than the codomain). Therefore |A ∩ B| ≤ |A ∪ B|. ∎
+
+**When is there equality?** We have |A ∩ B| = |A ∪ B| if and only if A = B.
+
+*Proof:* Since A ∩ B ⊆ A ∪ B, equality of cardinalities for finite sets implies A ∩ B = A ∪ B (a finite subset of a finite set with the same cardinality must equal the whole set). Now A ∩ B = A ∪ B implies:
+- A ⊆ A ∪ B = A ∩ B ⊆ A, so A = A ∩ B, meaning A ⊆ B.
+- Similarly B ⊆ A.
+- Therefore A = B.
+
+Conversely, if A = B, then A ∩ B = A = A ∪ B, so equality holds.
+
+---
+
+### Problem 3
+
+**Set-based formulation of ordered pairs.**
+
+We use the **Kuratowski definition**: define the ordered pair as
+
+> (a, b) := {{a}, {a, b}}.
+
+**Theorem.** (a, b) = (c, d) if and only if a = c and b = d.
+
+**Proof.**
+
+(⇐) If a = c and b = d, then {{a}, {a, b}} = {{c}, {c, d}} immediately.
+
+(⇒) Suppose {{a}, {a, b}} = {{c}, {c, d}}. We consider two cases.
+
+**Case 1: a = b.** Then (a, b) = {{a}, {a, a}} = {{a}, {a}} = {{a}}. So {{a}} = {{c}, {c, d}}. A set with one element equals a set with two listed elements only if those two elements are the same, so {c} = {c, d} = {a}. From {c} = {a} we get c = a. From {c, d} = {a} and c = a, we get d = a = b. Thus a = c and b = d.
+
+**Case 2: a ≠ b.** Then {a} ≠ {a, b} (since {a, b} has two distinct elements). The set {{a}, {a, b}} has exactly two elements. Since it equals {{c}, {c, d}}, which also has at most two elements, we consider which elements correspond:
+
+- **Sub-case 2a:** {a} = {c} and {a, b} = {c, d}. From {a} = {c}, we get a = c. Then {a, b} = {a, d}, which (since a ≠ b) gives b = d.
+
+- **Sub-case 2b:** {a} = {c, d} and {a, b} = {c}. From {a, b} = {c}, both a and b equal c, so a = b = c. But this contradicts a ≠ b.
+
+In all cases, a = c and b = d. ∎
+
+---
+
+## 2 Functions
+
+### Problem 1
+
+Let f(x) = x² + 1 and g(x) = x + 2.
+
+**f ∘ g:** (f ∘ g)(x) = f(g(x)) = f(x + 2) = (x + 2)² + 1 = x² + 4x + 4 + 1 = **x² + 4x + 5**.
+
+**g ∘ f:** (g ∘ f)(x) = g(f(x)) = g(x² + 1) = (x² + 1) + 2 = **x² + 3**.
+
+---
+
+### Problem 2
+
+**Claim:** If f and f ∘ g are one-to-one, then g is one-to-one.
+
+**Proof.** Suppose g(x₁) = g(x₂) for some x₁, x₂ in the domain of g. Then:
+
+f(g(x₁)) = f(g(x₂))
+
+which means (f ∘ g)(x₁) = (f ∘ g)(x₂). Since f ∘ g is one-to-one, this implies x₁ = x₂.
+
+Therefore g is one-to-one. ∎
+
+---
+
+### Problem 3
+
+Let f : A → B and S, T ⊆ A.
+
+**(a)** Prove that f(S ∪ T) = f(S) ∪ f(T).
+
+**Proof.**
+
+(⊆) Let y ∈ f(S ∪ T). Then y = f(x) for some x ∈ S ∪ T. Either x ∈ S or x ∈ T (or both).
+- If x ∈ S, then y = f(x) ∈ f(S).
+- If x ∈ T, then y = f(x) ∈ f(T).
+
+In either case, y ∈ f(S) ∪ f(T).
+
+(⊇) Let y ∈ f(S) ∪ f(T). Then y ∈ f(S) or y ∈ f(T).
+- If y ∈ f(S), then y = f(x) for some x ∈ S. Since S ⊆ S ∪ T, we have x ∈ S ∪ T, so y ∈ f(S ∪ T).
+- If y ∈ f(T), then y = f(x) for some x ∈ T ⊆ S ∪ T, so y ∈ f(S ∪ T).
+
+Since both inclusions hold, f(S ∪ T) = f(S) ∪ f(T). ∎
+
+---
+
+**(b)** Prove that f(S ∩ T) ⊆ f(S) ∩ f(T).
+
+**Proof.** Let y ∈ f(S ∩ T). Then y = f(x) for some x ∈ S ∩ T. Since x ∈ S ∩ T, we have x ∈ S and x ∈ T. Therefore:
+- y = f(x) ∈ f(S) (since x ∈ S), and
+- y = f(x) ∈ f(T) (since x ∈ T).
+
+So y ∈ f(S) ∩ f(T). This proves f(S ∩ T) ⊆ f(S) ∩ f(T). ∎
+
+*Note:* Equality does not hold in general. For a counterexample, let A = {1, 2}, B = {3}, f(1) = f(2) = 3, S = {1}, T = {2}. Then S ∩ T = ∅, so f(S ∩ T) = ∅, but f(S) ∩ f(T) = {3} ∩ {3} = {3} ≠ ∅.
+
+---
+
+### Problem 4
+
+**Claim:** There exists a bijection h : B → C.
+
+**Proof.** Since f : A → B is a bijection, it has an inverse f⁻¹ : B → A, which is also a bijection. Define
+
+> h = g ∘ f⁻¹ : B → C.
+
+We show h is a bijection by verifying it is both injective and surjective.
+
+**Injective:** Suppose h(b₁) = h(b₂) for b₁, b₂ ∈ B. Then g(f⁻¹(b₁)) = g(f⁻¹(b₂)). Since g is injective (as it is a bijection), f⁻¹(b₁) = f⁻¹(b₂). Since f⁻¹ is injective (as it is a bijection), b₁ = b₂. So h is injective.
+
+**Surjective:** Let c ∈ C. Since g is surjective, there exists a ∈ A with g(a) = c. Let b = f(a) ∈ B. Then f⁻¹(b) = a, so h(b) = g(f⁻¹(b)) = g(a) = c. So h is surjective.
+
+Since h is both injective and surjective, h is a bijection from B to C. ∎
+
+---
+
+### Problem 5
+
+**Claim:** If A and B are finite sets with |A| = |B| and f : A → B is injective, then f is surjective.
+
+**Proof.** Since f is injective, distinct elements of A map to distinct elements of B. Therefore the image f(A) = {f(a) : a ∈ A} has exactly |A| distinct elements, i.e., |f(A)| = |A|.
+
+Since f(A) ⊆ B and both are finite with |f(A)| = |A| = |B|, the subset f(A) must equal all of B (a finite set cannot have a proper subset of the same cardinality). Therefore f(A) = B, which means f is surjective. ∎
+
+---
+
+### Problem 6
+
+**Claim:** No, an injective function f : A → B between infinite sets with a bijection between them is **not** necessarily surjective.
+
+**Counterexample.** Let A = B = ℕ = {0, 1, 2, 3, ...} (the natural numbers). The identity function id : ℕ → ℕ is a bijection, so a bijection between A and B exists.
+
+Define f : ℕ → ℕ by f(n) = 2n.
+
+- **f is injective:** If f(n₁) = f(n₂), then 2n₁ = 2n₂, so n₁ = n₂.
+- **f is not surjective:** The element 1 ∈ ℕ is not in the image of f, since 2n = 1 has no solution in ℕ.
+
+Therefore, the existence of a bijection between two infinite sets does not guarantee that every injection between them is a surjection. ∎
+
+---
+
+## 3 Relations
+
+### Problem 1
+
+**Claim:** R₁ defined on ordered pairs of positive integers by (a, b) R₁ (c, d) iff ad = bc is an equivalence relation.
+
+**Proof.**
+
+**Reflexive:** For any (a, b), we need (a, b) R₁ (a, b), i.e., ab = ba. This holds since multiplication of integers is commutative.
+
+**Symmetric:** Suppose (a, b) R₁ (c, d), so ad = bc. Then cb = da (the same equation rearranged), which means (c, d) R₁ (a, b).
+
+**Transitive:** Suppose (a, b) R₁ (c, d) and (c, d) R₁ (e, f). Then:
+- ad = bc ... (1)
+- cf = de ... (2)
+
+We need to show af = be.
+
+Multiply (1) by f: adf = bcf.
+Multiply (2) by b: bcf = bde.
+
+Therefore adf = bde. Since d is a positive integer (d > 0), we can divide both sides by d:
+
+af = be.
+
+This gives (a, b) R₁ (e, f). Therefore R₁ is transitive.
+
+Since R₁ is reflexive, symmetric, and transitive, it is an equivalence relation. ∎
+
+*Remark:* The equivalence class of (a, b) corresponds to the rational number a/b, and the relation captures exactly when two fractions are equal: a/b = c/d iff ad = bc.
+
+---
+
+### Problem 2
+
+**Claim:** If R₁ and R₂ are equivalence relations on a set A, then R₁ ∩ R₂ is an equivalence relation on A.
+
+**Proof.**
+
+**Reflexive:** For all a ∈ A, since R₁ is reflexive, (a, a) ∈ R₁, and since R₂ is reflexive, (a, a) ∈ R₂. Therefore (a, a) ∈ R₁ ∩ R₂.
+
+**Symmetric:** Suppose (a, b) ∈ R₁ ∩ R₂. Then (a, b) ∈ R₁ and (a, b) ∈ R₂. By symmetry of R₁, (b, a) ∈ R₁. By symmetry of R₂, (b, a) ∈ R₂. Therefore (b, a) ∈ R₁ ∩ R₂.
+
+**Transitive:** Suppose (a, b) ∈ R₁ ∩ R₂ and (b, c) ∈ R₁ ∩ R₂. Then:
+- (a, b) ∈ R₁ and (b, c) ∈ R₁, so by transitivity of R₁, (a, c) ∈ R₁.
+- (a, b) ∈ R₂ and (b, c) ∈ R₂, so by transitivity of R₂, (a, c) ∈ R₂.
+
+Therefore (a, c) ∈ R₁ ∩ R₂.
+
+Since R₁ ∩ R₂ is reflexive, symmetric, and transitive, it is an equivalence relation. ∎
+
+---
+
+### Problem 3
+
+**Definition.** A relation R on A is *circular* if (a, b) ∈ R and (b, c) ∈ R implies (c, a) ∈ R.
+
+**Claim:** A relation R on A is an equivalence relation if and only if it is reflexive and circular.
+
+**Proof.**
+
+**(⇒)** Suppose R is an equivalence relation (reflexive, symmetric, transitive). Clearly R is reflexive. To show R is circular: suppose (a, b) ∈ R and (b, c) ∈ R. By transitivity, (a, c) ∈ R. By symmetry, (c, a) ∈ R. So R is circular.
+
+**(⇐)** Suppose R is reflexive and circular. We show R is symmetric and transitive.
+
+**Symmetric:** Suppose (a, b) ∈ R. Since R is reflexive, (b, b) ∈ R. Applying the circular property to (a, b) ∈ R and (b, b) ∈ R, we get (b, a) ∈ R. So R is symmetric.
+
+**Transitive:** Suppose (a, b) ∈ R and (b, c) ∈ R. By the circular property, (c, a) ∈ R. By symmetry (proved above), (a, c) ∈ R. So R is transitive.
+
+Since R is reflexive, symmetric, and transitive, R is an equivalence relation. ∎
+
+---
+
+### Problem 4
+
+**(a)** A poset with a minimal element but no maximal element.
+
+**Example:** (ℕ, ≤) where ℕ = {0, 1, 2, 3, ...} with the usual ordering.
+
+- **Minimal element:** 0 is minimal because there is no n ∈ ℕ with n < 0.
+- **No maximal element:** For any n ∈ ℕ, we have n < n + 1, so n is not maximal.
+
+---
+
+**(b)** A poset with neither a maximal nor a minimal element.
+
+**Example:** (ℤ, ≤) where ℤ = {..., -2, -1, 0, 1, 2, ...} with the usual ordering.
+
+- **No minimal element:** For any n ∈ ℤ, we have n - 1 < n, so n is not minimal.
+- **No maximal element:** For any n ∈ ℤ, we have n < n + 1, so n is not maximal.
+
+---
+
+### Problem 5
+
+**Can a non-empty finite partially ordered set have no minimal element?**
+
+**No.**
+
+**Proof.** Let (A, ≤) be a non-empty finite partially ordered set. Suppose for contradiction that A has no minimal element. Pick any element a₁ ∈ A. Since a₁ is not minimal, there exists a₂ ∈ A with a₂ < a₁ (i.e., a₂ ≤ a₁ and a₂ ≠ a₁). Since a₂ is not minimal, there exists a₃ ∈ A with a₃ < a₂. Continuing inductively, we obtain an infinite sequence
+
+a₁ > a₂ > a₃ > a₄ > ⋯
+
+All elements in this sequence are distinct: if i < j, then by transitivity of ≤ we have aⱼ ≤ aⱼ₋₁ ≤ ⋯ ≤ aᵢ₊₁ ≤ aᵢ, so aⱼ ≤ aᵢ. Also aⱼ ≠ aᵢ (since each step is strict: aₖ₊₁ < aₖ, and if aⱼ = aᵢ, then aᵢ ≤ aⱼ = aᵢ₊₁ ≤ ... ≤ aᵢ₊₁, which combined with aᵢ₊₁ < aᵢ gives aᵢ ≤ aᵢ₊₁ and aᵢ₊₁ < aᵢ, a contradiction).
+
+So the sequence a₁, a₂, a₃, ... consists of infinitely many distinct elements of A. But A is finite, so it cannot contain infinitely many distinct elements. This is a contradiction.
+
+Therefore, every non-empty finite partially ordered set must have a minimal element, and A cannot be finite. ∎
Sub-Model Usage
| Model | Input | Output | Cache Read | Cost |
|---|---|---|---|---|
| claude-opus-4-6 | 9 | 14.0K | 285.4K | $0.71 |
BSCS Bench