Logic and Set Theory
Introduction
Logic and Set Theory are fundamental branches of mathematics that provide the foundation for many areas in computer science, mathematics, and philosophy. Logic deals with the principles of valid reasoning, while Set Theory provides a framework for organizing and manipulating collections of objects.
- Foundation for mathematical reasoning and proofs
- Essential for computer science (programming, algorithms, databases)
- Improves critical thinking and analytical skills
- Provides tools for solving complex problems in various fields
1. Propositional Logic
1.1 Propositions
A proposition is a declarative statement that is either true or false, but not both.
- "Paris is the capital of France." (True)
- "7 + 5 = 10" (False)
- "All prime numbers are odd." (False, because 2 is prime but even)
- "How are you?" (Question, not a statement)
- "Go to the store." (Command, not a statement)
- "This statement is false." (Paradoxical, cannot be assigned a truth value)
We typically use letters like p, q, r to denote propositions.
1.2 Logical Connectives
Logical connectives allow us to combine simple propositions into compound propositions.
Connective | Symbol | Name | Meaning |
---|---|---|---|
NOT | ¬ | Negation | "It is not the case that" |
AND | ∧ | Conjunction | "Both... and..." |
OR | ∨ | Disjunction | "Either... or... (or both)" |
IF...THEN | → | Implication | "If... then..." |
IF AND ONLY IF | ↔ | Biconditional | "... if and only if..." |
Let p: "It is raining" and q: "The ground is wet"
- ¬p: "It is not raining"
- p ∧ q: "It is raining and the ground is wet"
- p ∨ q: "It is raining or the ground is wet (or both)"
- p → q: "If it is raining, then the ground is wet"
- p ↔ q: "It is raining if and only if the ground is wet"
1.3 Truth Tables
Truth tables define the meaning of logical connectives by showing how the truth value of a compound proposition depends on the truth values of its components.
Negation (NOT): ¬p
p | ¬p |
---|---|
T | F |
F | T |
The negation of a true statement is false, and the negation of a false statement is true.
Conjunction (AND): p ∧ q
p | q | p ∧ q |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | F |
A conjunction is true only when both of its components are true.
Disjunction (OR): p ∨ q
p | q | p ∨ q |
---|---|---|
T | T | T |
T | F | T |
F | T | T |
F | F | F |
A disjunction is true when at least one of its components is true.
Implication (IF-THEN): p → q
p | q | p → q |
---|---|---|
T | T | T |
T | F | F |
F | T | T |
F | F | T |
An implication is false only when the antecedent (p) is true and the consequent (q) is false.
The implication p → q can be read as "if p, then q" or "p implies q". It is only false when p is true and q is false.
Note that "if p, then q" is equivalent to "not p or q" (¬p ∨ q).
Biconditional (IF AND ONLY IF): p ↔ q
p | q | p ↔ q |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | T |
A biconditional is true when both components have the same truth value.
p ↔ q is equivalent to (p → q) ∧ (q → p)
Creating Truth Tables for Complex Expressions
Let's create a truth table for the expression (p → q) ∧ ¬p
p | q | p → q | ¬p | (p → q) ∧ ¬p |
---|---|---|---|---|
T | T | T | F | F |
T | F | F | F | F |
F | T | T | T | T |
F | F | T | T | T |
Method:
- List all possible combinations of truth values for the variables.
- Build the truth table column by column, working from the simplest components.
- Use the previously computed columns to determine the values for more complex expressions.
1.4 Logical Equivalence
Two logical expressions are equivalent if they have the same truth values for all possible combinations of their variables.
p | q | p → q | ¬p | ¬p ∨ q |
---|---|---|---|---|
T | T | T | F | T |
T | F | F | F | F |
F | T | T | T | T |
F | F | T | T | T |
Since the columns for p → q and ¬p ∨ q are identical, the expressions are logically equivalent.
Important Logical Equivalences
Law | Equivalence |
---|---|
Double Negation | ¬(¬p) ≡ p |
Commutative Laws | p ∧ q ≡ q ∧ p p ∨ q ≡ q ∨ p |
Associative Laws | (p ∧ q) ∧ r ≡ p ∧ (q ∧ r) (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) |
Distributive Laws | p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) |
De Morgan's Laws | ¬(p ∧ q) ≡ ¬p ∨ ¬q ¬(p ∨ q) ≡ ¬p ∧ ¬q |
Implication Law | p → q ≡ ¬p ∨ q |
Contrapositive | p → q ≡ ¬q → ¬p |
Biconditional Law | p ↔ q ≡ (p → q) ∧ (q → p) |
Example: Simplify ¬(p ∧ (q ∨ ¬r)) using logical equivalences.
Solution:
- ¬(p ∧ (q ∨ ¬r))
- Apply De Morgan's Law: ¬p ∨ ¬(q ∨ ¬r)
- Apply De Morgan's Law again: ¬p ∨ (¬q ∧ ¬(¬r))
- Apply Double Negation: ¬p ∨ (¬q ∧ r)
- The simplified expression is: ¬p ∨ (¬q ∧ r)
1.5 Arguments and Validity
An argument consists of a set of premises and a conclusion. An argument is valid if the conclusion logically follows from the premises.
Premises:
- If it rains, then the ground gets wet. (p → q)
- It is raining. (p)
Conclusion: The ground is wet. (q)
This is a valid argument form known as Modus Ponens.
Common Valid Argument Forms
Name | Form |
---|---|
Modus Ponens | p → q, p ⊢ q |
Modus Tollens | p → q, ¬q ⊢ ¬p |
Hypothetical Syllogism | p → q, q → r ⊢ p → r |
Disjunctive Syllogism | p ∨ q, ¬p ⊢ q |
Addition | p ⊢ p ∨ q |
Simplification | p ∧ q ⊢ p |
Conjunction | p, q ⊢ p ∧ q |
Resolution | p ∨ q, ¬p ∨ r ⊢ q ∨ r |
The symbol ⊢ means "therefore" or "it can be derived that."
Example: Determine if the following argument is valid:
Premises:
- If I study hard, I will pass the exam. (p → q)
- I did not pass the exam. (¬q)
Conclusion: I did not study hard. (¬p)
Analysis:
Let's check if the conclusion logically follows from the premises:
- p → q (Premise 1)
- ¬q (Premise 2)
- We want to determine if ¬p follows logically
This is an example of Modus Tollens (p → q, ¬q ⊢ ¬p), which is a valid argument form.
Therefore, the argument is valid.
2. Set Theory
2.1 Set Basics
A set is a well-defined collection of distinct objects, called elements or members of the set.
Set Notation
- Roster Notation: Listing all elements inside curly braces: A = {1, 2, 3, 4, 5}
- Set-Builder Notation: Specifying a property that defines the set: B = {x | x is an even integer and 0 ≤ x ≤ 10}
- Element Notation: a ∈ A means "a is an element of set A"
- Not an Element: a ∉ A means "a is not an element of set A"
Special Sets
- Empty Set (∅ or {}): The set containing no elements
- Universal Set (U): The set containing all elements under consideration
- Natural Numbers (ℕ): {1, 2, 3, ...}
- Integers (ℤ): {..., -2, -1, 0, 1, 2, ...}
- Rational Numbers (ℚ): Numbers expressible as fractions
- Real Numbers (ℝ): All numbers on the number line
Set Properties
- Cardinality: The number of elements in a set, denoted |A|
- Subset: A ⊆ B means every element of A is also in B
- Proper Subset: A ⊂ B means A ⊆ B and A ≠ B
- Equal Sets: A = B means A ⊆ B and B ⊆ A
- Power Set: P(A) is the set of all subsets of A
Let A = {1, 2, 3}
- |A| = 3 (A has 3 elements)
- {1, 2} ⊂ A (proper subset)
- A ⊆ A (subset, but not proper)
- P(A) = {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}
- |P(A)| = 2³ = 8
2.2 Set Operations
Set operations allow us to combine sets to create new sets.
Operation | Symbol | Definition |
---|---|---|
Union | A ∪ B | {x | x ∈ A or x ∈ B} |
Intersection | A ∩ B | {x | x ∈ A and x ∈ B} |
Difference | A - B | {x | x ∈ A and x ∉ B} |
Complement | A' | {x ∈ U | x ∉ A} |
Symmetric Difference | A △ B | (A - B) ∪ (B - A) |
Cartesian Product | A × B | {(a, b) | a ∈ A and b ∈ B} |
Let A = {1, 2, 3, 4}, B = {3, 4, 5, 6}, and U = {1, 2, 3, 4, 5, 6, 7, 8, 9}
- A ∪ B = {1, 2, 3, 4, 5, 6}
- A ∩ B = {3, 4}
- A - B = {1, 2}
- B - A = {5, 6}
- A' = {5, 6, 7, 8, 9}
- A △ B = {1, 2, 5, 6}
For A = {a, b} and B = {1, 2, 3}:
A × B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3)}
B × A = {(1, a), (1, b), (2, a), (2, b), (3, a), (3, b)}
Note that A × B ≠ B × A unless A = B.
|A × B| = |A| × |B| = 2 × 3 = 6
2.3 Set Identities
Set identities are statements that assert the equality of two sets or set expressions.
Law | Identity |
---|---|
Identity Laws | A ∪ ∅ = A A ∩ U = A |
Domination Laws | A ∪ U = U A ∩ ∅ = ∅ |
Idempotent Laws | A ∪ A = A A ∩ A = A |
Complementation Laws | A ∪ A' = U A ∩ A' = ∅ (A')' = A |
Commutative Laws | A ∪ B = B ∪ A A ∩ B = B ∩ A |
Associative Laws | (A ∪ B) ∪ C = A ∪ (B ∪ C) (A ∩ B) ∩ C = A ∩ (B ∩ C) |
Distributive Laws | A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) |
De Morgan's Laws | (A ∪ B)' = A' ∩ B' (A ∩ B)' = A' ∪ B' |
Absorption Laws | A ∪ (A ∩ B) = A A ∩ (A ∪ B) = A |
Example: Prove that A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
We need to show that every element in the left-hand side is also in the right-hand side, and vice versa.
Part 1: Show x ∈ A ∪ (B ∩ C) → x ∈ (A ∪ B) ∩ (A ∪ C)
If x ∈ A ∪ (B ∩ C), then either x ∈ A or x ∈ B ∩ C.
- If x ∈ A, then x ∈ A ∪ B and x ∈ A ∪ C, so x ∈ (A ∪ B) ∩ (A ∪ C).
- If x ∈ B ∩ C, then x ∈ B and x ∈ C, which means x ∈ A ∪ B and x ∈ A ∪ C, so x ∈ (A ∪ B) ∩ (A ∪ C).
Part 2: Show x ∈ (A ∪ B) ∩ (A ∪ C) → x ∈ A ∪ (B ∩ C)
If x ∈ (A ∪ B) ∩ (A ∪ C), then x ∈ A ∪ B and x ∈ A ∪ C.
There are three cases to consider:
- If x ∈ A, then x ∈ A ∪ (B ∩ C).
- If x ∉ A but x ∈ B and x ∈ C, then x ∈ B ∩ C, so x ∈ A ∪ (B ∩ C).
- If x ∉ A and either x ∉ B or x ∉ C, then x cannot be in both A ∪ B and A ∪ C, which contradicts our assumption.
Therefore, A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C).
2.4 Venn Diagrams
Venn diagrams visually represent sets and set operations using overlapping circles within a rectangle (representing the universal set).
A basic Venn diagram with two sets A and B. The universal set U is represented by the rectangle surrounding the circles.
The union A ∪ B consists of all elements in either A or B (or both). It's represented by the entire shaded area.
The intersection A ∩ B consists of all elements that are in both A and B. It's represented by the overlapping region (purple).
The difference A - B consists of elements in A that are not in B. It's represented by the blue region (A) minus the overlapping region.
The complement A' consists of all elements in the universal set U that are not in A. It's represented by the green area outside the circle A.
Three-Set Venn Diagrams
For three sets, the Venn diagram becomes more complex with 8 distinct regions:
- Elements in A only
- Elements in B only
- Elements in C only
- Elements in A and B, but not C
- Elements in A and C, but not B
- Elements in B and C, but not A
- Elements in A, B, and C
- Elements in none of A, B, or C (but in U)
This allows us to visualize complex set operations like (A ∩ B) ∪ (B ∩ C) ∪ (A ∩ C).
2.5 Cartesian Product
The Cartesian product of two sets A and B, denoted A × B, is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B.
Let A = {1, 2} and B = {a, b, c}
A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
B × A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}
Properties of Cartesian Product
- |A × B| = |A| · |B|
- A × B ≠ B × A (unless A = B or either A or B is empty)
- A × (B ∪ C) = (A × B) ∪ (A × C)
- A × (B ∩ C) = (A × B) ∩ (A × C)
- If A = ∅ or B = ∅, then A × B = ∅
3. Relations and Functions
3.1 Relations
A relation R from set A to set B is a subset of the Cartesian product A × B. It consists of ordered pairs (a, b) where a ∈ A and b ∈ B.
Let A = {1, 2, 3} and B = {a, b, c}
A possible relation R from A to B could be:
R = {(1, a), (1, c), (2, b), (3, c)}
This relation associates 1 with both a and c, 2 with b, and 3 with c.
Relations on a Set
A relation on a set A is a relation from A to itself, i.e., a subset of A × A.
Properties of Relations
A relation R on a set A can have the following properties:
Property | Definition |
---|---|
Reflexive | (a, a) ∈ R for all a ∈ A |
Symmetric | If (a, b) ∈ R, then (b, a) ∈ R |
Antisymmetric | If (a, b) ∈ R and (b, a) ∈ R, then a = b |
Transitive | If (a, b) ∈ R and (b, c) ∈ R, then (a, c) ∈ R |
Example: Let's examine the "less than or equal to" relation (≤) on the set of integers:
- Reflexive? Yes, because a ≤ a for all integers a.
- Symmetric? No, because 3 ≤ 5 but 5 ≰ 3.
- Antisymmetric? Yes, because if a ≤ b and b ≤ a, then a = b.
- Transitive? Yes, because if a ≤ b and b ≤ c, then a ≤ c.
Equivalence Relations
A relation that is reflexive, symmetric, and transitive is called an equivalence relation.
Equivalence relations partition a set into disjoint subsets called equivalence classes.
The "congruence modulo n" relation on integers: a ≡ b (mod n) if a and b have the same remainder when divided by n.
For example, with mod 3, the equivalence classes are:
- [0] = {..., -3, 0, 3, 6, ...}
- [1] = {..., -2, 1, 4, 7, ...}
- [2] = {..., -1, 2, 5, 8, ...}
Partial Order Relations
A relation that is reflexive, antisymmetric, and transitive is called a partial order relation.
- ≤ on real numbers
- ⊆ on sets (subset relation)
- | on integers (divisibility relation: a | b if a divides b)
3.2 Functions
A function f from set A to set B, denoted f: A → B, is a relation from A to B where each element in A is related to exactly one element in B.
Function Terminology
- Domain: The set A of input values
- Codomain: The set B of possible output values
- Range: The set of actual output values {f(a) | a ∈ A}
- Image: For a ∈ A, f(a) is the image of a under f
- Preimage: For b ∈ B, the set {a ∈ A | f(a) = b} is the preimage of b
Types of Functions
Type | Definition |
---|---|
Injective (One-to-One) | ∀a₁, a₂ ∈ A, if a₁ ≠ a₂, then f(a₁) ≠ f(a₂) |
Surjective (Onto) | ∀b ∈ B, ∃a ∈ A such that f(a) = b |
Bijective | Both injective and surjective |
Let A = {1, 2, 3} and B = {a, b, c, d}
- f₁ = {(1, a), (2, b), (3, c)} is injective but not surjective (d is not in the range)
- f₂ = {(1, a), (2, a), (3, b)} is not injective (1 and 2 map to the same element) and not surjective
- If B = {a, b, c}, then f₃ = {(1, a), (2, b), (3, c)} is bijective
Function Composition
Given functions f: A → B and g: B → C, the composition of g and f, denoted g ∘ f: A → C, is defined as:
(g ∘ f)(a) = g(f(a)) for all a ∈ A
Example:
Let f(x) = x² and g(x) = x + 3
(g ∘ f)(x) = g(f(x)) = g(x²) = x² + 3
(f ∘ g)(x) = f(g(x)) = f(x + 3) = (x + 3)²
Note that function composition is not commutative: g ∘ f ≠ f ∘ g in general.
Inverse Functions
If f: A → B is a bijective function, then there exists an inverse function f⁻¹: B → A such that:
- f⁻¹(f(a)) = a for all a ∈ A
- f(f⁻¹(b)) = b for all b ∈ B
Example:
Let f(x) = 2x + 3
To find f⁻¹, solve for x:
y = 2x + 3
x = (y - 3)/2
Therefore, f⁻¹(y) = (y - 3)/2
We can verify that:
f⁻¹(f(x)) = f⁻¹(2x + 3) = ((2x + 3) - 3)/2 = x
f(f⁻¹(y)) = f((y - 3)/2) = 2((y - 3)/2) + 3 = y - 3 + 3 = y
4. Quizzes and Practice Problems
Propositional Logic Quiz
The given statement is p → q, where p is "it rains" and q is "the ground gets wet".
The negation of p → q is ¬(p → q).
Using the equivalence p → q ≡ ¬p ∨ q, we get:
¬(p → q) ≡ ¬(¬p ∨ q) ≡ ¬¬p ∧ ¬q ≡ p ∧ ¬q
Therefore, the negation is "It rains and the ground doesn't get wet."
Let's simplify p → (q → r):
- p → (q → r)
- p → (¬q ∨ r) [Using the equivalence q → r ≡ ¬q ∨ r]
- ¬p ∨ (¬q ∨ r) [Using the equivalence p → s ≡ ¬p ∨ s]
- (¬p ∨ ¬q) ∨ r [Associative law of disjunction]
- ¬(p ∧ q) ∨ r [Using De Morgan's law]
- (p ∧ q) → r [Using the equivalence ¬s ∨ t ≡ s → t]
Therefore, p → (q → r) is logically equivalent to (p ∧ q) → r.
If I study, I will pass the exam.
If I pass the exam, I will graduate.
I did not graduate.
Therefore, I did not study.
Let's symbolize the statements:
- p: I study
- q: I pass the exam
- r: I graduate
The premises are:
- p → q (If I study, I will pass the exam)
- q → r (If I pass the exam, I will graduate)
- ¬r (I did not graduate)
The conclusion is: ¬p (I did not study)
Let's check if the conclusion follows from the premises:
- From premises 1 and 2, we can derive p → r using the hypothetical syllogism.
- From p → r and ¬r, we can derive ¬p using modus tollens.
Therefore, the argument is valid.
Set Theory Quiz
Step 1: Find A ∪ B
A ∪ B = {1, 2, 3, 4} ∪ {3, 4, 5, 6} = {1, 2, 3, 4, 5, 6}
Step 2: Find (A ∪ B) ∩ C
(A ∪ B) ∩ C = {1, 2, 3, 4, 5, 6} ∩ {2, 4, 6, 8} = {2, 4, 6}
Therefore, (A ∪ B) ∩ C = {2, 4, 6}
Wait, I made a mistake. Let me verify again:
A = {1, 2, 3, 4}
B = {3, 4, 5, 6}
C = {2, 4, 6, 8}
A ∪ B = {1, 2, 3, 4, 5, 6}
(A ∪ B) ∩ C = {1, 2, 3, 4, 5, 6} ∩ {2, 4, 6, 8} = {2, 4, 6}
The correct answer is {2, 4, 6}.
Step 1: Find B'
B' = {1, 3, 5, 7, 9} (all elements in U that are not in B)
Step 2: Find A ∩ B'
A ∩ B' = {1, 3, 5, 7, 9} ∩ {1, 3, 5, 7, 9} = {1, 3, 5, 7, 9}
Step 3: Find (A ∩ B')'
(A ∩ B')' = {1, 3, 5, 7, 9}' = {2, 4, 6, 8, 10}
Therefore, (A ∩ B')' = {2, 4, 6, 8, 10}
Alternatively, we can use set identities:
(A ∩ B')' = A' ∪ (B')' = A' ∪ B [Using De Morgan's law and double negation]
A' = {2, 4, 6, 8, 10}
A' ∪ B = {2, 4, 6, 8, 10} ∪ {2, 4, 6, 8, 10} = {2, 4, 6, 8, 10}
For a set with n elements, the number of distinct subsets is 2^n.
Since A has 3 elements, it has 2^3 = 8 distinct subsets:
- ∅ (the empty set)
- {a}
- {b}
- {c}
- {a, b}
- {a, c}
- {b, c}
- {a, b, c}
Therefore, A has 8 distinct subsets.