การอุปถัมภ์และการเรียกซ้ำ
แนะนำใหม่ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| induction/ɪnˈdʌkʃn/ | การอุปนัยทางคณิตศาสตร์ |
| base case/beɪs keɪs/ | กรณีฐาน |
| inductive step/ɪnˈdʌktɪv step/ | ขั้นตอนอุปนัย |
| induction hypothesis/ɪnˈdʌkʃn haɪˈpɒθəsɪs/ | สมมติฐานอุปนัย |
| strong induction/strɒŋ ɪnˈdʌkʃn/ | การอุปนัยแบบเข้มงวด |
| recursive definition/rɪˈkɜːsɪv ˌdefɪˈnɪʃn/ | นิยามแบบวนซ้ำ |
A loop you can trust for every n
- A loop adds $1 + 2 + \dots + n$. You test $n = 1, 2, 3$ and it matches $\frac{n(n+1)}{2}$. But a test only covers the cases you ran; what about $n = 10^9$?
- Induction 数学归纳法 proves a claim for every $n$ at once. It is how loops and recursive code are proved correct.
The ladder: base and step
- To prove $P(n)$ for all $n \ge n_0$: check the base case 基础情形 $P(n_0)$ by hand. Then prove the inductive step 归纳步骤: if $P(k)$ holds, then $P(k+1)$ holds.
- In the step, $P(k)$ is the induction hypothesis 归纳假设. Base plus step reach every rung: $P(n_0)$ gives $P(n_0 + 1)$, which gives $P(n_0 + 2)$, and so on.

เรียงลำดับส่วนประกอบของการพิสูจน์ด้วยการอุปนัย
ความยาก 3/5 · 200 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ข้อความอ้าง, ขั้นแรก, การปีนหนึ่งขั้นที่ทำได้จากขั้นใดก็ได้, แล้วสรุปผล
Proving the sum formula
Claim: $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$ for all $n \ge 1$.
Base, $n = 1$: the left side is 1 and the right side is $\frac{1 \cdot 2}{2} = 1$.
Step: assume $\sum_{i=1}^{k} i = \frac{k(k+1)}{2}$. Then
which is the formula at $n = k + 1$.
- Mark the line where the hypothesis is used. A step that never uses $P(k)$ has proved nothing about the chain.
ในขั้นตอนสำหรับ Σi = n(n+1)/2, ผลรวมจนถึง k + 1 จะถูกเขียนใหม่เป็น —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
แยกพจน์สุดท้าย: สมมติฐานครอบคลุม 1 ถึง k, แล้วเพิ่ม k + 1. ต้องลดรูปก่อนจึงจะได้ (k+1)(k+2)/2.
ใช้สูตรหาค่า 1 + 2 + … + 100
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
100 × 101 ÷ 2 = 5050.
Strong induction
- Strong induction 强归纳法 assumes $P(n_0), \dots, P(k)$, every rung below, not just $P(k)$. Use it when $k + 1$ depends on a case further down.
- Example: every integer $n \ge 2$ is a product of primes. If $k + 1$ is not prime, $k + 1 = ab$ with $2 \le a, b \le k$, and both $a$ and $b$ are covered by the hypothesis.
การพิสูจน์ว่าทุก n ≥ 2 สามารถแยกตัวประกอบเป็นจำนวนเฉพาะได้ ต้องใช้การอุปนัยแบบเข้ม เพราะ k + 1 = ab ขึ้นอยู่กับกรณีที่มีค่าน้อยกว่า k
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ตัวประกอบ a และ b อาจมีขนาดตั้งแต่ 2 ถึง k ดังนั้นสมมติฐานต้องครอบคลุมทุกขั้นด้านล่าง ไม่ใช่แค่ k เท่านั้น
Recursion is induction built downwards
- A recursive definition 递归定义 gives a base value and a rule using smaller cases: $0! = 1$ and $n! = n \cdot (n-1)!$. It is the same ladder, built instead of climbed.
- To prove a recursive function correct, induct on the input size: the base case of the code is the base case of the proof, and the recursive call is the hypothesis.
ใช้ 0! = 1 และ n! = n · (n−1)!, ค่าของ 5! คืออะไร?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
5 × 4 × 3 × 2 × 1 × 1 = 120; การทำซ้ำจะหยุดที่ค่าพื้นฐาน 0! = 1
Catching a faulty proof
- "All horses are the same colour." The step removes a different horse from a group of $k + 1$ to get two groups of $k$ that overlap, so all must match.
- At $k + 1 = 2$ the two groups are single horses with nothing in common. The step silently needs $k \ge 2$, and $P(2)$ was never proved, so the chain breaks there.
การพิสูจน์ "ม้าทุกตัวมีสีเดียวกัน" ล้มเหลวเพราะ —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ขั้นนี้ต้องการม้าที่ทับซ้อนกัน ซึ่งเกิดขึ้นก็ต่อเมื่อ k ≥ 2; P(2) ไม่เคยได้รับการพิสูจน์
Marks that slip away
- No base case. Hypothesis plus step with no first rung is a ladder standing on air.
- Hypothesis never used. Write "by the hypothesis" at the exact line.
- Assuming $P(k+1)$. Using the goal to prove itself is circular.
- Step that fails for small $k$. Check the smallest case the step must cover.
You've got it
- Induction = base case $P(n_0)$ + step $P(k) \Rightarrow P(k+1)$, with the hypothesis used.
| Induction | Ordinary | Strong |
|---|---|---|
| The step assumes | $P(k)$ | every case up to $P(k)$ |
| Example | the sum formula | prime factors |
-
Use strong induction when $k + 1$ needs a case further down than $k$.
-
Recursion defines downwards; proving recursive code correct is induction on input size.
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้