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(合取)pq ("p AND q")

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

pqpq
TTT
TFF
FTF
FFF

3. Disjunction(析取)pq ("p OR q")

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

pqpq
TTT
TFT
FTT
FFF

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

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

pqpq
TTF
TFT
FTT
FFF

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

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

pqpq
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 pq 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 pq:

NameFormEquivalent to
Converse(逆命题)qp
Inverse(反命题)¬p¬q
Contrapositive(逆否命题)¬q¬ppq

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

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

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

pqpq
TTT
TFF
FTF
FFT

Note: pq(pq)(qp)

Precedence of Logical Operators(优先级)

From highest to lowest:

OperatorPrecedence
¬1 (highest)
2
3
4
5 (lowest)

So pqr means (pq)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(sp)

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 pq.

Key Equivalences Table

Law NameEquivalences
Identity laws (恒等律)pTp, pFp
Domination laws (支配律)pTT, pFF
Idempotent laws (幂等律)ppp, ppp
Double Negation¬(¬p)p
Commutative laws (交换律)pqqp, pqqp
Associative laws (结合律)(pq)rp(qr)
Distributive laws (分配律)p(qr)(pq)(pr)
De Morgan's laws (德摩根律)¬(pq)¬p¬q, ¬(pq)¬p¬q
Absorption laws (吸收律)p(pq)p, p(pq)p
Complement laws (互补律)p¬pT, p¬pF

Useful implications:

  • pq¬pq
  • pq(pq)(qp)

Constructing Equivalence Proofs

To show AB, build a chain of equivalences AB, applying known laws at each step.

Example: Show ¬(pq)p¬q:

¬(pq)¬(¬pq)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 ST, then ST.

Example: S=(p¬q)rT, so S=(p¬q)rF.

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 (AB), (AB), (AB), (AB).
  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: (l11l1n)(lk1lkm)

Example: (pq)(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: (l11l1n)(lk1lkm)

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](¬pq)r[De Morgan](¬pr)(qr)[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¬qrp=F,q=F,r=T
2¬pq¬r
3¬pqr
4p¬q¬r
5p¬qr
6pq¬r
7pqrp=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=m7m5m1=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)Ax(P(x)A)xP(x)Ax(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":

xy(x+y=0)

Order of Quantifiers Matters!

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

These are generally NOT equivalent.

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

Negating Nested Quantifiers

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

¬xyP(x,y)xy¬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., (p1p2pn)q is a tautology.

Rules of Inference for Propositions

Rule NameFormTautology
Modus Ponens (假言推理)p, pq q(p(pq))q
Modus Tollens (取拒式)¬q, pq ¬p(¬q(pq))¬p
Hypothetical Syllogism (假言三段论)pq, qr pr
Disjunctive Syllogism (析取三段论)pq, ¬p q
Addition (附加律)p pq
Simplification (化简律)pq p
Conjunction (合取律)p, q pq
Resolution (消解律)pr, ¬pq qr

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 q0.

Proof Methods for pq

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 pq).

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=p1p2pn+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 pq is true.

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

Biconditional Proofs

To prove pq: prove pq AND qp separately.


Section 1.8 — More Proof Strategies

Proof by Cases(分情形证明)

Use the tautology (p1p2pn)q[(p1q)(p2q)(pnq)].

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 yx 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 pq 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 xyz0 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 xx/2 (if even) or x3x+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: aA means a is an element of A; aA 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={xP(x)} — all x satisfying property P.
O={xZ+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={xxx}. Is SS? Either answer leads to contradiction. This motivates axiomatic set theory.

Subsets, Equality, Power Sets

  • AB (subset, 子集): every element of A is also in B.
    Equivalently, x(xAxB).
  • A=B (equality): AB and BA.
  • AB (proper subset, 真子集): AB but AB.
  • S for every set S; SS 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)aA and bB}.

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 (并集) AB{xxAxB}
Intersection (交集) AB{xxAxB}
Complement (补集) A¯{xUxA}¬
Difference (差集) AB{xxAxB}=AB¯
Symmetric Difference (对称差) AB(AB)(BA)

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

Inclusion-Exclusion (容斥原理): |AB|=|A|+|B||AB|

Set Identities

Mirror image of logical equivalences — just replace , , ¬, TU, F.

Key: De Morgan's Laws for sets:

AB=A¯B¯,AB=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 uiA, else 0.

Set operations become bitwise operations:

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

Section 2.3 — Functions(函数)

Definition: A function f:AB 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)aA}B

Formally: a(aA!b(bBf(a)=b))

Types of Functions

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

Surjection(满射) (onto): for every bB, there exists aA 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:AB is a bijection, its inverse f1:BA is defined by f1(b)=a iff f(a)=b.
Inverse exists if and only if f is a bijection.

Function Composition(函数复合)

Given g:AB and f:BC, the composition (fg):AC is defined by (fg)(x)=f(g(x)).

Note: fggf 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!=123n, 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=fn1+fn2.
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=an1+3, a1=2:

an=2+3(n1)

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

Summations(求和)

j=mnaj=am+am+1++an

Geometric series: j=0narj=a(rn+11)r1 for r1; =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 (r1)rn+11r1

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.d11d12d13r2=0.d21d22d23r3=0.d31d32d33

Construct x=0.x1x2x3 where:

xi={3if dii34if 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 AB: entry-wise OR.
  • Meet AB: entry-wise AND.
  • Boolean product AB: cij=(ai1b1j)(ai2b2j)(aikbkj).

Boolean powers: A[r]=AAA (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: Θ(logn) — 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+1x2+2x2+x2=4x2. Take C=4, k=1.

Polynomial: If f(x)=anxn++a0 with an0, 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(nlogn)

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<loglogn<logn<(logn)c<nd<nlogn<n2<n3<<2n<3n<<n!

Key inequalities:

  • (log n)c is O(nd) for any c,d>0 — but nd is NOT O((logn)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Θ(logn)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((logm)2logn) 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×105 seconds at 1011 ops/sec).


Chapter 4: Number Theory(数论)


Section 4.1 — Divisibility and Modular Arithmetic

Divisibility(整除性)

ab ("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 ab and ac, then:

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

Corollary: ab and ac 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 0r<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(同余)

ab(modm): m(ab). 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: ab(modm) iff a=b+km for some integer k.

Theorem (Congruence preserves operations):
If ab(modm) and cd(modm), then:

a+cb+d(modm),acbd(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., 64(mod2) but 32(mod2).)

Arithmetic Modulo m

Zm={0,1,,m1} 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 ma.


Section 4.2 — Integer Representations

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

n=akbk+ak1bk1++a1b+a0

where 0ai<b and ak0.

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=(ak1a1a0)2.
  • Use repeated squaring: compute b,b2,b4,,b2k1(modm).
  • Multiply the terms where ai=1.
  • Total: O((logm)2logn) 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=p1p2pn+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 2p1 where p is prime.

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

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 da and db.

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)=ab.

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=391+14gcd(287,91)=gcd(91,14)91=614+7gcd(91,14)=gcd(14,7)14=27+0gcd(14,7)=7

Time complexity: O(logb) 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=1198+54
  • 198=354+36
  • 54=136+18
  • 36=218

Working back: 18=54136=54(198354)=454198=4(252198)198=42525198.

Lemma: If gcd(a,b)=1 and abc, then ac.
Lemma: If p is prime and pa1a2an, then pai for some i.


Section 4.4 — Solving Congruences & Cryptography

Linear Congruences(线性同余方程)

A linear congruence is of the form axb(modm).

An inverse of a modulo m is an integer a¯ such that a¯a1(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 sa1(modm), so s is an inverse.

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

Solving axb(modm): Find inverse a¯ of a(modm), then xa¯b(modm).

Example: Solve 3x4(mod7).
Inverse of 3 mod 7: 7=23+1, so 23+17=1, hence a¯=25.
x(2)(4)=86(mod7).

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

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

xa1(modm1),xa2(modm2),,xan(modmn)

has a unique solution modulo m=m1m2mn.

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

x=a1M1y1+a2M2y2++anMnyn(modm)

Sun-Tsu's problem: x2(mod3), x3(mod5), x2(mod7).
m=105, M1=35,M2=21,M3=15.
Inverses: y1=2 (since 352=701(mod3)), y2=1, y3=1.
x=2352+3211+2151=140+63+30=23323(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 pa, then ap11(modp).
Equivalently, apa(modp) for every integer a.

Example: Find 7222mod11.
By FLT: 7101(mod11). Then 7222=72210+2=(710)2272122495(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 2n11(modn) but n is composite, n is a pseudoprime to the base 2.

A Carmichael number (卡米切尔数) satisfies bn11(modn) for all b with gcd(b,n)=1, yet is composite. Example: 561=31117.

Primitive Roots(原根)

A primitive root modulo a prime p is an integer rZp 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 rea(modp), then e is the discrete logarithm of a modulo p to base r, written logra=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,,m1}).

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+x120(mod10)

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

i=110ixi0(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)=(p1)(q1).
  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))kM1kM=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: SeM(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
Contrapositivepq¬q¬p
De Morgan (prop)¬(pq)¬p¬q
De Morgan (quant)¬xP(x)x¬P(x)
Conditionalpq¬pq
Biconditionalpq(pq)(qp)

Chapter 2 — Sets and Functions

ConceptFormula
Power set size$
Inclusion-Exclusion$
Geometric seriesk=0nrk=rn+11r1
Sum of first n integersn(n+1)2

Chapter 3 — Algorithms

AlgorithmComplexity
Binary searchΘ(logn)
Bubble/Insertion sortΘ(n2)
Matrix multiplyO(n3)

Chapter 4 — Number Theory

ConceptFormula
Division algorithma=dq+r, 0r<d
Congruenceab(modm) iff m(ab)
Bézout's identitygcd(a,b)=sa+tb
lcm-gcd relationlcm(a,b)gcd(a,b)=ab
Fermat's Little Thmap11(modp) for prime p, pa
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