Discrete Mathematics — Comprehensive Lecture Notes
教材:K. Rosen, Discrete Mathematics and its Applications, 8th Edition 本笔记按课程顺序整理,涵盖第1–11次课所有内容,详细复述课件知识点。关键术语在首次出现时括号内给出中文翻译。
Chapter 1: Logic and Proofs(逻辑与证明)
Section 1.1 — Propositional Logic(命题逻辑)
Propositions(命题)
A proposition (命题) is a declarative sentence that is either true or false — not both.
Examples of propositions:
- "The Moon is made of green cheese." (false)
- "1 + 0 = 1" (true)
- "0 + 0 = 2" (false)
Examples that are NOT propositions:
- "Sit down!" — (a command, not declarative)
- "What time is it?" — (a question)
- "x + 1 = 2" — (contains a free variable, truth value undefined)
Propositional Variables(命题变量)
We use propositional variables
- The proposition that is always true is denoted
(tautology). - The proposition that is always false is denoted
(contradiction).
Compound propositions (组合命题) are built from simpler ones using logical connectives (逻辑联结词).
The Six Connectives
1. Negation(否定) —
| T | F |
| F | T |
2. Conjunction(合取) —
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | F |
3. Disjunction(析取) —
This is the inclusive or (兼或):
| T | T | T |
| T | F | T |
| F | T | T |
| F | F | F |
4. Exclusive Or(异或) —
| T | T | F |
| T | F | T |
| F | T | T |
| F | F | F |
5. Conditional Statement(条件命题/蕴含) —
This is the most subtle connective.
| T | T | T |
| T | F | F |
| F | T | T |
| F | F | T |
is called the hypothesis (假设) / antecedent (前件) / premise (前提). is called the conclusion (结论) / consequent (后件).
Key insight: When the hypothesis is false, the whole implication is vacuously true. Think of it as a contract: "If I am elected, I will lower taxes." The politician only breaks the promise when elected but does NOT lower taxes.
Many ways to say
- "if p, then q" / "p implies q" / "p only if q"
- "q if p" / "q whenever p" / "q follows from p"
- "p is sufficient for q" / "q is necessary for p"
Related conditionals derived from
| Name | Form | Equivalent to |
|---|---|---|
| Converse(逆命题) | — | |
| Inverse(反命题) | — | |
| Contrapositive(逆否命题) |
is logically equivalent to its contrapositive , but not to its converse or inverse.
6. Biconditional Statement(双条件命题) —
| T | T | T |
| T | F | F |
| F | T | F |
| F | F | T |
Note:
Precedence of Logical Operators(优先级)
From highest to lowest:
| Operator | Precedence |
|---|---|
| 1 (highest) | |
| 2 | |
| 3 | |
| 4 | |
| 5 (lowest) |
So
Bit Operations(位运算)
In computers, bits (0 and 1) represent truth values (0 = False, 1 = True). Boolean operations correspond to logical operations:
- Bitwise OR ↔
- Bitwise AND ↔
- Bitwise XOR ↔
Section 1.2 — Applications of Propositional Logic
Key application: translating English sentences to logic.
Steps:
- Identify atomic propositions and assign variables.
- Determine logical connectives.
Example: "You can access the Internet from campus only if you are a student or you pay the fee."
- Let
= "you can access the Internet from campus" - Let
= "you are a student" - Let
= "you pay the fee" - Result:
System specifications (系统规范) must be consistent (自洽的) — no assignment of truth values should cause a contradiction.
Logic puzzles: use logic to determine truth from clues.
Section 1.3 — Logical Equivalences(逻辑等价式)
Two propositions are logically equivalent (逻辑等价) if they have the same truth value for every assignment of truth values to their variables. We write
Key Equivalences Table
| Law Name | Equivalences |
|---|---|
| Identity laws (恒等律) | |
| Domination laws (支配律) | |
| Idempotent laws (幂等律) | |
| Double Negation | |
| Commutative laws (交换律) | |
| Associative laws (结合律) | |
| Distributive laws (分配律) | |
| De Morgan's laws (德摩根律) | |
| Absorption laws (吸收律) | |
| Complement laws (互补律) |
Useful implications:
Constructing Equivalence Proofs
To show
Example: Show
Tautology (重言式/永真式): always true.
Contradiction (矛盾式/永假式): always false.
Contingency (可满足式): truth depends on variable values.
Dual(对偶式)
The dual
- Replacing each
with and vice versa - Replacing each
with and vice versa
Theorem: If
Example:
Functionally Complete Operators(完全联结词组)
A set of operators is functionally complete (完全的) if every compound proposition can be expressed using only those operators.
Complete sets include:
, (NAND / Sheffer stroke 与非) — alone forms a complete set (NOR / Peirce arrow 或非) — alone forms a complete set
Propositional Satisfiability(命题可满足性)
A compound proposition is satisfiable (可满足的) if at least one assignment of truth values makes it true. If no such assignment exists, it is unsatisfiable (不可满足的).
SAT problem: determining satisfiability is NP-complete. Many real-world problems (e.g., Sudoku) can be encoded as SAT problems and solved by SAT solvers.
Section 1.3 (Supplement) — Propositional Normal Forms(范式)
Propositional Formula(命题公式)
Formal definition:
- Each propositional variable and
are formulas. - If
is a formula, so is . - If
and are formulas, so are , , , . - Only strings formed by finitely many applications of the above rules are formulas.
Literals(文字)
A literal (文字) is a propositional variable or its negation. E.g.,
DNF — Disjunctive Normal Form(析取范式)
A formula is in DNF if it is a disjunction of conjunctive clauses (合取子句), where each conjunctive clause is a conjunction of literals.
Example:
CNF — Conjunctive Normal Form(合取范式)
A formula is in CNF if it is a conjunction of disjunctive clauses (析取子句), where each disjunctive clause is a disjunction of literals.
How to convert a formula to CNF/DNF:
- Eliminate
and using equivalences. - Move
inward: apply De Morgan's laws and double negation until only precedes atoms. - Use distributive laws to expand to the desired form.
Example: Convert
Minterms(极小项/最小项)
A minterm (极小项) is a conjunction of literals in which each variable appears exactly once (positive or negative).
For
For variables
| minterm | true when | |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 |
Properties of minterms:
- Each minterm is true for exactly one assignment.
- The conjunction of two different minterms is always
. - The disjunction of all minterms is
.
Full Disjunctive Normal Form(主析取范式)
The full disjunctive normal form (主析取范式) of a function
Notation:
How to find from a truth table: select the minterms corresponding to rows where the function is true.
Example: If
Maxterms(极大项)and Full CNF(主合取范式)
A maxterm
Converting between forms: if
Then
Section 1.4 — Predicate Logic(谓词逻辑)
Propositional logic cannot express arguments like "All men are mortal; Socrates is a man; therefore Socrates is mortal." We need predicate logic (谓词逻辑), also called first-order logic.
Propositional Functions(命题函数)
A propositional function
Quantifiers(量词)
Universal Quantifier(全称量词)
- True when
is true for every element of the domain. - False when there exists at least one counterexample (反例)
for which is false. - When domain
:
Existential Quantifier(存在量词)
- True when
is true for at least one element. - When domain
:
Uniqueness Quantifier(唯一性量词)
This can be expressed as:
Precedence: quantifiers have higher precedence than all logical operators.
So
Bound vs. Free Variables(约束变量 vs. 自由变量)
- A variable is bound (约束的) if it is quantified.
- A variable is free (自由的) if it is not quantified.
- The scope (作用域) of a quantifier is the part of the expression to which it applies.
All variables must be bound for the expression to be a proposition.
De Morgan's Laws for Quantifiers
To negate a universal statement, turn it into an existential statement that the property fails somewhere (and vice versa).
Translating English to Logic
Key patterns:
- "All/every/each S are P" →
- "Some/there exists an S that is P" →
(Warning: do NOT usewith , it has a different meaning!)
Example: "No CS student is a Math student."
Logical Equivalences with Quantifiers
If
Section 1.5 — Nested Quantifiers(嵌套量词)
Nested quantifiers (嵌套量词): one quantifier is within the scope of another.
Example: "Every real number has an additive inverse":
Order of Quantifiers Matters!
These are generally NOT equivalent.
| Statement | When true | When false |
|---|---|---|
| Some pair makes | ||
| For each | Some | |
| One | Every | |
| Some pair satisfies |
Negating Nested Quantifiers
Apply De Morgan's laws repeatedly, moving
Section 1.6 — Rules of Inference(推理规则)
Valid Arguments(有效论证)
An argument (论证) in propositional logic is a sequence of propositions; all but the last are premises (前提), and the last is the conclusion (结论).
An argument is valid (有效的) if whenever all premises are true, the conclusion is also true — i.e.,
Rules of Inference for Propositions
| Rule Name | Form | Tautology |
|---|---|---|
| Modus Ponens (假言推理) | ||
| Modus Tollens (取拒式) | ||
| Hypothetical Syllogism (假言三段论) | ||
| Disjunctive Syllogism (析取三段论) | ||
| Addition (附加律) | ||
| Simplification (化简律) | ||
| Conjunction (合取律) | ||
| Resolution (消解律) |
Rules of Inference for Quantified Statements
| Rule | Name |
|---|---|
| Universal Instantiation (UI) (全称实例) | |
| Universal Generalization (UG) (全称引入) | |
| Existential Instantiation (EI) (存在实例) | |
| Existential Generalization (EG) (存在引入) |
Universal Modus Ponens (全称假言推理) combines UI and Modus Ponens:
Building valid arguments: Write each step as either a premise or a consequence of previous steps by a named rule.
Section 1.7 — Introduction to Proofs(证明方法)
Terminology
- Theorem (定理): a statement proven true using definitions, other theorems, axioms, and rules of inference.
- Lemma (引理): a "helping theorem" used in the proof of a larger result.
- Corollary (推论): a result that follows directly from a theorem.
- Conjecture (猜想): a statement believed to be true but not yet proven.
- Axiom (公理): a statement assumed to be true.
Even and Odd Integers
Every integer is either even or odd (but not both).
A real number
Proof Methods for
1. Direct Proof(直接证明法): Assume
Example: Prove "if
Proof: Assume
2. Proof by Contraposition(反证法/逆否证明): Prove
Example: Prove "if
Proof: (Contrapositive) Assume
3. Proof by Contradiction(归谬证明法): Assume
Example: Prove
Proof: Assume
Example: Prove there is no largest prime.
Proof: Assume primes
4. Trivial Proof(平凡证明): If
5. Vacuous Proof(空证明): If
Biconditional Proofs
To prove
Section 1.8 — More Proof Strategies
Proof by Cases(分情形证明)
Use the tautology
Prove
Without Loss of Generality (WLOG) (不失一般性): when cases are symmetric, prove one and state the other follows similarly.
Existence Proofs(存在性证明)
Prove
Constructive (构造性): find an explicit
such that is true.
Example: 1729 =(can be written as sum of cubes in two ways). Nonconstructive (非构造性): prove existence indirectly (often by contradiction), without finding the element.
Example: Proveirrational such that is rational.
Consider: if rational, done ( ). If irrational, let , ; then , rational.
Disproof by Counterexample(反例否证)
To disprove
Uniqueness Proofs(唯一性证明)
To prove
- Existence: find an element
satisfying . - Uniqueness: show that if
also satisfies , we get a contradiction.
Proof Strategies
- Forward reasoning: start from axioms/premises, derive conclusion.
- Backward reasoning: to prove
, find a statement with that you can prove. - If direct proof fails, try contrapositive or contradiction.
Open Problems (undecided conjectures)
- Fermat's Last Theorem (费马大定理):
has no integer solutions with for . (Proved by Andrew Wiles, 1990s) - Goldbach's Conjecture (哥德巴赫猜想): every even integer
is the sum of two primes. (Still open) - 3x+1 Conjecture (Collatz): repeatedly applying
(if even) or (if odd) always reaches 1.
Additional Proof Methods (Preview)
- Mathematical Induction (数学归纳法): covered in Chapter 5.
- Structural Induction (结构归纳法): for recursively defined sets.
- Cantor Diagonalization (康托尔对角线方法): proving uncountability.
- Combinatorial Proofs (组合证明): using counting arguments.
Chapter 2: Basic Structures(基本结构)
Section 2.1 — Sets(集合)
A set (集合) is an unordered collection of distinct objects. Objects in a set are called elements (元素) or members (成员).
Notation:
Describing Sets
Roster method (列举法): list elements explicitly.
Set-builder notation (描述法):
Important Sets
| Symbol | Set |
|---|---|
| Natural numbers | |
| Integers | |
| Positive integers | |
| Rational numbers | |
| Real numbers | |
| Complex numbers |
Universal set (全集)
Empty set (空集)
Russell's Paradox (罗素悖论): Let
Subsets, Equality, Power Sets
(subset, 子集): every element of is also in .
Equivalently,. (equality): and . (proper subset, 真子集): but . for every set ; for every set .
Cardinality (基数)
Power set (幂集)
If
Example:
Tuples and Cartesian Product
An ordered
2-tuples are called ordered pairs (序偶).
Cartesian product (笛卡尔积)
Example:
A relation (关系) from
Section 2.2 — Set Operations(集合运算)
Set operations are analogous to logical operations (Boolean Algebra).
| Operation | Definition | Analogy |
|---|---|---|
| Union (并集) | ||
| Intersection (交集) | ||
| Complement (补集) | ||
| Difference (差集) | — | |
| Symmetric Difference (对称差) |
If
Inclusion-Exclusion (容斥原理):
Set Identities
Mirror image of logical equivalences — just replace
Key: De Morgan's Laws for sets:
Proving Set Identities
- Element-chasing: show each side is a subset of the other.
- Set-builder + propositional logic: convert to logical statements and use known equivalences.
- Membership table: like a truth table but with "in set" (1) / "not in set" (0).
Computer Representation of Sets
Represent subset
- Bit
= 1 if , else 0.
Set operations become bitwise operations:
- Union → bitwise OR
- Intersection → bitwise AND
- Complement → bitwise NOT
Section 2.3 — Functions(函数)
Definition: A function
= domain (定义域) = codomain (陪域) : is the image (像) of ; is the preimage (原像) of - Range (值域): the set of all images
Formally:
Types of Functions
Injection(单射) (one-to-one):
Different inputs give different outputs.
Surjection(满射) (onto): for every
Every element of the codomain is an image.
Bijection(双射) (one-to-one correspondence): both injective AND surjective.
Inverse Functions(反函数)
If
Inverse exists if and only if
Function Composition(函数复合)
Given
Note:
Floor and Ceiling Functions
- Floor (下取整)
: largest integer . - Ceiling (上取整)
: smallest integer .
Examples:
Useful identity:
Factorial(阶乘)
Stirling's approximation:
Section 2.4 — Sequences and Summations(序列与求和)
A sequence (序列) is a function from a subset of integers to a set
Geometric progression (等比数列/级数):
Arithmetic progression (等差数列):
Recurrence Relations(递推关系)
A recurrence relation (递推关系) expresses
Fibonacci sequence (斐波那契数列):
Values:
Solving a recurrence: find a closed formula (闭公式). Method: iteration (forward or backward substitution).
Example:
Financial application: compound interest.
Summations(求和)
Geometric series:
Useful formulas:
| Sum | Formula |
|---|---|
Section 2.5 — Cardinality of Sets(集合的基数)
Definition:
Countable set (可数集): either finite, or has the same cardinality as
The cardinality of a countably infinite set is
An infinite set is countable iff its elements can be listed as a sequence
Uncountable set (不可数集): infinite but not countable (e.g.,
Showing Sets are Countably Infinite
- Positive even integers
: bijection from to . ✓ - Integers
: list as ✓ - Positive rationals
: use the diagonal enumeration of (Cantor's diagonal argument for countability). ✓ - Finite strings over a finite alphabet: list by length, then lexicographically. ✓
- Set of all Java programs: countable (Java programs are finite strings from finite alphabet). ✓
Properties of countable sets:
- No infinite set has smaller cardinality than a countable set.
- Union of finitely many countable sets is countable.
- Union of countably many countable sets is countable.
Hilbert's Grand Hotel (David Hilbert)
A hotel with countably infinite rooms, all occupied: we can still accommodate a new guest! Move guest in room
Cantor Diagonalization(康托尔对角线论证)
Theorem: The set of real numbers in
Proof: Assume
Construct
Then
Corollary:
The Continuum Hypothesis (连续统假设) asserts there is no cardinality
Schröder-Bernstein Theorem: If
Cantor's Theorem:
Computability: Since the set of Java programs is countable but the set of functions
Section 2.6 — Matrices(矩阵)
A matrix (矩阵) is a rectangular array of numbers. An
Matrix Arithmetic
Addition:
Multiplication:
Note: matrix multiplication is not commutative in general.
Identity matrix (单位矩阵)
Transpose (转置)
A matrix is symmetric (对称矩阵) if
Zero-One Matrices
A zero-one matrix has entries only 0 or 1.
Boolean operations:
- Join
: entry-wise OR. - Meet
: entry-wise AND. - Boolean product
: .
Boolean powers:
Chapter 3: Algorithms(算法)
Section 3.1 — Algorithms
Definition: An algorithm is a finite set of precise instructions for performing a computation or solving a problem.
Properties of a good algorithm:
- Input: well-defined input values.
- Output: produces correct output.
- Correctness: produces the right answer.
- Finiteness: terminates after finite steps.
- Effectiveness: each step can be performed exactly.
- Generality: works for all valid inputs.
Searching Algorithms
Linear Search (线性搜索): scan each element from left to right.
Complexity:
Binary Search (二分搜索): requires a sorted list.
- Compare target with middle element.
- If equal, found. If target is larger, search upper half. If smaller, search lower half.
- Repeat until the list has 1 element.
Pseudocode:
procedure binary_search(x, a[1..n]):
i := 1; j := n
while i < j:
m := ⌊(i+j)/2⌋
if x > a[m] then i := m+1
else j := m
if x = a[i] then return i
else return 0Complexity:
Sorting Algorithms
Bubble Sort (冒泡排序): make passes through the list, swapping adjacent elements that are out of order.
Worst-case complexity:
Insertion Sort (插入排序): build the sorted array one element at a time.
Worst-case complexity:
Greedy Algorithms(贪心算法)
A greedy algorithm makes the locally "best" choice at each step. Does not always give the globally optimal solution.
Example: Making change with U.S. coins (quarters, dimes, nickels, pennies). Always pick the largest denomination that fits. This is optimal for standard U.S. coins.
Failure example ("Asiarons" 1, 7, 10): greedy gives 15 = 10+1+1+1+1+1 (6 coins), but optimal is 7+7+1 (3 coins).
Greedy Scheduling: to schedule the most talks (no overlap), always choose the talk with the earliest finishing time among compatible ones. (This is optimal.)
Halting Problem(停机问题)
Claim: There is no algorithm that can always determine whether an arbitrary program halts.
Proof by contradiction: Assume procedure
The halting problem is unsolvable (不可解的).
Section 3.2 — The Growth of Functions
Big-O Notation(大O记号)
Definition:
and are called witnesses (凭证). - Big-O gives an upper bound on the growth rate.
- We say "
asymptotically dominates ."
Example: Show
When
Polynomial: If
(The leading term dominates.)
Common Big-O estimates:
is is is
Big-Omega Notation(大Ω记号)
Big-Omega gives a lower bound. Note:
Big-Theta Notation(大Θ记号)
Equivalently, there exist
and are said to be of the same order. - Example:
is .
Useful Hierarchies
In order of growth (slowest to fastest):
Key inequalities:
- (log
) is for any — but is NOT . is for — but is NOT . - If
: is but NOT vice versa.
Section 3.3 — Complexity of Algorithms
Time complexity (时间复杂度): number of operations (comparisons, arithmetic) as a function of input size.
Space complexity (空间复杂度): memory usage (studied in later courses).
We focus on worst-case complexity (最坏情况复杂度) — an upper bound that holds for all inputs.
Complexity of Key Algorithms
| Algorithm | Worst-case | Notes |
|---|---|---|
| Finding maximum | ||
| Linear search | ||
| Binary search | sorted list required | |
| Bubble sort | ||
| Insertion sort | ||
| Matrix multiplication ( | ||
| Boolean matrix product | bit operations |
Binary modular exponentiation: computing
Complexity Classes
- Class P (多项式时间类): problems solvable in polynomial time
. - Class NP: solutions can be verified in polynomial time, but finding a solution may not be polynomial.
- NP-complete (NP完全): hardest problems in NP; if any one has a polynomial algorithm, all NP problems do.
- Unsolvable (不可解): no algorithm exists (e.g., halting problem).
SAT (satisfiability) is the first NP-complete problem (Cook, 1971).
Big open question: P = NP? — generally believed to be NO.
Intuition on complexity:
For
Chapter 4: Number Theory(数论)
Section 4.1 — Divisibility and Modular Arithmetic
Divisibility(整除性)
We say
Theorem (Properties of divisibility):
If
for any integer - If
and , then
Corollary:
Division Algorithm(带余除法)
For any integer
= divisor, = dividend(被除数), = quotient(商), = remainder(余数).
Examples:
, so , . , so , .
Congruence(同余)
Two integers are congruent mod
Theorem:
Theorem (Congruence preserves operations):
If
Corollary:
Caution: Dividing both sides of a congruence by an integer does NOT always preserve congruence. (E.g.,
Arithmetic Modulo
Properties: closure, associativity, commutativity, identity elements (0 for
Additive inverse of
Section 4.2 — Integer Representations
Any positive integer
where
Key bases:
- Binary (二进制): base 2, digits =
- Octal (八进制): base 8, digits =
- Hexadecimal (十六进制): base 16, digits =
Conversions:
- Decimal → base
: repeatedly divide by ; remainders (right to left) give the digits. - Binary ↔ Octal: group binary digits in 3s (right to left).
- Binary ↔ Hex: group binary digits in 4s.
Algorithms for Integer Operations
Binary addition:
Binary multiplication:
Binary Modular Exponentiation (快速模幂): to compute
- Write
in binary: . - Use repeated squaring: compute
. - Multiply the terms where
. - Total:
bit operations.
Section 4.3 — Primes and GCD
Prime Numbers(质数)
A positive integer
Fundamental Theorem of Arithmetic (算术基本定理): Every positive integer
Sieve of Eratosthenes (埃拉托斯特尼筛法): to find all primes up to
- List all integers from 2 to
. - Strike out all multiples of 2 (except 2 itself), then of 3, then of 5, etc.
- Stop when you've processed all primes up to
.
Theorem (Euclid): There are infinitely many primes.
Proof: Assume finite list
Mersenne primes (梅森质数): primes of the form
Prime Number Theorem (质数定理): The number of primes
Goldbach's Conjecture (哥德巴赫猜想): every even integer
Twin Prime Conjecture (孪生质数猜想): infinitely many pairs of primes differing by 2. (Unproved, but Zhang Yitang proved there are infinitely many prime pairs differing by
Greatest Common Divisor (GCD)(最大公因数)
Integers
Using prime factorizations: if
Least Common Multiple (LCM) (最小公倍数):
Key relationship:
Euclidean Algorithm(欧几里得算法)
Key lemma:
Algorithm: repeatedly replace
Example:
Time complexity:
Bézout's Theorem(贝祖定理)
If
Finding Bézout coefficients: work backwards through the Euclidean algorithm.
Example: Express
Working back:
Lemma: If
Lemma: If
Section 4.4 — Solving Congruences & Cryptography
Linear Congruences(线性同余方程)
A linear congruence is of the form
An inverse of
Theorem 1: If
Proof: By Bézout's theorem, there exist
Finding inverses: use the Euclidean algorithm to find Bézout coefficients.
Solving
Example: Solve
Inverse of 3 mod 7:
Chinese Remainder Theorem(中国剩余定理 / 秦九韶定理)
Theorem (CRT): Given pairwise relatively prime moduli
has a unique solution modulo
Construction: Let
Sun-Tsu's problem:
Inverses:
Back Substitution is an alternative method: rewrite first congruence as equality, substitute into next, etc.
Fermat's Little Theorem(费马小定理)
Theorem: If
Equivalently,
Example: Find
By FLT:
Euler's Theorem (欧拉定理) generalizes this: if
Pseudoprimes(伪质数)
If
A Carmichael number (卡米切尔数) satisfies
Primitive Roots(原根)
A primitive root modulo a prime
Every prime
Discrete Logarithm(离散对数)
If
Asymmetry: Given
Section 4.5 — Applications of Number Theory
Hashing Functions(哈希函数)
A hashing function
Common:
Collision (碰撞): when two keys map to the same location. Resolved by linear probing:
Pseudorandom Numbers(伪随机数)
Linear congruential method: given modulus
The sequence is periodic with period at most
Example:
Check Digits(校验码)
UPC (Universal Product Code): 12-digit code. Check digit
ISBN-10: 10-digit code. Check digit
These check digits detect single-digit errors and transposition errors.
Public Key Cryptography and RSA
Private key cryptosystem: encryption and decryption keys are related; knowing one lets you find the other. All parties must share the secret key.
Public key cryptosystem (公钥密码系统): encryption key is public; decryption key is kept private. Knowing how to encrypt does NOT help decrypt.
RSA Cryptosystem (Rivest–Shamir–Adleman, 1976):
Setup (Key generation):
- Choose two large primes
and . - Compute
and . - Choose
with (public exponent). - Find
= inverse of modulo (private key).
Public key:
Encryption:
Decryption:
Why it works:
Security: relies on the fact that factoring large
Example: Key
Encrypt "STOP" = 1819 1415:
Ciphertext: 2081 2182.
Decrypt with
Diffie-Hellman Key Exchange(密钥交换协议)
Alice and Bob agree on prime
- Alice chooses secret
, sends to Bob. - Bob chooses secret
, sends to Alice. - Shared secret:
.
Security: finding
Digital Signatures(数字签名)
To prove a message came from Alice:
- Alice encrypts (signs) with her private key
: . - Anyone can verify with Alice's public key
: .
Combining encryption and signature:
- Use recipient Bob's public key for confidentiality (only Bob can read).
- Use Alice's private key for authentication (proves it's from Alice).
Summary of Key Formulas
Chapter 1 — Logic
| Concept | Formula |
|---|---|
| Contrapositive | |
| De Morgan (prop) | |
| De Morgan (quant) | |
| Conditional | |
| Biconditional |
Chapter 2 — Sets and Functions
| Concept | Formula |
|---|---|
| Power set size | $ |
| Inclusion-Exclusion | $ |
| Geometric series | |
| Sum of first |
Chapter 3 — Algorithms
| Algorithm | Complexity |
|---|---|
| Binary search | |
| Bubble/Insertion sort | |
| Matrix multiply |
Chapter 4 — Number Theory
| Concept | Formula |
|---|---|
| Division algorithm | |
| Congruence | |
| Bézout's identity | |
| lcm-gcd relation | |
| Fermat's Little Thm | |
| Euler's Theorem | |
| RSA encrypt | |
| RSA decrypt |
End of Comprehensive Lecture Notes
Covers: Lectures 1–11 | Sections 1.1–1.8, 2.1–2.6, 3.1–3.3, 4.1–4.5