Discrete Mathematics – Complete Study Notes
Logic • Proofs • Set Theory • Abstract Algebra • Advanced Counting
Unit 1 – Logic and its Applications
Foundation of mathematical reasoning and digital circuits.
1.1 Propositional Logic
A proposition is a declarative statement that is either true (T) or false (F)—never both. Propositional logic studies how propositions combine to form compound statements.
A statement with a definite truth value. Examples:
✔ "2 + 2 = 4" (T) ✔ "Paris is in Germany" (F)
✘ "What time is it?" (question — not a proposition)
✘ "x > 5" (open sentence, truth depends on x)
Logical Connectives
| Symbol | Name | Meaning | True when … |
|---|---|---|---|
| ¬p | Negation (NOT) | not p | p is F |
| p ∧ q | Conjunction (AND) | p and q | both T |
| p ∨ q | Disjunction (OR) | p or q | at least one T |
| p → q | Implication | if p then q | p is F, or both T |
| p ↔ q | Biconditional | p if and only if q | same truth value |
| p ⊕ q | XOR (Exclusive OR) | p exclusive or q | exactly one T |
Truth Table for Implication (→)
The implication p → q is false only when p is true and q is false. In all other cases it is true. Think of it as a promise: the promise is only broken when you do the condition but not the result.
| p | q | p→q | ¬p∨q (equivalent form) |
|---|---|---|---|
| T | T | T | T |
| T | F | F | F |
| F | T | T | T |
| F | F | T | T |
Key Terminology
- Tautology: Always true for all inputs. E.g., p ∨ ¬p (Law of Excluded Middle).
- Contradiction: Always false. E.g., p ∧ ¬p.
- Contingency: Sometimes true, sometimes false. E.g., p ∧ q.
Important Logical Equivalences
| Law | Equivalence |
|---|---|
| Double Negation | ¬(¬p) ≡ p |
| De Morgan's (AND) | ¬(p ∧ q) ≡ ¬p ∨ ¬q |
| De Morgan's (OR) | ¬(p ∨ q) ≡ ¬p ∧ ¬q |
| Implication Rewrite | p → q ≡ ¬p ∨ q |
| Contrapositive | p → q ≡ ¬q → ¬p |
| Absorption | p ∨ (p ∧ q) ≡ p |
| Distributive | p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) |
1.1a Logical Equivalences of Conditional & Biconditional Statements
Equivalences of p → q (Conditional / Implication)
The conditional p → q has several important equivalent and non-equivalent forms. Knowing which are equivalent and which are not is a key B.Tech exam skill.
| Form | Expression | Equivalent to p→q? | Explanation |
|---|---|---|---|
| Original | p → q | — | Base implication |
| Contrapositive | ¬q → ¬p | YES ✓ | Flip and negate both — always equivalent |
| Converse | q → p | NO ✗ | Just flip — NOT equivalent |
| Inverse | ¬p → ¬q | NO ✗ | Just negate both — NOT equivalent (≡ converse) |
| OR form | ¬p ∨ q | YES ✓ | Standard rewrite |
| NAND form | ¬(p ∧ ¬q) | YES ✓ | Negation of "p and not q" |
| Exportation | (p ∧ q) → r ≡ p → (q → r) | YES ✓ | Used in proofs to "export" a premise |
Equivalence pairs to memorise:
- p→q ≡ Contrapositive (¬q→¬p) — always safe to swap
- Converse ≡ Inverse — but both are NOT equal to the original
- p→q ≡ ¬p∨q — most useful algebraic rewrite
- p→q ≡ ¬(p∧¬q) — useful in CNF/circuit design
| p | q | p→q (original) | q→p (converse) | ¬p→¬q (inverse) | ¬q→¬p (contrapositive) |
|---|---|---|---|---|---|
| T | T | T | T | T | T |
| T | F | F | T | T | F |
| F | T | T | F | F | T |
| F | F | T | T | T | T |
Columns 3 and 6 are identical → p→q ≡ contrapositive ✓
Columns 4 and 5 are identical → converse ≡ inverse ✓ (but both differ from column 3)
Equivalences of p ↔ q (Biconditional)
The biconditional p ↔ q ("p if and only if q") is true exactly when p and q have the same truth value. It has several useful equivalent forms.
| Equivalent Form | Expression | Why |
|---|---|---|
| Both-implications | (p→q) ∧ (q→p) | Definition: "if and only if" = both directions hold |
| Same-value cases | (p∧q) ∨ (¬p∧¬q) | True when both T or both F |
| Double OR form | (¬p∨q) ∧ (¬q∨p) | Expand each implication as ¬p∨q |
| Negated complement | ¬p ↔ ¬q | Negating both sides preserves biconditional |
| Negation (XOR) | ¬(p↔q) ≡ p⊕q | True when p and q differ — exclusive OR |
| p | q | p↔q | p∧q | ¬p∧¬q | (p∧q)∨(¬p∧¬q) |
|---|---|---|---|---|---|
| T | T | T | T | F | T |
| T | F | F | F | F | F |
| F | T | F | F | F | F |
| F | F | T | F | T | T |
Columns 3 and 6 match ✓
Q1. For the statement "If you study hard, you will pass", write the (a) converse (b) inverse (c) contrapositive. Which are equivalent?
Let p = "you study hard", q = "you will pass".
(a) Converse: q→p = "If you pass, you studied hard." (NOT equivalent)
(b) Inverse: ¬p→¬q = "If you do not study hard, you will not pass." (NOT equivalent; ≡ converse)
(c) Contrapositive: ¬q→¬p = "If you do not pass, you did not study hard." (EQUIVALENT to original)
Q2. Show that p↔q ≡ (p→q) ∧ (q→p) using a truth table.
| p | q | p↔q | p→q | q→p | (p→q)∧(q→p) |
|---|---|---|---|---|---|
| T | T | T | T | T | T |
| T | F | F | F | T | F |
| F | T | F | T | F | F |
| F | F | T | T | T | T |
Columns 3 and 6 are identical. ✓ Proved.
Q3. Is the converse of a true conditional always true? Give an example.
No. A true conditional does NOT guarantee a true converse.
Example: p→q = "If a number is divisible by 4, it is divisible by 2." TRUE.
Converse q→p = "If a number is divisible by 2, it is divisible by 4." FALSE (e.g., 6 is divisible by 2 but not 4).
Q4. Rewrite p→q using only ∧ and ¬ (no ∨ or →).
p→q ≡ ¬p∨q [standard rewrite]
¬p∨q ≡ ¬(p∧¬q) [De Morgan's: ¬(A∧B) = ¬A∨¬B, reversed]
Answer: p→q ≡ ¬(p ∧ ¬q)
1.1b Satisfiability and the Sudoku Puzzle
Satisfiability
A propositional formula φ is:
- Satisfiable: There exists at least one truth assignment that makes φ = T. (Could be tautology or contingency.)
- Unsatisfiable (Contradiction): Every truth assignment makes φ = F. No satisfying assignment exists.
- Valid (Tautology): Every truth assignment makes φ = T. (A special case of satisfiable.)
Quick check: φ is unsatisfiable ↔ ¬φ is a tautology.
The Boolean Satisfiability Problem (SAT): given a propositional formula in CNF, decide if it is satisfiable.
- First problem proved to be NP-complete (Cook-Levin Theorem, 1971).
- No known polynomial-time algorithm. Best worst-case: exponential (2ⁿ assignments to check).
- Practical SAT solvers (DPLL, CDCL) can handle millions of variables in real applications.
- If you can solve SAT in polynomial time → P = NP (the most famous open problem in CS).
| Formula | Satisfiable? | Tautology? | Reason |
|---|---|---|---|
| p ∨ ¬p | Yes | Yes | Always true (excluded middle) |
| p ∧ ¬p | No | No | Always false (contradiction) |
| p ∧ q | Yes (p=T,q=T) | No | True for one assignment only |
| (p→q) ∧ p ∧ ¬q | No | No | p,¬q makes p→q false; contradiction |
Sudoku as a Satisfiability Problem
A standard 9×9 Sudoku. Each row, column, and bold 3×3 box must contain digits 1–9 exactly once. Pre-filled cells are the given clues.
| 5 | 3 | · | · | 7 | · | · | · | · |
| 6 | · | · | 1 | 9 | 5 | · | · | · |
| · | 9 | 8 | · | · | · | · | 6 | · |
| 8 | · | · | · | 6 | · | · | · | 3 |
| 4 | · | · | 8 | · | 3 | · | · | 1 |
| 7 | · | · | · | 2 | · | · | · | 6 |
| · | 6 | · | · | · | · | 2 | 8 | · |
| · | · | · | 4 | 1 | 9 | · | · | 5 |
| · | · | · | · | 8 | · | · | 7 | 9 |
SAT Encoding
Each cell (i,j) and digit k is a Boolean variable:
p(i,j,k) = 1 if cell (i,j) holds digit k
Example: the blue cell at row 1, col 1 (value=5) gives the unit clause:
p(1,1,5) = TRUE
Total: 9×9×9 = 729 variables
Constraints as clauses:
At-least-one per cell, at-most-one per cell, row/col/box uniqueness = thousands of clauses
A SAT solver finds a satisfying assignment = the completed puzzle.
Every Sudoku puzzle can be converted into a SAT problem and solved by a SAT solver. This shows how logic is applied in practice.
Variables: p(i, j, k) = "cell in row i, column j contains digit k" (i,j,k ∈ {1,…,9})
Total variables: 9 × 9 × 9 = 729 Boolean variables
Constraints (encoded as clauses):
- Each cell has at least one digit: p(i,j,1) ∨ p(i,j,2) ∨ … ∨ p(i,j,9) for all i,j
- Each cell has at most one digit: ¬p(i,j,k) ∨ ¬p(i,j,l) for all k≠l
- Each digit appears once per row: ¬p(i,j,k) ∨ ¬p(i,j',k) for all j≠j'
- Each digit appears once per column and box: similar clauses
- Given clues: directly set p(i,j,k) = T for the pre-filled cells
A SAT solver (e.g., MiniSAT) finds a satisfying assignment → the solution to the puzzle, in milliseconds.
Q1. Is (p ∨ q) ∧ (¬p ∨ r) ∧ (¬q ∨ ¬r) satisfiable?
Try p=T, q=F, r=T:
(T∨F) ∧ (F∨T) ∧ (T∨F) = T ∧ T ∧ T = T ✓
Yes, satisfiable. Assignment: p=T, q=F, r=T satisfies all three clauses.
Q2. Is (p ∨ q) ∧ ¬p ∧ ¬q satisfiable?
From ¬p and ¬q: p=F, q=F.
Then p∨q = F∨F = F. So (p∨q)∧¬p∧¬q = F.
No other assignments are possible since ¬p and ¬q force p=F, q=F.
No, unsatisfiable (contradiction).
Q3. How many truth assignments satisfy p ↔ q when there are 2 variables?
p↔q is true when p and q have the same value.
Satisfying assignments: (T,T) and (F,F) — exactly 2 out of 4.
Answer: 2 satisfying assignments.
Build a truth table and verify column p→q equals column ¬p∨q:
| p | q | ¬p | p→q | ¬p∨q |
|---|---|---|---|---|
| T | T | F | T | T |
| T | F | F | F | F |
| F | T | T | T | T |
| F | F | T | T | T |
Columns 4 and 5 are identical → equivalence confirmed ✓
Q1. Is (p ∨ q) ∧ ¬p → q a tautology?
Solution: We need: whenever (p∨q)∧¬p is T, q must also be T.
(p∨q)∧¬p is T only when p=F and q=T (¬p=T requires p=F; p∨q=T requires q=T when p=F).
In that case q=T, so the implication holds. In all other cases the hypothesis is F → implication is automatically T.
Yes, it is a tautology (this is Disjunctive Syllogism).
Q2. Write the contrapositive of: "If it rains, then the ground is wet."
Let p = "It rains", q = "The ground is wet". Original: p → q.
Contrapositive: ¬q → ¬p.
Answer: "If the ground is not wet, then it did not rain."
The contrapositive is logically equivalent to the original.
Q3. Simplify ¬(p → q).
p → q ≡ ¬p ∨ q
¬(p → q) ≡ ¬(¬p ∨ q) ≡ p ∧ ¬q [De Morgan's]
Answer: p ∧ ¬q (p is true AND q is false — the only case when an implication fails).
Q4. Is (p ∧ q) → p always true?
If p∧q is T → both p and q are T → p is T → implication is T.
If p∧q is F → false antecedent → implication is T.
Yes, it is a tautology (Simplification rule of inference).
1.2 Predicate Logic & Quantifiers
Propositional logic cannot express statements like "All students passed." Predicate logic adds predicates (properties) and quantifiers (all, some) to express such statements.
A predicate P(x) is a statement containing a variable x. It becomes a proposition when x is assigned a specific value.
Example: P(x) = "x > 5". P(10) is T, P(3) is F.
Universal and Existential Quantifiers
| Quantifier | Symbol | Meaning | False when … |
|---|---|---|---|
| Universal | ∀x P(x) | "For all x, P(x)" | At least one x makes P(x) false |
| Existential | ∃x P(x) | "There exists x such that P(x)" | No x makes P(x) true |
Negation of Quantifiers (De Morgan's for Quantifiers)
¬(∀x P(x)) ≡ ∃x ¬P(x)
¬(∃x P(x)) ≡ ∀x ¬P(x)
Intuition: "Not all students passed" ≡ "Some student did not pass."
Nested Quantifiers — Order Matters!
| Statement | Meaning |
|---|---|
| ∀x ∃y P(x,y) | For every x, there is some y that works (y may depend on x) |
| ∃y ∀x P(x,y) | One single y works for all x (much stronger!) |
Domain: real numbers. P(x,y) = "x + y = 0"
∀x ∃y P(x,y) → TRUE (for any x, choose y = −x)
∃y ∀x P(x,y) → FALSE (no single y satisfies x + y = 0 for all x)
Q1. Negate: "Every student has a laptop."
Let L(x) = "x has a laptop", domain = students.
Original: ∀x L(x). Negation: ¬(∀x L(x)) ≡ ∃x ¬L(x).
Answer: "There exists a student who does not have a laptop."
Q2. Express "Some birds cannot fly" using predicates.
Let B(x) = "x is a bird", F(x) = "x can fly".
Answer: ∃x (B(x) ∧ ¬F(x))
Important: Use ∧ (not →) with ∃. Writing ∃x (B(x) → ¬F(x)) would be true even if there are no birds, which is wrong!
Q3. Negate: ∀x ∀y (x ≠ y → P(x,y))
¬(∀x ∀y (x≠y → P(x,y)))
≡ ∃x ∃y ¬(x≠y → P(x,y))
≡ ∃x ∃y (x≠y ∧ ¬P(x,y)) [since ¬(A→B) ≡ A∧¬B]
Answer: "There exist two distinct elements for which P(x,y) does not hold."
1.3 Boolean Algebra & Computer Architecture Applications
Boolean Algebra is the mathematical foundation of digital circuits. Variables take values 0 (false) or 1 (true). The three basic operations are AND (·), OR (+), NOT (').
Boolean Laws
| Law | AND form | OR form |
|---|---|---|
| Identity | A · 1 = A | A + 0 = A |
| Null/Domination | A · 0 = 0 | A + 1 = 1 |
| Idempotent | A · A = A | A + A = A |
| Complement | A · A' = 0 | A + A' = 1 |
| De Morgan's | (A·B)' = A'+B' | (A+B)' = A'·B' |
| Absorption | A·(A+B) = A | A + A·B = A |
Logic Gates
Logic gates are the physical building blocks of digital circuits. Each gate implements a Boolean operation. Below are the standard IEEE symbols, truth tables, and key properties.
| Gate | Operation | Output 1 when … | Universal Gate? |
|---|---|---|---|
| AND | A · B | All inputs are 1 | No |
| OR | A + B | At least one input is 1 | No |
| NOT | A' | Input is 0 | No |
| NAND | (A·B)' | Not all inputs are 1 | Yes |
| NOR | (A+B)' | All inputs are 0 | Yes |
| XOR | A ⊕ B | Exactly one input is 1 | No |
AND Gate
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
OR Gate
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
NOT Gate (Inverter)
| A | Y |
|---|---|
| 0 | 1 |
| 1 | 0 |
NAND Gate ★ Universal
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NOR Gate ★ Universal
| A | B | Y |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |
XOR Gate
| A | B | Y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NAND and NOR are called universal gates because ANY Boolean function (AND, OR, NOT, XOR, …) can be built using only NAND gates (or only NOR gates). This is important in chip manufacturing — you only need one type of gate to build an entire CPU.
NOT using NAND: A' = NAND(A, A)
AND using NAND: A·B = NAND(NAND(A,B), NAND(A,B))
OR using NAND: A+B = NAND(NAND(A,A), NAND(B,B))
1.3a Boolean Functions, Literals, Minterms, Maxterms, DNF & CNF
Boolean Function
A Boolean function of n variables is a mapping f : {0,1}ⁿ → {0,1}.
- n variables → 2ⁿ possible input combinations (rows in truth table)
- Each row can independently output 0 or 1 → 2^(2ⁿ) possible distinct Boolean functions
| n (variables) | Input combinations (2ⁿ) | Distinct functions (2^(2ⁿ)) |
|---|---|---|
| 1 | 2 | 4 |
| 2 | 4 | 16 |
| 3 | 8 | 256 |
Literal
A literal is a variable or the complement of a variable.
For variable x: literals are x (positive literal) and x' or ¬x (negative literal).
Example: In expression AB' + A'C, the literals are A, B', A', C.
Elementary Product & Elementary Sum
Elementary Product (Fundamental Product): AND of one or more literals, where no variable appears more than once.
Examples: A, AB', A'BC, x'yz
Elementary Sum (Fundamental Sum): OR of one or more literals, where no variable appears more than once.
Examples: A, A+B', A'+B+C'
Minterm
A minterm of n variables is an elementary product in which every variable appears exactly once (either complemented or not).
- For n variables: there are exactly 2ⁿ minterms, labelled m₀, m₁, …, m_{2ⁿ-1}
- Minterm mᵢ evaluates to 1 only for the input combination whose binary value equals i; it is 0 for all other inputs
Minterms for 2 variables (A, B):
| Row i | A | B | Minterm mᵢ | Expression |
|---|---|---|---|---|
| 0 | 0 | 0 | m₀ | A'B' |
| 1 | 0 | 1 | m₁ | A'B |
| 2 | 1 | 0 | m₂ | AB' |
| 3 | 1 | 1 | m₃ | AB |
Rule: For minterm mᵢ, write each variable complemented if its bit in i is 0, and uncomplemented if the bit is 1.
Maxterm
A maxterm of n variables is an elementary sum in which every variable appears exactly once.
- Maxterm Mᵢ evaluates to 0 only for the input combination whose binary value equals i; it is 1 for all others
- Key relationship: Mᵢ = (mᵢ)' — maxterm is the complement of the corresponding minterm
Maxterms for 2 variables:
| Row i | A | B | Maxterm Mᵢ | Expression |
|---|---|---|---|---|
| 0 | 0 | 0 | M₀ | A+B |
| 1 | 0 | 1 | M₁ | A+B' |
| 2 | 1 | 0 | M₂ | A'+B |
| 3 | 1 | 1 | M₃ | A'+B' |
Rule: For maxterm Mᵢ, write each variable uncomplemented if its bit in i is 0, and complemented if the bit is 1 — opposite of minterm.
Disjunctive Normal Form (DNF) — Sum of Products (SOP)
DNF (Canonical DNF) = OR of all minterms for which the function outputs 1.
Written: f = Σm(list of row indices where f=1)
Steps to find DNF from a truth table:
- Write out the truth table for f
- Identify every row where f = 1
- Write the minterm for each such row
- OR all those minterms together
Every Boolean function has a unique canonical DNF.
Conjunctive Normal Form (CNF) — Product of Sums (POS)
CNF (Canonical CNF) = AND of all maxterms for which the function outputs 0.
Written: f = ΠM(list of row indices where f=0)
Steps to find CNF:
- Write out the truth table for f
- Identify every row where f = 0
- Write the maxterm for each such row
- AND all those maxterms together
Every Boolean function has a unique canonical CNF.
| Row | A | B | f=A+B | Minterm | Maxterm |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | m₀=A'B' | M₀=A+B |
| 1 | 0 | 1 | 1 | m₁=A'B | M₁=A+B' |
| 2 | 1 | 0 | 1 | m₂=AB' | M₂=A'+B |
| 3 | 1 | 1 | 1 | m₃=AB | M₃=A'+B' |
DNF: f = Σm(1,2,3) = A'B + AB' + AB
CNF: f = ΠM(0) = (A+B)
Both simplify to A+B — consistent! ✓
Q1. Find the canonical DNF and CNF for f(A,B) where f=1 only when A=1,B=0.
| A | B | f |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
DNF: f = 1 only at row 2 (A=1,B=0). Minterm m₂ = AB'.
f = Σm(2) = AB'
CNF: f = 0 at rows 0,1,3. Maxterms: M₀=A+B, M₁=A+B', M₃=A'+B'.
f = ΠM(0,1,3) = (A+B)(A+B')(A'+B')
Q2. Express f(A,B,C) = Σm(1,4,5,7) as a product of maxterms (CNF).
DNF uses minterms at rows 1,4,5,7. So CNF uses maxterms at ALL OTHER rows: 0,2,3,6.
Rows where f=0: 0,2,3,6.
Maxterms (3 variables A,B,C):
M₀ = A+B+C (row 000)
M₂ = A+B'+C (row 010)
M₃ = A+B'+C' (row 011)
M₆ = A'+B+C' (row 110)
f = ΠM(0,2,3,6) = (A+B+C)(A+B'+C)(A+B'+C')(A'+B+C')
Q3. How many minterms and maxterms exist for a 3-variable Boolean function?
For n=3 variables (A,B,C): 2³ = 8 minterms (m₀ to m₇) and 8 maxterms (M₀ to M₇).
And there are 2^8 = 256 possible distinct Boolean functions of 3 variables.
1.3b Karnaugh Map (K-map)
A Karnaugh Map (K-map) is a graphical method to simplify Boolean expressions without algebraic manipulation. It works by visually grouping adjacent minterms whose combined expression simplifies.
- Cells are arranged in Gray code order so adjacent cells differ by exactly 1 bit
- Group 1s in rectangles of size 1, 2, 4, 8, … (must be powers of 2) → gives simplified DNF
- Group 0s similarly → gives simplified CNF
- Groups must be rectangular (or wrap around edges — K-map is a torus)
- Make groups as large as possible; use fewest groups possible
- Each group of 2ᵏ cells eliminates k variables from the term
- A cell can belong to multiple groups
K-map Layout for 2 Variables
B=0 B=1
A=0 [ m₀ | m₁ ]
A=1 [ m₂ | m₃ ]
Adjacent cells (differ by 1 bit): m₀↔m₁, m₀↔m₂, m₁↔m₃, m₂↔m₃, and wrap-around edges.
K-map for 3 Variables
One variable on rows (A), two variables on columns (BC) in Gray code order: 00, 01, 11, 10
BC=00 BC=01 BC=11 BC=10
A=0 [ m₀ | m₁ | m₃ | m₂ ]
A=1 [ m₄ | m₅ | m₇ | m₆ ]
Note: The columns are NOT in binary order — they use Gray code (00,01,11,10) so adjacent columns always differ by 1 bit. This is essential for the method to work correctly.
Step 1: Fill in the K-map
BC=00 BC=01 BC=11 BC=10
A=0 [ 1 | 1 | 1 | 0 ] ← m₀=1, m₁=1, m₃=1, m₂=0
A=1 [ 0 | 0 | 1 | 0 ] ← m₄=0, m₅=0, m₇=1, m₆=0
Step 2: Identify groups of 1s
- Group 1 (size 2): m₀, m₁ → A=0, BC=00 and BC=01 → A is fixed at 0, C varies, B=0 → A'B'
- Group 2 (size 2): m₁, m₃ → A=0, BC=01 and BC=11 → A=0, B varies, C=1 → A'C
- Group 3 (size 2): m₃, m₇ → BC=11, A varies → B=1, C=1 → BC
Step 3: OR all groups together
f = A'B' + A'C + BC
Compare to the raw DNF: m₀+m₁+m₃+m₇ = A'B'C' + A'B'C + A'BC + ABC — much longer! K-map gives the minimal form. ✓
| Group Size | Variables Eliminated | Variables Remaining in Term |
|---|---|---|
| 1 (single cell) | 0 | All n (full minterm) |
| 2 cells | 1 | n−1 |
| 4 cells | 2 | n−2 |
| 8 cells (all in 3-var map) | 3 | 0 → f = 1 (tautology) |
Q1. Use a 3-variable K-map to simplify f(A,B,C) = Σm(0,2,4,6).
Fill K-map:
BC=00 BC=01 BC=11 BC=10
A=0 [ 1 | 0 | 0 | 1 ] m₀=1, m₁=0, m₃=0, m₂=1
A=1 [ 1 | 0 | 0 | 1 ] m₄=1, m₅=0, m₇=0, m₆=1
Group all four 1s: m₀,m₂,m₄,m₆ — these are BC=00 and BC=10 columns, both rows.
In these cells: A varies (0,1), B varies (0,1), C = 0 always.
The common factor: C' (C=0)
f = C' — the function is simply 1 whenever C=0.
Q2. Simplify f(A,B,C) = Σm(1,3,5,7) using K-map.
BC=00 BC=01 BC=11 BC=10
A=0 [ 0 | 1 | 1 | 0 ] m₁=1, m₃=1
A=1 [ 0 | 1 | 1 | 0 ] m₅=1, m₇=1
Group all four 1s: m₁,m₃,m₅,m₇ — BC=01 and BC=11 columns, both rows.
In all these cells: C=1 always. A and B vary.
f = C — true whenever C=1.
Q3. Find the simplified DNF for f(A,B,C) = Σm(0,1,2,3,6).
BC=00 BC=01 BC=11 BC=10
A=0 [ 1 | 1 | 1 | 1 ] m₀,m₁,m₃,m₂ = all 1
A=1 [ 1 | 0 | 0 | 1 ] m₄=1, m₅=0, m₇=0, m₆=1
Group 1 (size 4): Entire A=0 row → m₀,m₁,m₂,m₃ → A=0 → term: A'
Group 2 (size 2): m₀,m₄ (BC=00 column) → B=0,C=0 → term: B'C'
Group 3 (size 2): m₂,m₆ (BC=10 column) → B=1,C=0 → term: BC'
Note: m₀ is covered by both Group 1 and 2 (allowed). m₂ covered by both Group 1 and 3.
f = A' + B'C' + BC'
This can further simplify: B'C' + BC' = C'(B'+B) = C'. So f = A' + C'.
Q4. Why must K-map groups have sizes that are powers of 2?
Because we need to eliminate exactly one variable per doubling. Each time a group doubles in size, one variable changes across the group (0→1 or 1→0), so it can be eliminated from the simplified term.
For example: a group of 2 cells → 1 variable eliminated. Group of 4 → 2 variables eliminated. Group of 3 cells would not correspond to any clean Boolean simplification.
Simplify: F = AB' + AB + A'B
- Group first two terms: AB' + AB = A(B' + B) = A · 1 = A
- Expression becomes: A + A'B
- Apply consensus theorem: A + A'B = A + B
Result: F = A + B
Q1. Simplify F = A + A'B using Boolean laws.
F = A + A'B
= (A + A')(A + B) [Distributive: x + yz = (x+y)(x+z)]
= 1 · (A + B) = A + B
Answer: F = A + B
Q2. Implement XOR using only NAND gates.
Circuit (4 NAND gates):
G1 = NAND(A, B)
G2 = NAND(A, G1)
G3 = NAND(B, G1)
Output = NAND(G2, G3)
Proof: NAND(G2,G3) = (G2·G3)' = ((A·G1)'·(B·G1)')' = A⊕B ✓
Q3. Prove De Morgan's law ¬(A ∧ B) = ¬A ∨ ¬B using truth table.
| A | B | A∧B | ¬(A∧B) | ¬A | ¬B | ¬A∨¬B |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 |
Columns 4 and 7 are identical. ✓ Proved.
Unit 2 – Proofs
Formal methods for establishing mathematical truth.
2.1 Definitions & Axiomatic Systems
- Axiom / Postulate: A statement assumed to be true without proof — the starting point of any mathematical system.
- Theorem: A statement proved rigorously from axioms and previously proved theorems.
- Lemma: A small helper theorem used as a stepping stone toward a larger theorem.
- Corollary: A result that follows immediately and easily from a theorem.
- Conjecture: A statement believed to be true but not yet formally proved (e.g., Goldbach's Conjecture).
- Proof: A finite sequence of logical deductions from axioms/hypotheses that establishes a theorem.
- 0 is a natural number.
- For every natural number n, S(n) (its successor) is a natural number.
- 0 is not the successor of any natural number.
- If S(m) = S(n) then m = n (successors are injective).
- Induction Axiom: If P(0) is true and [P(n) → P(S(n))] for all n, then P(n) is true for all natural numbers n.
2.2 Rules of Inference
Rules of inference are valid argument forms. If the premises are true, the conclusion must be true. They are the "legal moves" in a proof.
| Rule Name | Premises | Conclusion | Example |
|---|---|---|---|
| Modus Ponens (MP) | p, p→q | q | "If it rains, ground is wet. It rains. ∴ Ground is wet." |
| Modus Tollens (MT) | ¬q, p→q | ¬p | "Ground not wet. If rain, ground wet. ∴ No rain." |
| Hypothetical Syllogism | p→q, q→r | p→r | Chain of implications. |
| Disjunctive Syllogism | p∨q, ¬p | q | "Heads or tails. Not heads. ∴ Tails." |
| Addition | p | p∨q | "It rains. ∴ It rains or snows." |
| Simplification | p∧q | p | "It rains and is cold. ∴ It rains." |
| Conjunction | p, q | p∧q | Combining two true facts. |
| Resolution | p∨q, ¬p∨r | q∨r | Used in automated theorem proving. |
Given: (1) p→q (2) q→r (3) p. Prove: r.
- From (1) and (2) by Hypothetical Syllogism: p→r
- From p→r and (3) p by Modus Ponens: r ✓
Q1. Identify the fallacy: "If it rains, the match is cancelled. The match was cancelled. Therefore it rained."
This is the Fallacy of Affirming the Consequent.
Invalid form: p→q, q ⊬ p.
The match could have been cancelled for other reasons (pitch damage, no players, etc.).
Contrast with valid Modus Ponens (p→q, p ∴ q) — affirm the antecedent, not consequent.
Q2. "It is hot or sunny. It is not hot." Conclude what you can.
Premises: H ∨ S, ¬H.
By Disjunctive Syllogism: From H∨S and ¬H → conclude S.
Answer: It is sunny.
2.3 Types of Proofs
1. Direct Proof
Assume the hypothesis is true, then use logical steps to derive the conclusion directly.
Assume n is even → n = 2k for some integer k.
Then n² = (2k)² = 4k² = 2(2k²). Since 2k² is an integer, n² is even. ∎
2. Proof by Contrapositive
Instead of proving p→q, prove the logically equivalent ¬q→¬p.
Contrapositive: "If n is even, then n² is even" — proved above! ∎
3. Proof by Contradiction
Assume the statement is false; derive a logical contradiction, proving the statement must be true.
- Assume √2 is rational: √2 = p/q where p,q are integers with gcd(p,q)=1 (fully reduced).
- Then 2 = p²/q², so p² = 2q² → p² is even → p is even → p = 2k for some k.
- Substitute: (2k)² = 2q² → 4k² = 2q² → q² = 2k² → q² is even → q is even.
- Both p and q are even, contradicting gcd(p,q) = 1. ✗
- ∴ Our assumption was wrong. √2 is irrational. ∎
4. Mathematical Induction
Used to prove statements about all natural numbers. Works like an infinite chain of dominoes.
Base Case: Prove P(n₀) is true (usually n₀ = 0 or 1).
Inductive Step: Assume P(k) is true (Inductive Hypothesis, IH). Using this assumption, prove P(k+1) is true.
Conclusion: P(n) is true for all n ≥ n₀.
Prove: \(1 + 2 + \cdots + n = \dfrac{n(n+1)}{2}\)
- Base case n=1: LHS = 1, RHS = 1·2/2 = 1. ✓
- IH: Assume \(1+2+\cdots+k = \dfrac{k(k+1)}{2}\) for some k ≥ 1.
- Prove for k+1: \(1+\cdots+k+(k+1) = \dfrac{k(k+1)}{2} + (k+1) = (k+1)\left(\dfrac{k}{2}+1\right) = \dfrac{(k+1)(k+2)}{2}\) ✓
This matches the formula with n = k+1. ∎
5. Proof by Cases
Divide all possibilities into a finite number of cases and prove the statement for each case.
Case 1: n is even. n = 2k → n² + n = 4k² + 2k = 2(2k²+k). Even. ✓
Case 2: n is odd. n = 2k+1 → n² + n = (2k+1)² + (2k+1) = 4k²+4k+1+2k+1 = 4k²+6k+2 = 2(2k²+3k+1). Even. ✓
Both cases give even → n² + n is always even. ∎
Q1. Prove: The sum of two odd integers is even. (Direct Proof)
Let a = 2m+1 and b = 2n+1 be two odd integers.
a + b = (2m+1) + (2n+1) = 2m + 2n + 2 = 2(m+n+1).
Since m+n+1 is an integer, a+b is even. ∎
Q2. Prove by induction: \(1^2 + 2^2 + \cdots + n^2 = \frac{n(n+1)(2n+1)}{6}\)
Base case n=1: LHS=1, RHS=1·2·3/6=1. ✓
IH: Assume true for k.
Prove for k+1:
\(\frac{k(k+1)(2k+1)}{6} + (k+1)^2 = (k+1)\left[\frac{k(2k+1)}{6} + (k+1)\right]\)
\(= (k+1) \cdot \frac{k(2k+1) + 6(k+1)}{6} = (k+1) \cdot \frac{2k^2+7k+6}{6} = \frac{(k+1)(k+2)(2k+3)}{6}\) ✓ ∎
Q3. Prove there are infinitely many primes. (Contradiction)
Assume finitely many primes: p₁, p₂, …, pₙ.
Let N = p₁·p₂·⋯·pₙ + 1.
N is not divisible by any pᵢ (remainder 1 each time).
So N is either prime (a new prime!) or has a prime factor not in our list. Either way, contradicts our assumption. ∎
2.4 Program Correctness & Loop Invariants
If precondition P is true before executing statement S, and S terminates, then postcondition Q is true afterward.
Example: {x = 5} x = x + 1 {x = 6}
A condition that is true before the loop starts, remains true after each iteration, and after termination implies the desired result.
Three proof obligations:
- Initialization: The invariant is true before the first iteration.
- Maintenance: If true before an iteration, it stays true after that iteration.
- Termination: When the loop ends, the invariant + exit condition gives the desired result.
result = 1; i = 1;
while (i <= n):
result = result * i
i = i + 1
Invariant: At the start of each iteration, result = (i−1)!
Initialization: Before loop: i=1, result=1 = (1−1)! = 0! = 1. ✓
Maintenance: If result=(i−1)! at start, after body: result = (i−1)!·i = i!, and i increments, so new (i−1)! refers to what's now i!. ✓
Termination: Loop exits when i=n+1. Invariant gives result = (n+1−1)! = n!. ✓
Q1. State and verify a loop invariant for binary search.
low=0; high=n-1
while (low <= high):
mid = (low+high)/2
if A[mid]==target: return mid
elif A[mid] < target: low = mid+1
else: high = mid-1
return -1
Invariant: If target exists in A, it lies within A[low..high].
Init: Before loop, A[low..high] = entire array. Invariant trivially holds. ✓
Maintenance: If A[mid] < target, target must be in right half → set low=mid+1 preserves invariant. Similarly for the other branch. ✓
Termination: low > high means search space is empty → target not present → return −1 is correct. ✓
Unit 3 – Set Theory
Foundations of mathematics and computability theory.
3.1 Russell's Paradox
In naive set theory, any property defines a set. Define:
\[ R = \{ S \mid S \notin S \} \quad \text{(the set of all sets that do NOT contain themselves)} \]
The question: Does R contain itself?
- If R ∈ R → by definition, R ∉ R. Contradiction!
- If R ∉ R → by definition, R ∈ R. Contradiction!
Both cases lead to contradiction → naive set theory is inconsistent!
The Barber Paradox (Informal Illustration)
In a village, the barber shaves every man who does not shave himself, and only those men. Who shaves the barber?
- If barber shaves himself → he is someone who shaves himself → barber should NOT shave him. Contradiction!
- If barber does not shave himself → he is someone who doesn't shave himself → barber SHOULD shave him. Contradiction!
Conclusion: Such a barber cannot exist — and similarly, the "set of all sets" cannot exist.
Resolution: ZFC Axiomatic Set Theory
ZFC restricts set formation to avoid the paradox:
- Axiom of Separation: You can only form a subset of an already existing set. You cannot form a set by collecting absolutely everything.
- No "set of all sets": In ZFC, there is no universal set. This prevents Russell's R from being formed.
- All of useful mathematics can be developed within ZFC without the paradox.
Q1. Why can't we just define a "set of all sets" in mathematics?
If U = set of all sets exists, then R = {S ∈ U : S ∉ S} would be a valid set by the Separation Axiom.
But then R ∈ R ↔ R ∉ R — Russell's paradox again.
Therefore, a "set of all sets" cannot exist consistently. Instead, we use a "proper class" (collection too large to be a set) which is not itself a set and cannot be an element of other collections.
3.2 Countability
A set A is countable if there exists a bijection (one-to-one and onto function) f : A → ℕ, or equivalently, its elements can be listed in a sequence a₁, a₂, a₃, …
- Finite sets are countable.
- Countably infinite sets are infinite but "listable" (same cardinality as ℕ).
- Examples: ℕ, ℤ, ℚ, even numbers, prime numbers.
Listing: 0, 1, −1, 2, −2, 3, −3, 4, −4, …
Bijection: f(n) maps natural number n to: 0 if n=0, n/2 if n is even and >0, −(n+1)/2 if n is odd.
Every integer appears exactly once in the list. ✓
Arrange positive rationals in a 2D grid (row i, column j → i/j):
1/1 1/2 1/3 1/4 ... 2/1 2/2 2/3 2/4 ... 3/1 3/2 3/3 3/4 ... ...
Traverse diagonals: 1/1, 1/2, 2/1, 3/1, 2/2, 1/3, 1/4, 2/3, 3/2, 4/1, …
Skip duplicates (2/2 = 1/1). Every positive rational appears → ℚ⁺ is countable. Adding negatives and 0 keeps it countable. ✓
If A₁, A₂, A₃, … are all countable sets, then A₁ ∪ A₂ ∪ … is countable.
Proof idea: Apply the same 2D zigzag technique — arrange elements in a grid and traverse diagonally.
3.3 Uncountability
Theorem: The real numbers in (0,1) cannot be listed — they are uncountably infinite.
Proof:
- Suppose for contradiction all reals in (0,1) can be listed: r₁, r₂, r₃, …
- Write each as an infinite decimal:
r₁ = 0.d₁₁ d₁₂ d₁₃ …
r₂ = 0.d₂₁ d₂₂ d₂₃ …
r₃ = 0.d₃₁ d₃₂ d₃₃ … - Construct x = 0.x₁x₂x₃… where xᵢ ≠ dᵢᵢ (change each diagonal digit).
- x ≠ r₁ (differs at position 1), x ≠ r₂ (position 2), x ≠ rₙ (position n).
- So x is not in the list — contradiction! ∴ ℝ is uncountable. ∎
r₁ = 0.3141592... → diagonal digit: 3 → change to 5 r₂ = 0.5000000... → diagonal digit: 0 → change to 5 r₃ = 0.7182818... → diagonal digit: 8 → change to 5 r₄ = 0.1428571... → diagonal digit: 8 → change to 5
New number: x = 0.5555… This is NOT equal to any rᵢ in the list (differs at position i). Contradiction!
Q1. Is the set of all computer programs countable?
Yes! A program is a finite string over a finite character set (ASCII).
The set of all finite strings over a finite alphabet is countable — list them in order of increasing length, then lexicographically.
Deep implication: There are only countably many programs, but uncountably many functions ℕ→ℕ (since 𝒫(ℕ) is uncountable). Therefore, most mathematical functions cannot be computed by any program!
Q2. Show that the power set 𝒫(ℕ) is uncountable.
Suppose 𝒫(ℕ) is countable: list all subsets as S₁, S₂, S₃, …
Define the diagonal set: D = {n ∈ ℕ : n ∉ Sₙ}.
For each n: n ∈ D ↔ n ∉ Sₙ, so D ≠ Sₙ for any n.
But D ⊆ ℕ, so D should appear somewhere in the list. Contradiction!
∴ 𝒫(ℕ) is uncountable.
3.4 Applications in Computability and Automata
Claim: No program H can exist that, given any program P and input I, correctly decides whether P halts on I.
- Assume H(P, I) → "halts" or "loops" exists.
- Construct D(P): run H(P, P); if H says "halts" → D loops forever; if H says "loops" → D halts.
- Run D(D): if D halts → H(D,D) said "loops" → D should loop. Contradiction!
If D loops → H(D,D) said "halts" → D should halt. Contradiction! - ∴ H cannot exist. The Halting Problem is undecidable. ∎
- The set {0,1}* of all finite binary strings is countably infinite (can be listed by length).
- The set of all languages over {0,1} = 𝒫({0,1}*) is uncountable.
- DFAs are finite structures → only countably many DFAs exist → only countably many regular languages.
- Conclusion: The vast majority of formal languages are not regular (and not even decidable)!
Unit 4 – Abstract Algebra
Algebraic structures powering modern cryptography and coding theory.
4.1–4.4 Group Theory: Axioms and Examples
A group is a set G with a binary operation ★ satisfying exactly four axioms:
| Axiom | Statement | Meaning |
|---|---|---|
| G1 – Closure | ∀ a,b ∈ G: a★b ∈ G | Operation stays inside the set |
| G2 – Associativity | (a★b)★c = a★(b★c) | Grouping doesn't matter |
| G3 – Identity | ∃ e ∈ G: a★e = e★a = a | There is a "do nothing" element |
| G4 – Inverse | ∀ a ∈ G, ∃ a⁻¹: a★a⁻¹ = e | Every element is "undoable" |
If additionally a★b = b★a for all a,b, the group is Abelian (commutative).
4.2 Additive Group ℤₙ = ({0,1,…,n−1}, +ₙ)
Elements are integers mod n; addition is done modulo n. Identity is 0. Inverse of a is n−a.
3 +₅ 4 = 7 mod 5 = 2. Identity: 0. Inverse of 3 = 5−3 = 2 (since 3+₅2=5≡0).
This is Abelian and cyclic, |ℤ₅| = 5.
4.3 Multiplicative Group ℤₙ* = ({a : gcd(a,n)=1}, ×ₙ)
Only elements coprime to n (gcd = 1) have multiplicative inverses mod n, so only they form a group.
|ℤₙ*| = φ(n) (Euler's totient function = count of integers from 1 to n coprime to n).
Example: ℤ₁₂* = {1,5,7,11}, φ(12) = 4.
4.4 Other Important Groups
| Group | Operation | Order | Abelian? |
|---|---|---|---|
| (ℤ, +) | Integer addition | ∞ | Yes |
| (ℝ*, ×) | Nonzero real multiplication | ∞ | Yes |
| Sₙ (Symmetric group) | Permutation composition | n! | No (n≥3) |
| Dₙ (Dihedral group) | Symmetries of regular n-gon | 2n | No (n≥3) |
| GL(n,ℝ) | Invertible n×n matrices | ∞ | No (n≥2) |
Q1. Verify that ({1,−1}, ×) is a group.
Closure: 1×1=1, 1×(−1)=−1, (−1)×(−1)=1. All in {1,−1}. ✓
Associativity: Multiplication is associative. ✓
Identity: 1 is identity: 1×a = a×1 = a. ✓
Inverse: 1⁻¹=1 and (−1)⁻¹=−1 (since (−1)×(−1)=1). ✓
Also commutative → Abelian group. ✓
Q2. Find all elements of ℤ₁₀* and compute φ(10).
ℤ₁₀* = {a : 1 ≤ a ≤ 9, gcd(a,10)=1}
gcd(1,10)=1 ✓, gcd(3,10)=1 ✓, gcd(7,10)=1 ✓, gcd(9,10)=1 ✓
ℤ₁₀* = {1, 3, 7, 9}
φ(10) = φ(2)×φ(5) = 1×4 = 4. So |ℤ₁₀*| = 4. ✓
4.5–4.6 Order of an Element, Cyclic Groups
The order of element g in group G is the smallest positive integer k such that g^k = e (identity).
Written: ord(g) or |g|. If no such k exists, g has infinite order.
G is cyclic if ∃ g ∈ G such that G = {e, g, g², g³, …} = ⟨g⟩.
g is called a generator. Every cyclic group is Abelian.
ℤₙ under addition is always cyclic with generator 1 (or any element coprime to n).
| Element | Successive multiples (mod 6) | Order |
|---|---|---|
| 0 | 0 | 1 |
| 1 | 1,2,3,4,5,0 | 6 ← generator |
| 2 | 2,4,0 | 3 |
| 3 | 3,0 | 2 |
| 4 | 4,2,0 | 3 |
| 5 | 5,4,3,2,1,0 | 6 ← generator |
ℤ₆ is cyclic: ℤ₆ = ⟨1⟩ = ⟨5⟩.
4.7 Lagrange's Theorem and Corollaries
If H is a subgroup of a finite group G, then |H| divides |G|.
Proof idea: The left cosets {gH : g ∈ G} partition G into equal parts of size |H|. So |G| = (number of cosets) × |H|.
- Corollary 1: ord(g) divides |G| for any g ∈ G.
- Corollary 2: g^|G| = e for any g ∈ G.
- Corollary 3: Any group of prime order p is cyclic (isomorphic to ℤₚ).
- Fermat's Little Theorem: If p is prime and p ∤ a, then a^(p−1) ≡ 1 (mod p).
- Euler's Theorem: If gcd(a,n)=1, then a^φ(n) ≡ 1 (mod n).
Q1. In ℤ₇*, what are the possible orders of elements?
|ℤ₇*| = φ(7) = 6. By Lagrange, element orders must divide 6.
Divisors of 6: 1, 2, 3, 6.
Possible orders: 1, 2, 3, or 6.
Q2. Compute 2^100 mod 7 using Fermat's Little Theorem.
p = 7 (prime), 7 ∤ 2. By Fermat: 2^6 ≡ 1 (mod 7).
100 = 6×16 + 4, so 2^100 = (2^6)^16 × 2^4 ≡ 1^16 × 16 ≡ 16 mod 7 ≡ 2 (mod 7).
Answer: 2^100 ≡ 2 (mod 7).
Q3. Prove: the order of every element of S₃ divides 6.
|S₃| = 3! = 6. By Lagrange, the order of ⟨g⟩ (a cyclic subgroup) must divide |S₃| = 6.
Since ord(g) = |⟨g⟩|, it follows that ord(g) | 6 for every g ∈ S₃. ✓
4.8–4.9 Rings and Polynomial Rings
A ring is a set R with two operations satisfying:
- (R, +) is an Abelian group.
- (R, ×) is a monoid (closed, associative, has identity 1).
- Distributivity: a×(b+c) = a×b + a×c and (b+c)×a = b×a + c×a.
Commutative ring: Also has a×b = b×a. Examples: ℤ, ℤₙ, ℝ[x].
Not commutative: Matrix ring Mₙ(ℝ) for n ≥ 2.
R[x] = {a₀ + a₁x + a₂x² + ⋯ + aₙxⁿ : aᵢ ∈ R} with standard polynomial addition and multiplication.
GF(2)[x] = polynomials with binary coefficients, used in cryptography and error-correcting codes.
All coefficients are mod 2 (so 2 ≡ 0, 3 ≡ 1).
(x² + x + 1) + (x + 1) = x² + 2x + 2 = x² (since 2≡0 mod 2)
(x + 1)² = x² + 2x + 1 = x² + 1 (since 2x ≡ 0)
4.10–4.11 Fields and Primitive Elements
A field is a commutative ring where every nonzero element has a multiplicative inverse.
Equivalently: (F, +) and (F\{0}, ×) are both Abelian groups, with distributivity.
Examples: ℚ, ℝ, ℂ, ℤₚ (p prime), GF(pⁿ) (Galois/Finite Fields).
Note: ℤ is NOT a field (2 has no multiplicative inverse in ℤ).
The multiplicative group GF(q)* = GF(q)\{0} is cyclic of order q−1.
A primitive element (primitive root) g is a generator: {g¹, g², …, g^(q−1)} = GF(q)*.
Is g=3 a primitive root mod 7? ℤ₇* has order 6.
3¹=3, 3²=2, 3³=6, 3⁴=4, 3⁵=5, 3⁶=1 (mod 7)
All 6 nonzero elements of ℤ₇ appear → yes, 3 is a primitive root mod 7! ✓
4.12 Cryptography: DLP and Diffie-Hellman Key Exchange
Problem: Given a prime p, generator g of ℤₚ*, and y = g^x mod p, find x.
Forward direction: Computing g^x mod p is easy (O(log x) via fast exponentiation).
Reverse direction: Given y, finding x is believed to be computationally hard for large p (no polynomial-time algorithm known). This asymmetry is the security basis.
Public parameters: prime p, generator g of ℤₚ*.
- Alice picks secret a, computes A = g^a mod p, sends A to Bob publicly.
- Bob picks secret b, computes B = g^b mod p, sends B to Alice publicly.
- Alice computes: K = B^a mod p = g^(ab) mod p.
- Bob computes: K = A^b mod p = g^(ab) mod p.
- Both share the secret K = g^(ab) mod p without ever transmitting a or b!
Security: An eavesdropper sees g, p, A=g^a, B=g^b but must solve DLP to find K.
p = 23, g = 5
Alice: a = 6 → A = 5⁶ mod 23 = 15625 mod 23 = 8
Bob: b = 15 → B = 5^15 mod 23 = 19
Alice: K = 19^6 mod 23 = 2
Bob: K = 8^15 mod 23 = 2
Shared secret: K = 2 ✓
Q1. Why can't an eavesdropper compute the shared key in Diffie-Hellman?
The eavesdropper sees: p, g, A = g^a mod p, B = g^b mod p.
To compute K = g^(ab) mod p, they need either a or b.
Finding a from A = g^a mod p is exactly the Discrete Logarithm Problem, which has no known efficient (polynomial-time) classical algorithm for large p.
Note: Shor's quantum algorithm CAN solve DLP efficiently, which is why post-quantum cryptography (lattice-based, hash-based) is being standardized by NIST.
Q2. Compute 3^(p-1) mod p for p=11 using Fermat's Little Theorem.
By Fermat's Little Theorem: a^(p-1) ≡ 1 (mod p) for prime p and gcd(a,p)=1.
gcd(3,11)=1 and 11 is prime.
3^(11-1) = 3^10 ≡ 1 (mod 11).
Answer: 1. (No computation needed — FLT gives it directly.)
Unit 5 – Advanced Counting
Analyzing algorithms and combinatorics using recurrences and generating functions.
5.1 Recurrence Relations of Recursive Algorithms
A recurrence relation defines a function T(n) in terms of its values at smaller inputs. Combined with base cases, it uniquely determines the function.
Used to express time complexity of recursive algorithms.
Method 1: Iteration (Unrolling)
T(1) = 1, T(n) = T(n−1) + 1
- T(n) = T(n−1) + 1
- = T(n−2) + 2
- = T(n−k) + k
- At k = n−1: T(1) + (n−1) = 1 + n − 1 = n
T(n) = n = O(n)
Method 2: Characteristic Equation (for linear recurrences)
- Assume F(n) = xⁿ. Substitute: xⁿ = xⁿ⁻¹ + xⁿ⁻². Divide by xⁿ⁻²: x² = x + 1.
- Characteristic equation: x² − x − 1 = 0.
- Roots: \(\varphi = \frac{1+\sqrt{5}}{2} \approx 1.618\) and \(\hat\varphi = \frac{1-\sqrt{5}}{2} \approx -0.618\)
- General solution: \(F(n) = A\varphi^n + B\hat\varphi^n\)
- Use F(0)=0, F(1)=1 to find A=1/√5, B=−1/√5.
- Binet's Formula: \(F(n) = \dfrac{\varphi^n - \hat\varphi^n}{\sqrt{5}}\)
Growth: F(n) = Θ(φⁿ) — exponential!
5.2 Recurrence Relations of Divide & Conquer Algorithms
A D&C algorithm solves a problem of size n by dividing it into a subproblems of size n/b, then spending f(n) work to combine solutions.
| Algorithm | Recurrence | a | b | f(n) | Solution |
|---|---|---|---|---|---|
| Binary Search | T(n/2) + O(1) | 1 | 2 | O(1) | O(log n) |
| Merge Sort | 2T(n/2) + O(n) | 2 | 2 | O(n) | O(n log n) |
| Strassen (Matrix) | 7T(n/2) + O(n²) | 7 | 2 | O(n²) | O(n^2.81) |
5.3 Master Theorem and Growth of Functions
For T(n) = a·T(n/b) + f(n) with a ≥ 1, b > 1:
Define the critical exponent: \(c^* = \log_b a\)
| Case | Condition on f(n) | Conclusion |
|---|---|---|
| Case 1 | f(n) = O(n^(c*−ε)) for ε>0 [f grows slower than n^c*] | T(n) = Θ(n^c*) |
| Case 2 | f(n) = Θ(n^c* · log^k n) for k≥0 [same order] | T(n) = Θ(n^c* · log^(k+1) n) |
| Case 3 | f(n) = Ω(n^(c*+ε)) and af(n/b) ≤ cf(n) [f grows faster] | T(n) = Θ(f(n)) |
Intuition: Case 1: recursion dominates. Case 2: balanced, extra log. Case 3: work at top level dominates.
Merge Sort: T(n) = 2T(n/2) + n
a=2, b=2 → c* = log₂2 = 1. f(n)=n=Θ(n¹)=Θ(n^c*). Case 2, k=0 → T(n)=Θ(n log n)
Binary Search: T(n) = T(n/2) + 1
a=1, b=2 → c* = log₂1 = 0. f(n)=1=Θ(1)=Θ(n⁰). Case 2, k=0 → T(n)=Θ(log n)
T(n) = 4T(n/2) + n
a=4, b=2 → c* = log₂4 = 2. f(n)=n=O(n^(2−1))=O(n¹). Case 1 → T(n)=Θ(n²)
Asymptotic Notation Reference
| Notation | Meaning | Formal Definition |
|---|---|---|
| f = O(g) | f ≤ g asymptotically | ∃c,n₀: f(n) ≤ c·g(n) ∀n≥n₀ |
| f = Ω(g) | f ≥ g asymptotically | ∃c,n₀: f(n) ≥ c·g(n) ∀n≥n₀ |
| f = Θ(g) | f and g same rate | f=O(g) AND f=Ω(g) |
| f = o(g) | f strictly slower | lim f(n)/g(n) = 0 as n→∞ |
Q1. Solve T(n) = 3T(n/3) + n.
a=3, b=3 → c* = log₃3 = 1. f(n)=n = Θ(n¹) = Θ(n^c*).
Case 2 with k=0: T(n) = Θ(n log n).
Q2. Solve T(n) = 9T(n/3) + n.
a=9, b=3 → c* = log₃9 = 2. f(n)=n = O(n^(2−1)) = O(n^1).
f grows strictly slower than n^c*=n²: Case 1.
T(n) = Θ(n²).
Q3. Solve T(n) = 2T(n/2) + n log n.
a=2, b=2 → c* = 1. f(n) = n log n = Θ(n¹ · log¹n) = Θ(n^c* · log¹n).
Case 2 with k=1: T(n) = Θ(n log² n).
5.4 Generating Functions
The OGF of sequence a₀, a₁, a₂, … is the formal power series:
\[ A(x) = \sum_{n=0}^{\infty} a_n x^n = a_0 + a_1 x + a_2 x^2 + \cdots \]
Key idea: The sequence IS the generating function — encoded as coefficients. We treat this as a formal algebraic object and use algebra to extract information.
Reading off: aₙ = [xⁿ] A(x) (the coefficient of xⁿ in A(x)).
Standard Generating Functions
| Sequence aₙ | Generating Function A(x) |
|---|---|
| 1, 1, 1, 1, 1, … | \(\dfrac{1}{1-x}\) |
| 1, r, r², r³, … | \(\dfrac{1}{1-rx}\) |
| \(\binom{n+k}{k}\) (fixed k) | \(\dfrac{1}{(1-x)^{k+1}}\) |
| Fibonacci: 0,1,1,2,3,5,… | \(\dfrac{x}{1-x-x^2}\) |
| n = 0,1,2,3,… | \(\dfrac{x}{(1-x)^2}\) |
Operations on Generating Functions
| Operation | Effect on Sequence |
|---|---|
| A(x) + B(x) | aₙ + bₙ (pointwise sum) |
| x · A(x) | Shift right: 0, a₀, a₁, a₂, … |
| A(x) · B(x) | Convolution: cₙ = Σᵢ aᵢ · bₙ₋ᵢ |
| A'(x) | n · aₙ (multiply each term by its index) |
| ∫A(x)dx | aₙ/(n+1) (divide by index+1) |
5.5 Applications of Generating Functions in Counting
Problem: Number of ways to distribute n identical items into k distinct bins (each bin ≥ 0).
GF for one bin (can hold 0,1,2,… items): \(\sum_{j=0}^{\infty} x^j = \dfrac{1}{1-x}\)
GF for k bins: \(\left(\dfrac{1}{1-x}\right)^k = \dfrac{1}{(1-x)^k}\)
Answer = [xⁿ] \(\dfrac{1}{(1-x)^k} = \dbinom{n+k-1}{k-1}\) ← Stars and Bars!
Problem: Ways to make n cents using 1¢, 2¢, 5¢ coins (unlimited supply).
GF for each coin type: 1/(1−x^denomination)
Combined GF: \(\dfrac{1}{(1-x)(1-x^2)(1-x^5)}\)
Coefficient of xⁿ = number of ways to make n cents.
Problem: Distribute n identical items into 3 bins, each holding 0 to 4 items.
GF for one bin: 1 + x + x² + x³ + x⁴ = \(\dfrac{1-x^5}{1-x}\)
Combined: \(\left(\dfrac{1-x^5}{1-x}\right)^3 = \dfrac{(1-x^5)^3}{(1-x)^3}\)
Expand and extract coefficient of xⁿ.
5.6 Applying Generating Functions to Solve Recurrences
- Define A(x) = Σ aₙxⁿ.
- Multiply the recurrence by xⁿ and sum over valid n values.
- Rewrite in terms of A(x) using shifting: Σ aₙ₋₁xⁿ = xA(x), etc.
- Solve the resulting algebraic equation for A(x) as a rational function.
- Use partial fractions to decompose A(x), then read off coefficients.
F(n) = F(n−1) + F(n−2), F(0)=0, F(1)=1.
- Let F(x) = Σ F(n)xⁿ.
- Sum recurrence for n≥2: \(\sum_{n\geq 2}F(n)x^n = \sum_{n\geq 2}F(n-1)x^n + \sum_{n\geq 2}F(n-2)x^n\)
- LHS = F(x) − F(0) − F(1)x = F(x) − x
- RHS = x·(F(x)−F(0)) + x²·F(x) = xF(x) + x²F(x)
- F(x) − x = xF(x) + x²F(x)
- F(x)(1 − x − x²) = x
- \(\boxed{F(x) = \dfrac{x}{1-x-x^2}}\)
- Factor: 1−x−x² = −(x − 1/φ)(x − 1/ψ)... use partial fractions to get \(F(n) = \dfrac{\varphi^n - \hat\varphi^n}{\sqrt{5}}\) ✓
Q1. Find the coefficient of x⁵ in 1/(1−x)³.
\(\dfrac{1}{(1-x)^3} = \sum_{n=0}^{\infty} \dbinom{n+2}{2} x^n\)
For n=5: \(\dbinom{7}{2} = 21.\)
Answer: 21.
Combinatorial meaning: ways to distribute 5 identical items into 3 distinct bins = C(7,2) = 21.
Q2. Solve aₙ = 2aₙ₋₁, a₀ = 1 using generating functions.
Let A(x) = Σ aₙxⁿ.
A(x) − a₀ = 2x·A(x) → A(x) − 1 = 2xA(x)
A(x)(1−2x) = 1 → A(x) = 1/(1−2x) = Σ 2ⁿxⁿ
Answer: aₙ = 2ⁿ.
Q3. How many ways to distribute 10 identical candies to 4 children so each gets at least 1?
Substitution: let yᵢ = xᵢ − 1 ≥ 0. Then y₁+y₂+y₃+y₄ = 10 − 4 = 6.
GF = 1/(1−x)⁴. Answer = [x⁶] 1/(1−x)⁴ = C(6+3,3) = C(9,3) = 84.
Answer: 84 ways.
Q4. Solve aₙ − 5aₙ₋₁ + 6aₙ₋₂ = 0, a₀=0, a₁=1 using GFs.
Let A(x) = Σ aₙxⁿ. Multiply recurrence by xⁿ, sum for n≥2:
A(x) − x − 5x·A(x) + 6x²·A(x) = 0
A(x)(1 − 5x + 6x²) = x
A(x) = x / (1−5x+6x²) = x / ((1−2x)(1−3x))
Partial fractions: x/((1−2x)(1−3x)) = A/(1−2x) + B/(1−3x)
Set x=1/2: 1/2 = A(1/2) → A=−1. Set x=1/3: 1/3 = B(1/3) → B=1.
A(x) = −1/(1−2x) + 1/(1−3x) = Σ (−2ⁿ + 3ⁿ)xⁿ
Answer: aₙ = 3ⁿ − 2ⁿ. Verify: a₀=1−1=0 ✓, a₁=3−2=1 ✓.
Q5. Find the GF for the number of ways to partition n into at most 3 parts, each part ≤ 4.
Each part is between 0 and 4, and we have 3 parts (order matters here; if order doesn't matter it's harder).
Treating parts as ordered (compositions): GF for one part = 1 + x + x² + x³ + x⁴ = (1−x⁵)/(1−x).
GF for 3 ordered parts: \(\left(\frac{1-x^5}{1-x}\right)^3\).
Coefficient of xⁿ in this product gives the count. For example, [x⁵] = number of ways = 18 (can verify by enumeration).
© 2025 @oksaumya • All rights reserved.