Skip to content

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 p,q,r,s,… to represent propositions.

  • The proposition that is always true is denoted T (tautology).
  • The proposition that is always false is denoted F (contradiction).

Compound propositions (组合命题) are built from simpler ones using logical connectives (逻辑联结词).

The Six Connectives ​

1. Negation(否定) — ¬p ("not p")

p¬p
TF
FT

2. Conjunction(合取) — p∧q ("p AND q")

p∧q is true only when both p and q are true.

pqp∧q
TTT
TFF
FTF
FFF

3. Disjunction(析取) — p∨q ("p OR q")

This is the inclusive or (兼或): p∨q is true when at least one of p, q is true.

pqp∨q
TTT
TFT
FTT
FFF

4. Exclusive Or(异或) — p⊕q ("p XOR q")

p⊕q is true when exactly one of p, q is true (but not both).

pqp⊕q
TTF
TFT
FTT
FFF

5. Conditional Statement(条件命题/蕴含) — p→q ("if p, then q")

This is the most subtle connective. p→q is false only when p is true and q is false.

pqp→q
TTT
TFF
FTT
FFT
  • p is called the hypothesis (假设) / antecedent (前件) / premise (前提).
  • q 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 p→q in English:

  • "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 p→q:

NameFormEquivalent to
Converse(逆命题)q→p—
Inverse(反命题)¬p→¬q—
Contrapositive(逆否命题)¬q→¬pp→q ✓

p→q is logically equivalent to its contrapositive ¬q→¬p, but not to its converse or inverse.

6. Biconditional Statement(双条件命题) — p↔q ("p if and only if q", "p iff q")

p↔q is true when p and q have the same truth value.

pqp↔q
TTT
TFF
FTF
FFT

Note: p↔q≡(p→q)∧(q→p)

Precedence of Logical Operators(优先级) ​

From highest to lowest:

OperatorPrecedence
¬1 (highest)
∧2
∨3
→4
↔5 (lowest)

So p∧q∨r means (p∧q)∨r.

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:

  1. Identify atomic propositions and assign variables.
  2. Determine logical connectives.

Example: "You can access the Internet from campus only if you are a student or you pay the fee."

  • Let a = "you can access the Internet from campus"
  • Let s = "you are a student"
  • Let p = "you pay the fee"
  • Result: a→(s∨p)

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 p≡q.

Key Equivalences Table ​

Law NameEquivalences
Identity laws (恒等律)p∧T≡p, p∨F≡p
Domination laws (支配律)p∨T≡T, p∧F≡F
Idempotent laws (幂等律)p∨p≡p, p∧p≡p
Double Negation¬(¬p)≡p
Commutative laws (交换律)p∨q≡q∨p, p∧q≡q∧p
Associative laws (结合律)(p∨q)∨r≡p∨(q∨r)
Distributive laws (分配律)p∨(q∧r)≡(p∨q)∧(p∨r)
De Morgan's laws (德摩根律)¬(p∧q)≡¬p∨¬q, ¬(p∨q)≡¬p∧¬q
Absorption laws (吸收律)p∨(p∧q)≡p, p∧(p∨q)≡p
Complement laws (互补律)p∨¬p≡T, p∧¬p≡F

Useful implications:

  • p→q≡¬p∨q
  • p↔q≡(p→q)∧(q→p)

Constructing Equivalence Proofs ​

To show A≡B, build a chain of equivalences A≡⋯≡B, applying known laws at each step.

Example: Show ¬(p→q)≡p∧¬q:

¬(p→q)≡¬(¬p∨q)≡p∧¬q

Tautology (重言式/永真式): always true.
Contradiction (矛盾式/永假式): always false.
Contingency (可满足式): truth depends on variable values.

Dual(对偶式) ​

The dual S∗ of a formula S (containing only ∧,∨,¬) is obtained by:

  • Replacing each ∧ with ∨ and vice versa
  • Replacing each T with F and vice versa

Theorem: If S≡T, then S∗≡T∗.

Example: S=(p∧¬q)∨r∨T, so S∗=(p∨¬q)∧r∧F.

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:

  1. Each propositional variable and T,F are formulas.
  2. If A is a formula, so is (¬A).
  3. If A and B are formulas, so are (A∧B), (A∨B), (A→B), (A↔B).
  4. 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., p and ¬p are literals.

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.

DNF form: (l11∧⋯∧l1n)∨⋯∨(lk1∧⋯∧lkm)

Example: (p∧q)∨(p∧¬q)∨¬p is in DNF.

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.

CNF form: (l11∨⋯∨l1n)∧⋯∧(lk1∨⋯∧lkm)

How to convert a formula to CNF/DNF:

  1. Eliminate → and ↔ using equivalences.
  2. Move ¬ inward: apply De Morgan's laws and double negation until ¬ only precedes atoms.
  3. Use distributive laws to expand to the desired form.

Example: Convert ¬((p∧¬q)∨¬r) to CNF:

¬(p∧¬q)∧(¬¬r)[De Morgan]¬(p∧¬q)∧r[Double neg](¬p∨q)∧r[De Morgan](¬p∨r)∧(q∨r)[Distributive]

Minterms(极小项/最小项) ​

A minterm (极小项) is a conjunction of literals in which each variable appears exactly once (positive or negative).

For n variables there are 2n distinct minterms. We write mj for the minterm that is true when the binary representation of j gives the values of the variables.

For variables p,q,r:

jminterm mjtrue when
0¬p∧¬q∧¬rp=F,q=F,r=F
1¬p∧¬q∧rp=F,q=F,r=T
2¬p∧q∧¬r
3¬p∧q∧r
4p∧¬q∧¬r
5p∧¬q∧r
6p∧q∧¬r
7p∧q∧rp=T,q=T,r=T

Properties of minterms:

  1. Each minterm is true for exactly one assignment.
  2. The conjunction of two different minterms is always F.
  3. The disjunction of all minterms is T.

Full Disjunctive Normal Form(主析取范式) ​

The full disjunctive normal form (主析取范式) of a function f is the disjunction of all minterms for which f is true.

Notation: f=∑m(j,k,…,l)

How to find from a truth table: select the minterms corresponding to rows where the function is true.

Example: If f is true for assignments (T,T,T), (T,F,T), (F,F,T):

f=m7∨m5∨m1=∑m(1,5,7)

Maxterms(极大项)and Full CNF(主合取范式) ​

A maxterm Mi=¬mi is a disjunction of literals.

Converting between forms: if f=∑m(j,k,…), let g be the disjunction of all remaining minterms.
Then f=∏M(indices not in f) — the full conjunctive normal form (主合取范式).


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 P(x) becomes a proposition when variables are bound. E.g., $P(x) = $ "x > 0". Then P(3) is true, P(−1) is false.

Quantifiers(量词) ​

Universal Quantifier(全称量词) ∀: "∀xP(x)" means "For all x in the domain, P(x)."

  • True when P(x) is true for every element of the domain.
  • False when there exists at least one counterexample (反例) c for which P(c) is false.
  • When domain ={x1,…,xn}: ∀xP(x)≡P(x1)∧P(x2)∧⋯∧P(xn)

Existential Quantifier(存在量词) ∃: "∃xP(x)" means "There exists an x such that P(x)."

  • True when P(x) is true for at least one element.
  • When domain ={x1,…,xn}: ∃xP(x)≡P(x1)∨P(x2)∨⋯∨P(xn)

Uniqueness Quantifier(唯一性量词) ∃!: "∃!xP(x)" means "There is exactly one x such that P(x)."

This can be expressed as: ∃x(P(x)∧∀y(P(y)→y=x))

Precedence: quantifiers have higher precedence than all logical operators.
So ∀xP(x)∨Q(x) means (∀xP(x))∨Q(x).

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 ​

¬∀xP(x)≡∃x¬P(x)¬∃xP(x)≡∀x¬P(x)

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" → ∀x(S(x)→P(x))
  • "Some/there exists an S that is P" → ∃x(S(x)∧P(x))
    (Warning: do NOT use → with ∃, it has a different meaning!)

Example: "No CS student is a Math student."

∀x(C(x)→¬E(x))or equivalently¬∃x(C(x)∧E(x))

Logical Equivalences with Quantifiers ​

If x does not occur in A:

∀xP(x)∨A≡∀x(P(x)∨A)∃xP(x)∧A≡∃x(P(x)∧A)

Section 1.5 — Nested Quantifiers(嵌套量词) ​

Nested quantifiers (嵌套量词): one quantifier is within the scope of another.

Example: "Every real number has an additive inverse":

∀x∃y(x+y=0)

Order of Quantifiers Matters! ​

∀x∃yP(x,y): "For each x, there is a y..." — the y may depend on x.
∃y∀xP(x,y): "There is one y that works for all x" — much stronger.

These are generally NOT equivalent.

StatementWhen trueWhen false
∀x∀yP(x,y)P(x,y) true for every pairSome pair makes P false
∀x∃yP(x,y)For each x, some y worksSome x has no working y
∃x∀yP(x,y)One x works for all yEvery x fails for some y
∃x∃yP(x,y)Some pair satisfies PP false for every pair

Negating Nested Quantifiers ​

Apply De Morgan's laws repeatedly, moving ¬ inward:

¬∀x∃yP(x,y)≡∃x∀y¬P(x,y)

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., (p1∧p2∧⋯∧pn)→q is a tautology.

Rules of Inference for Propositions ​

Rule NameFormTautology
Modus Ponens (假言推理)p, p→q ⊢ q(p∧(p→q))→q
Modus Tollens (取拒式)¬q, p→q ⊢ ¬p(¬q∧(p→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∨r, ¬p∨q ⊢ q∨r

Rules of Inference for Quantified Statements ​

RuleName
∀xP(x) ⊢ P(c) for arbitrary cUniversal Instantiation (UI) (全称实例)
P(c) for arbitrary c ⊢ ∀xP(x)Universal Generalization (UG) (全称引入)
∃xP(x) ⊢ P(c) for some element cExistential Instantiation (EI) (存在实例)
P(c) for some c ⊢ ∃xP(x)Existential Generalization (EG) (存在引入)

Universal Modus Ponens (全称假言推理) combines UI and Modus Ponens:

∀x(P(x)→Q(x)),P(a)⊢Q(a)

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 ​

n is even if ∃k(n=2k).
n is odd if ∃k(n=2k+1).
Every integer is either even or odd (but not both).

A real number r is rational if r=p/q for some integers p,q with q≠0.

Proof Methods for p→q ​

1. Direct Proof(直接证明法): Assume p is true, then show q follows.

Example: Prove "if n is odd, then n2 is odd."
Proof: Assume n=2k+1. Then n2=4k2+4k+1=2(2k2+2k)+1, which is odd. ◻

2. Proof by Contraposition(反证法/逆否证明): Prove ¬q→¬p instead (equivalent to p→q).

Example: Prove "if n2 is odd, then n is odd."
Proof: (Contrapositive) Assume n is even, so n=2k. Then n2=4k2=2(2k2) is even. ◻

3. Proof by Contradiction(归谬证明法): Assume ¬p (or ¬q) and derive a contradiction.

Example: Prove 2 is irrational.
Proof: Assume 2=a/b in lowest terms. Then 2=a2/b2, so a2=2b2, meaning a is even. Write a=2c, then 4c2=2b2, so b2=2c2, meaning b is even. But then a and b share a factor of 2, contradicting "lowest terms." ◻

Example: Prove there is no largest prime.
Proof: Assume primes p1,p2,…,pn are all primes. Let q=p1p2⋯pn+1. None of p1,…,pn divides q (remainder 1 each time). So q is either prime itself or has a prime factor not in the list — contradiction. ◻

4. Trivial Proof(平凡证明): If q is known to be true, then p→q is true.

5. Vacuous Proof(空证明): If p is known to be false, then p→q is true.

Biconditional Proofs ​

To prove p↔q: prove p→q AND q→p separately.


Section 1.8 — More Proof Strategies ​

Proof by Cases(分情形证明) ​

Use the tautology (p1∨p2∨⋯∨pn)→q≡[(p1→q)∧(p2→q)∧⋯∧(pn→q)].

Prove q is true in each possible case.

Without Loss of Generality (WLOG) (不失一般性): when cases are symmetric, prove one and state the other follows similarly.

Existence Proofs(存在性证明) ​

Prove ∃xP(x).

  • Constructive (构造性): find an explicit c such that P(c) is true.
    Example: 1729 = 103+93=123+13 (can be written as sum of cubes in two ways).

  • Nonconstructive (非构造性): prove existence indirectly (often by contradiction), without finding the element.
    Example: Prove ∃ irrational x,y such that xy is rational.
    Consider 22: if rational, done (x=y=2). If irrational, let x=22, y=2; then xy=2, rational. ◻

Disproof by Counterexample(反例否证) ​

To disprove ∀xP(x), find one c such that P(c) is false.

Uniqueness Proofs(唯一性证明) ​

To prove ∃!xP(x):

  1. Existence: find an element x satisfying P(x).
  2. Uniqueness: show that if y≠x also satisfies P, we get a contradiction.

Proof Strategies ​

  • Forward reasoning: start from axioms/premises, derive conclusion.
  • Backward reasoning: to prove q, find a statement p with p→q that you can prove.
  • If direct proof fails, try contrapositive or contradiction.

Open Problems (undecided conjectures) ​

  • Fermat's Last Theorem (费马大定理): xn+yn=zn has no integer solutions with xyz≠0 for n>2. (Proved by Andrew Wiles, 1990s)
  • Goldbach's Conjecture (哥德巴赫猜想): every even integer >2 is the sum of two primes. (Still open)
  • 3x+1 Conjecture (Collatz): repeatedly applying x↦x/2 (if even) or x↦3x+1 (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: a∈A means a is an element of A; a∉A means a is not.

Describing Sets ​

Roster method (列举法): list elements explicitly.
S={a,b,c,d}, O={1,3,5,7,9}

Set-builder notation (描述法): S={x∣P(x)} — all x satisfying property P.
O={x∈Z+∣x is odd and x<10}

Important Sets ​

SymbolSet
NNatural numbers {0,1,2,3,…}
ZIntegers {…,−2,−1,0,1,2,…}
Z+Positive integers {1,2,3,…}
QRational numbers
RReal numbers
CComplex numbers

Universal set (全集) U: contains all objects under consideration.
Empty set (空集) ∅ (also written {}): contains no elements.

Russell's Paradox (罗素悖论): Let S={x∣x∉x}. Is S∈S? Either answer leads to contradiction. This motivates axiomatic set theory.

Subsets, Equality, Power Sets ​

  • A⊆B (subset, 子集): every element of A is also in B.
    Equivalently, ∀x(x∈A→x∈B).
  • A=B (equality): A⊆B and B⊆A.
  • A⊂B (proper subset, 真子集): A⊆B but A≠B.
  • ∅⊆S for every set S; S⊆S for every set S.

Cardinality (基数) |A|: the number of distinct elements in a finite set A.
|∅|=0, |{1,2,3}|=3, |{∅}|=1.

Power set (幂集) P(A): the set of all subsets of A.
If |A|=n, then |P(A)|=2n.
Example: A={a,b}, P(A)={∅,{a},{b},{a,b}}.

Tuples and Cartesian Product ​

An ordered n-tuple (有序n元组) (a1,a2,…,an): an ordered collection where position matters.
2-tuples are called ordered pairs (序偶).

Cartesian product (笛卡尔积) A×B={(a,b)∣a∈A and b∈B}.

Example: A={a,b}, B={1,2,3}:

A×B={(a,1),(a,2),(a,3),(b,1),(b,2),(b,3)}

A relation (关系) from A to B is a subset of A×B (more in Chapter 9).


Section 2.2 — Set Operations(集合运算) ​

Set operations are analogous to logical operations (Boolean Algebra).

OperationDefinitionAnalogy
Union (并集) A∪B{x∣x∈A∨x∈B}∨
Intersection (交集) A∩B{x∣x∈A∧x∈B}∧
Complement (补集) A¯{x∈U∣x∉A}¬
Difference (差集) A−B{x∣x∈A∧x∉B}=A∩B¯—
Symmetric Difference (对称差) A⊕B(A−B)∪(B−A)⊕

If A∩B=∅, A and B are disjoint (不相交).

Inclusion-Exclusion (容斥原理): |A∪B|=|A|+|B|−|A∩B|

Set Identities ​

Mirror image of logical equivalences — just replace ∧↔∩, ∨↔∪, ¬↔⋅―, T↔U, F↔∅.

Key: De Morgan's Laws for sets:

A∪B―=A¯∩B¯,A∩B―=A¯∪B¯

Proving Set Identities ​

  1. Element-chasing: show each side is a subset of the other.
  2. Set-builder + propositional logic: convert to logical statements and use known equivalences.
  3. Membership table: like a truth table but with "in set" (1) / "not in set" (0).

Computer Representation of Sets ​

Represent subset A of U={u1,…,un} as a bit string of length n:

  • Bit i = 1 if ui∈A, else 0.

Set operations become bitwise operations:

  • Union → bitwise OR
  • Intersection → bitwise AND
  • Complement → bitwise NOT

Section 2.3 — Functions(函数) ​

Definition: A function f:A→B assigns to each element of A exactly one element of B.

  • A = domain (定义域)
  • B = codomain (陪域)
  • f(a)=b: b is the image (像) of a; a is the preimage (原像) of b
  • Range (值域): the set of all images {f(a)∣a∈A}⊆B

Formally: ∀a(a∈A→∃!b(b∈B∧f(a)=b))

Types of Functions ​

Injection(单射) (one-to-one): f(a)=f(b)⇒a=b for all a,b∈A.
Different inputs give different outputs.

Surjection(满射) (onto): for every b∈B, there exists a∈A with f(a)=b.
Every element of the codomain is an image.

Bijection(双射) (one-to-one correspondence): both injective AND surjective.

Inverse Functions(反函数) ​

If f:A→B is a bijection, its inverse f−1:B→A is defined by f−1(b)=a iff f(a)=b.
Inverse exists if and only if f is a bijection.

Function Composition(函数复合) ​

Given g:A→B and f:B→C, the composition (f∘g):A→C is defined by (f∘g)(x)=f(g(x)).

Note: f∘g≠g∘f in general.

Floor and Ceiling Functions ​

  • Floor (下取整) ⌊x⌋: largest integer ≤x.
  • Ceiling (上取整) ⌈x⌉: smallest integer ≥x.

Examples: ⌊2.7⌋=2, ⌈2.1⌉=3, ⌊−2.7⌋=−3.

Useful identity: ⌊2x⌋=⌊x⌋+⌊x+1/2⌋ (proof by cases on {x}<1/2 vs ≥1/2).

Factorial(阶乘) ​

f(n)=n!=1⋅2⋅3⋯n, with 0!=1.

Stirling's approximation: n!≈2πn(n/e)n.


Section 2.4 — Sequences and Summations(序列与求和) ​

A sequence (序列) is a function from a subset of integers to a set S. We write {an}.

Geometric progression (等比数列/级数): a,ar,ar2,ar3,… with initial term a and common ratio (公比) r.

Arithmetic progression (等差数列): a,a+d,a+2d,… with initial term a and common difference (公差) d.

Recurrence Relations(递推关系) ​

A recurrence relation (递推关系) expresses an in terms of previous terms.

Fibonacci sequence (斐波那契数列): f0=0,f1=1,fn=fn−1+fn−2.
Values: 0,1,1,2,3,5,8,13,21,…

Solving a recurrence: find a closed formula (闭公式). Method: iteration (forward or backward substitution).

Example: an=an−1+3, a1=2:

an=2+3(n−1)

Financial application: compound interest. Pn=(1.11)n⋅P0. With P0=10000 and 30 years: P30≈$228,993.

Summations(求和) ​

∑j=mnaj=am+am+1+⋯+an

Geometric series: ∑j=0narj=a(rn+1−1)r−1 for r≠1; =a(n+1) for r=1.

Useful formulas:

SumFormula
∑k=1nkn(n+1)2
∑k=1nk2n(n+1)(2n+1)6
∑k=1nk3(n(n+1)2)2
∑k=0nrk (r≠1)rn+1−1r−1

Section 2.5 — Cardinality of Sets(集合的基数) ​

Definition: |A|=|B| iff there exists a bijection from A to B.
|A|≤|B| iff there exists an injection from A to B.

Countable set (可数集): either finite, or has the same cardinality as Z+.
The cardinality of a countably infinite set is ℵ0 ("aleph null").

An infinite set is countable iff its elements can be listed as a sequence a1,a2,a3,…

Uncountable set (不可数集): infinite but not countable (e.g., R).

Showing Sets are Countably Infinite ​

  • Positive even integers E: bijection f(n)=2n from Z+ to E. ✓
  • Integers Z: list as 0,1,−1,2,−2,3,−3,… ✓
  • Positive rationals Q+: use the diagonal enumeration of Z+×Z+ (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:

  1. No infinite set has smaller cardinality than a countable set.
  2. Union of finitely many countable sets is countable.
  3. 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 n to room n+1 for all n, freeing room 1.

Cantor Diagonalization(康托尔对角线论证) ​

Theorem: The set of real numbers in (0,1) is uncountable.

Proof: Assume A=(0,1) is countable. List all elements: r1,r2,r3,… in decimal form:

r1=0.d11d12d13…r2=0.d21d22d23…r3=0.d31d32d33…

Construct x=0.x1x2x3… where:

xi={3if dii≠34if dii=3

Then x differs from every ri in at least the i-th decimal digit, so x∉{r1,r2,…}. Contradiction! ◻

Corollary: |R|=|(0,1)|=ℵ1>ℵ0.

The Continuum Hypothesis (连续统假设) asserts there is no cardinality α with ℵ0<α<ℵ1. (Proved independent of ZFC axioms by Gödel and Cohen.)

Schröder-Bernstein Theorem: If |A|≤|B| and |B|≤|A|, then |A|=|B|.

Cantor's Theorem: |P(A)|>|A| for any set A — the power set always has strictly greater cardinality.

Computability: Since the set of Java programs is countable but the set of functions Z+→Z+ is uncountable, there must exist uncomputable functions (不可计算函数).


Section 2.6 — Matrices(矩阵) ​

A matrix (矩阵) is a rectangular array of numbers. An m×n matrix has m rows and n columns.

Matrix Arithmetic ​

Addition: A+B=[aij+bij] (matrices must have same dimensions).

Multiplication: AB=C where cij=∑k=1paikbkj (A is m×p, B is p×n).
Note: matrix multiplication is not commutative in general.

Identity matrix (单位矩阵) In: n×n matrix with 1's on diagonal, 0's elsewhere.
AIn=ImA=A for m×n matrix A.

Transpose (转置) At: rows and columns swapped, [At]ij=aji.

A matrix is symmetric (对称矩阵) if A=At.

Zero-One Matrices ​

A zero-one matrix has entries only 0 or 1.

Boolean operations:

  • Join A∨B: entry-wise OR.
  • Meet A∧B: entry-wise AND.
  • Boolean product A⊙B: cij=(ai1∧b1j)∨(ai2∧b2j)∨⋯∨(aik∧bkj).

Boolean powers: A[r]=A⊙A⊙⋯⊙A (r times), A[0]=In.


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: Θ(n) in the worst case.

Binary Search (二分搜索): requires a sorted list.

  1. Compare target with middle element.
  2. If equal, found. If target is larger, search upper half. If smaller, search lower half.
  3. 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 0

Complexity: Θ(log⁡n) — much better than linear search.

Sorting Algorithms ​

Bubble Sort (冒泡排序): make passes through the list, swapping adjacent elements that are out of order.
Worst-case complexity: Θ(n2).

Insertion Sort (插入排序): build the sorted array one element at a time.
Worst-case complexity: Θ(n2).

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 H(P,I) exists. Construct K(P): if H(P,P) says "loops forever," K(P) halts; if H(P,P) says "halts," K(P) loops. Then K(K) leads to contradiction. ∴ H cannot exist.

The halting problem is unsolvable (不可解的).


Section 3.2 — The Growth of Functions ​

Big-O Notation(大O记号) ​

Definition: f(x) is O(g(x)) if there exist constants C and k such that |f(x)|≤C|g(x)| whenever x>k.

  • C and k are called witnesses (凭证).
  • Big-O gives an upper bound on the growth rate.
  • We say "g asymptotically dominates f."

Example: Show f(x)=x2+2x+1 is O(x2).
When x>1: x2+2x+1≤x2+2x2+x2=4x2. Take C=4, k=1.

Polynomial: If f(x)=anxn+⋯+a0 with an≠0, then f(x) is O(xn).
(The leading term dominates.)

Common Big-O estimates:

  • ∑j=1nj is O(n2)
  • n! is O(nn)
  • log⁡(n!) is O(nlog⁡n)

Big-Omega Notation(大Ω记号) ​

f(x) is Ω(g(x)) if there exist C,k such that |f(x)|≥C|g(x)| for all x>k.

Big-Omega gives a lower bound. Note: f(x) is Ω(g(x)) iff g(x) is O(f(x)).

Big-Theta Notation(大Θ记号) ​

f(x) is Θ(g(x)) if f(x) is O(g(x)) and f(x) is Ω(g(x)).

Equivalently, there exist C1,C2,k such that C1|g(x)|≤|f(x)|≤C2|g(x)| for x>k.

  • f and g are said to be of the same order.
  • Example: ∑j=1nj=n(n+1)2 is Θ(n2).

Useful Hierarchies ​

In order of growth (slowest to fastest):

1<log⁡log⁡n<log⁡n<(log⁡n)c<nd<nlog⁡n<n2<n3<⋯<2n<3n<⋯<n!

Key inequalities:

  • (log n)c is O(nd) for any c,d>0 — but nd is NOT O((log⁡n)c).
  • nd is O(bn) for b>1 — but bn is NOT O(nd).
  • If c>b>1: bn is O(cn) 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 ​

AlgorithmWorst-caseNotes
Finding maximumΘ(n)
Linear searchΘ(n)
Binary searchΘ(log⁡n)sorted list required
Bubble sortΘ(n2)
Insertion sortΘ(n2)
Matrix multiplication (n×n)O(n3)
Boolean matrix productO(n3)bit operations

Binary modular exponentiation: computing bnmodm uses O((log⁡m)2log⁡n) bit operations — very efficient.

Complexity Classes ​

  • Class P (多项式时间类): problems solvable in polynomial time O(nk).
  • 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 n=50, computing 50! via brute force requires 1.5×1065 multiplications (≈ 5×1046 years), while Gaussian elimination needs ∼6×106 multiplications (∼6×10−5 seconds at 1011 ops/sec).


Chapter 4: Number Theory(数论) ​


Section 4.1 — Divisibility and Modular Arithmetic ​

Divisibility(整除性) ​

a∣b ("a divides b"): there exists integer c such that b=ac.
We say a is a factor (因子) or divisor (因数) of b; b is a multiple (倍数) of a.

Theorem (Properties of divisibility):
If a∣b and a∣c, then:

  1. a∣(b+c)
  2. a∣bc for any integer c
  3. If a∣b and b∣c, then a∣c

Corollary: a∣b and a∣c implies a∣(mb+nc) for any integers m,n.

Division Algorithm(带余除法) ​

For any integer a and positive integer d, there exist unique integers q and r with 0≤r<d such that:

a=dq+r
  • d = divisor,a = dividend(被除数),q=adivd = quotient(商),r=amodd = remainder(余数).

Examples:

  • 101=11×9+2, so 101div11=9, 101mod11=2.
  • −11=3×(−4)+1, so −11div3=−4, −11mod3=1.

Congruence(同余) ​

a≡b(modm): m∣(a−b). We say a is congruent to b modulo m.
Two integers are congruent mod m iff they have the same remainder when divided by m.

Theorem: a≡b(modm) iff a=b+km for some integer k.

Theorem (Congruence preserves operations):
If a≡b(modm) and c≡d(modm), then:

a+c≡b+d(modm),ac≡bd(modm)

Corollary:
(a+b)modm=((amodm)+(bmodm))modm
abmodm=((amodm)(bmodm))modm

Caution: Dividing both sides of a congruence by an integer does NOT always preserve congruence. (E.g., 6≡4(mod2) but 3≢2(mod2).)

Arithmetic Modulo m ​

Zm={0,1,…,m−1} with operations +m and ⋅m (modular addition and multiplication).

Properties: closure, associativity, commutativity, identity elements (0 for +m, 1 for ⋅m), distributivity.

Additive inverse of a in Zm is m−a.


Section 4.2 — Integer Representations ​

Any positive integer n can be uniquely expressed in base b (b>1):

n=akbk+ak−1bk−1+⋯+a1b+a0

where 0≤ai<b and ak≠0.

Key bases:

  • Binary (二进制): base 2, digits = {0,1}
  • Octal (八进制): base 8, digits = {0,…,7}
  • Hexadecimal (十六进制): base 16, digits = {0,…,9,A,…,F}

Conversions:

  • Decimal → base b: repeatedly divide by b; 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: O(n) bit operations for two n-bit integers.
Binary multiplication: O(n2) bit operations.

Binary Modular Exponentiation (快速模幂): to compute bnmodm:

  • Write n in binary: n=(ak−1⋯a1a0)2.
  • Use repeated squaring: compute b,b2,b4,…,b2k−1(modm).
  • Multiply the terms where ai=1.
  • Total: O((log⁡m)2log⁡n) bit operations.

Section 4.3 — Primes and GCD ​

Prime Numbers(质数) ​

A positive integer p>1 is prime (质数) if its only positive factors are 1 and p. Otherwise it is composite (合数).

Fundamental Theorem of Arithmetic (算术基本定理): Every positive integer >1 can be written uniquely as a product of primes (in nondecreasing order).

Sieve of Eratosthenes (埃拉托斯特尼筛法): to find all primes up to n:

  1. List all integers from 2 to n.
  2. Strike out all multiples of 2 (except 2 itself), then of 3, then of 5, etc.
  3. Stop when you've processed all primes up to n.

Theorem (Euclid): There are infinitely many primes.
Proof: Assume finite list p1,…,pn. Let q=p1p2⋯pn+1. Since q is not divisible by any pi, either q is prime or has a prime factor not in the list. Contradiction. ◻

Mersenne primes (梅森质数): primes of the form 2p−1 where p is prime.

Prime Number Theorem (质数定理): The number of primes ≤x is approximately x/ln⁡x.

Goldbach's Conjecture (哥德巴赫猜想): every even integer >2 is the sum of two primes. (Unproved.)

Twin Prime Conjecture (孪生质数猜想): infinitely many pairs of primes differing by 2. (Unproved, but Zhang Yitang proved there are infinitely many prime pairs differing by <70,000,000.)

Greatest Common Divisor (GCD)(最大公因数) ​

gcd(a,b) = largest integer d such that d∣a and d∣b.

Integers a and b are relatively prime (互质) if gcd(a,b)=1.

Using prime factorizations: if a=∏piai and b=∏pibi, then
gcd(a,b)=∏pimin(ai,bi).

Least Common Multiple (LCM) (最小公倍数): lcm(a,b)=∏pimax(ai,bi).

Key relationship: lcm(a,b)⋅gcd(a,b)=a⋅b.

Euclidean Algorithm(欧几里得算法) ​

Key lemma: gcd(a,b)=gcd(b,amodb).

Algorithm: repeatedly replace (a,b)←(b,amodb) until b=0; then gcd=a.

Example: gcd(287,91):

287=3⋅91+14⇒gcd(287,91)=gcd(91,14)91=6⋅14+7⇒gcd(91,14)=gcd(14,7)14=2⋅7+0⇒gcd(14,7)=7

Time complexity: O(log⁡b) divisions.

Bézout's Theorem(贝祖定理) ​

If a and b are positive integers, there exist integers s and t such that:

gcd(a,b)=sa+tb

s and t are called Bézout coefficients (贝祖系数). The equation is Bézout's identity.

Finding Bézout coefficients: work backwards through the Euclidean algorithm.

Example: Express gcd(252,198)=18 as a linear combination:

  • 252=1⋅198+54
  • 198=3⋅54+36
  • 54=1⋅36+18
  • 36=2⋅18

Working back: 18=54−1⋅36=54−(198−3⋅54)=4⋅54−198=4(252−198)−198=4⋅252−5⋅198.

Lemma: If gcd(a,b)=1 and a∣bc, then a∣c.
Lemma: If p is prime and p∣a1a2⋯an, then p∣ai for some i.


Section 4.4 — Solving Congruences & Cryptography ​

Linear Congruences(线性同余方程) ​

A linear congruence is of the form ax≡b(modm).

An inverse of a modulo m is an integer a¯ such that a¯a≡1(modm).

Theorem 1: If gcd(a,m)=1, then an inverse of a modulo m exists and is unique modulo m.

Proof: By Bézout's theorem, there exist s,t with sa+tm=1. Then sa≡1(modm), so s is an inverse.

Finding inverses: use the Euclidean algorithm to find Bézout coefficients.

Solving ax≡b(modm): Find inverse a¯ of a(modm), then x≡a¯b(modm).

Example: Solve 3x≡4(mod7).
Inverse of 3 mod 7: 7=2⋅3+1, so −2⋅3+1⋅7=1, hence a¯=−2≡5.
x≡(−2)(4)=−8≡6(mod7).

Chinese Remainder Theorem(中国剩余定理 / 秦九韶定理) ​

Theorem (CRT): Given pairwise relatively prime moduli m1,…,mn and arbitrary integers a1,…,an, the system:

x≡a1(modm1),x≡a2(modm2),…,x≡an(modmn)

has a unique solution modulo m=m1m2⋯mn.

Construction: Let Mk=m/mk. Find yk (inverse of Mk mod mk). Then:

x=a1M1y1+a2M2y2+⋯+anMnyn(modm)

Sun-Tsu's problem: x≡2(mod3), x≡3(mod5), x≡2(mod7).
m=105, M1=35,M2=21,M3=15.
Inverses: y1=2 (since 35⋅2=70≡1(mod3)), y2=1, y3=1.
x=2⋅35⋅2+3⋅21⋅1+2⋅15⋅1=140+63+30=233≡23(mod105).

Back Substitution is an alternative method: rewrite first congruence as equality, substitute into next, etc.

Fermat's Little Theorem(费马小定理) ​

Theorem: If p is prime and p∤a, then ap−1≡1(modp).
Equivalently, ap≡a(modp) for every integer a.

Example: Find 7222mod11.
By FLT: 710≡1(mod11). Then 7222=722⋅10+2=(710)22⋅72≡122⋅49≡5(mod11).

Euler's Theorem (欧拉定理) generalizes this: if gcd(a,n)=1, then aϕ(n)≡1(modn), where ϕ(n) is Euler's totient function (the number of integers ≤n relatively prime to n).

Pseudoprimes(伪质数) ​

If 2n−1≡1(modn) but n is composite, n is a pseudoprime to the base 2.

A Carmichael number (卡米切尔数) satisfies bn−1≡1(modn) for all b with gcd(b,n)=1, yet is composite. Example: 561=3⋅11⋅17.

Primitive Roots(原根) ​

A primitive root modulo a prime p is an integer r∈Zp∗ such that every nonzero element of Zp is a power of r (mod p).

Every prime p has a primitive root.

g is a primitive root mod m iff the multiplicative order of g mod m equals ϕ(m).

Discrete Logarithm(离散对数) ​

If r is a primitive root mod p and re≡a(modp), then e is the discrete logarithm of a modulo p to base r, written logr⁡a=e.

Asymmetry: Given r and e, computing a=remodp is easy. But given r and a, finding e (discrete log) is believed to be computationally hard — no polynomial-time algorithm is known. This hardness underpins many cryptographic protocols.


Section 4.5 — Applications of Number Theory ​

Hashing Functions(哈希函数) ​

A hashing function h assigns memory location h(k) to a record with key k.

Common: h(k)=kmodm (maps to {0,1,…,m−1}).

Collision (碰撞): when two keys map to the same location. Resolved by linear probing: h(k,i)=(h(k)+i)modm.

Pseudorandom Numbers(伪随机数) ​

Linear congruential method: given modulus m, multiplier a, increment c, seed x0:

xn+1=(axn+c)modm

The sequence is periodic with period at most m.

Example: m=9,a=7,c=4,x0=3: generates 3,7,8,6,1,2,0,4,5,3,… (period 9).

Check Digits(校验码) ​

UPC (Universal Product Code): 12-digit code. Check digit x12 satisfies:

3x1+x2+3x3+⋯+3x11+x12≡0(mod10)

ISBN-10: 10-digit code. Check digit x10 satisfies:

∑i=110i⋅xi≡0(mod11)(x10 may be 10 = X)

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):

  1. Choose two large primes p and q.
  2. Compute n=pq and ϕ(n)=(p−1)(q−1).
  3. Choose e with gcd(e,ϕ(n))=1 (public exponent).
  4. Find d = inverse of e modulo ϕ(n) (private key).

Public key: (n,e). Private key (解密密钥): d.

Encryption: C=Memodn.
Decryption: M=Cdmodn.

Why it works: Cd=Med=Mkϕ(n)+1=(Mϕ(n))k⋅M≡1k⋅M=M(modn) (by Euler's Theorem, assuming gcd(M,n)=1).

Security: relies on the fact that factoring large n=pq is computationally infeasible (no known efficient algorithm for numbers with hundreds of digits).

Example: Key (2537,13), 2537=43×59.
Encrypt "STOP" = 1819 1415:
C1=181913mod2537=2081, C2=141513mod2537=2182.
Ciphertext: 2081 2182.

Decrypt with d=937:
M=C937mod2537.

Diffie-Hellman Key Exchange(密钥交换协议) ​

Alice and Bob agree on prime p and primitive root a.

  • Alice chooses secret k1, sends ak1modp to Bob.
  • Bob chooses secret k2, sends ak2modp to Alice.
  • Shared secret: (ak2)k1modp=(ak1)k2modp=ak1k2modp.

Security: finding k1 from ak1modp is the discrete logarithm problem — believed hard.

Digital Signatures(数字签名) ​

To prove a message came from Alice:

  • Alice encrypts (signs) with her private key d: S=Mdmodn.
  • Anyone can verify with Alice's public key e: Se≡M(modn).

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 ​

ConceptFormula
Contrapositivep→q≡¬q→¬p
De Morgan (prop)¬(p∧q)≡¬p∨¬q
De Morgan (quant)¬∀xP(x)≡∃x¬P(x)
Conditionalp→q≡¬p∨q
Biconditionalp↔q≡(p→q)∧(q→p)

Chapter 2 — Sets and Functions ​

ConceptFormula
Power set size$
Inclusion-Exclusion$
Geometric series∑k=0nrk=rn+1−1r−1
Sum of first n integersn(n+1)2

Chapter 3 — Algorithms ​

AlgorithmComplexity
Binary searchΘ(log⁡n)
Bubble/Insertion sortΘ(n2)
Matrix multiplyO(n3)

Chapter 4 — Number Theory ​

ConceptFormula
Division algorithma=dq+r, 0≤r<d
Congruencea≡b(modm) iff m∣(a−b)
Bézout's identitygcd(a,b)=sa+tb
lcm-gcd relationlcm(a,b)⋅gcd(a,b)=ab
Fermat's Little Thmap−1≡1(modp) for prime p, p∤a
Euler's Theoremaϕ(n)≡1(modn) for gcd(a,n)=1
RSA encryptC=Memodn
RSA decryptM=Cdmodn

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