Skip to content

Commit e84c5e6

Browse files
authored
Reviewed Induction. (Agda-zh#81)
1 parent a402c72 commit e84c5e6

File tree

4 files changed

+65
-53
lines changed

4 files changed

+65
-53
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ ifeq (,$$(findstring courses/,$$(in)))
4949
else
5050
# Fix links to the file itself (out/<filename> to out/<filepath>)
5151
./highlight.sh $$(subst ./,,$$(in)) --include-path=src/ --include-path=$$(subst ./,,$$(dir $$(in)))
52-
ruby scripts/fix-cjk.rb $$(out)
5352
endif
53+
ruby scripts/fix-cjk.rb $$(out)
5454
endef
5555

5656
$(foreach agda,$(AGDA),$(eval $(call AGDA_template,$(agda))))

scripts/fix-cjk.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env ruby
22
filename = ARGV[0]
3-
# puts "Fixing line breaks for #{filename}"
3+
puts "Fixing line breaks for #{filename}"
44
content = File.read(filename)
55
REDUNDANT_LINE_BREAK_REGEX = /([\p{Han}\p{Po}]+)\n([\p{Han}]+)/u
66
while content.gsub!(REDUNDANT_LINE_BREAK_REGEX, '\1\2')

src/plfa/Induction.lagda.md

+56-44
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Operators pop up all the time, and mathematicians have agreed
6767
on names for some of the most common properties.
6868
{:/}
6969

70-
运算符总是到处出现,而数学家们已经统一了一些最常见的性质的名称
70+
运算符随处可见,而数学家们统一了一些最常见的性质的名称
7171

7272
{::comment}
7373
* _Identity_. Operator `+` has left identity `0` if `0 + n ≡ n`, and
@@ -88,17 +88,17 @@ on names for some of the most common properties.
8888
`p`, and `q`.
8989
{:/}
9090

91-
* **幺元(Identity)**对于所有的 `n`,若 `0 + n ≡ n`,则 `+` 有左幺元 `0`
91+
* **幺元(Identity)**对于所有的 `n`,若 `0 + n ≡ n`,则 `+` 有左幺元 `0`
9292
`n + 0 ≡ n`,则 `+` 有右幺元 `0`。同时为左幺元和右幺元的值称简称幺元。
9393
幺元有时也称作**单位元(Unit)**
9494

95-
* **结合律(Associativity)**若括号的位置无关紧要,则称运算符 `+` 满足结合律,
95+
* **结合律(Associativity)**若括号的位置无关紧要,则称运算符 `+` 满足结合律,
9696
即对于所有的 `m``n``p`,有 `(m + n) + p ≡ m + (n + p)`
9797

98-
* **交换律(Commutativity)**若参数的顺序无关紧要,则称运算符 `+` 满足交换律,
98+
* **交换律(Commutativity)**若参数的顺序无关紧要,则称运算符 `+` 满足交换律,
9999
即对于所有的 `m``n`,有 `m + n ≡ n + m`
100100

101-
* **分配律(Distributivity)**对于所有的 `m``n``p`,若
101+
* **分配律(Distributivity)**对于所有的 `m``n``p`,若
102102
`(m + n) * p ≡ (m * p) + (n * p)`,则运算符 `*` 对运算符 `+` 满足左分配律;
103103
对于所有的 `m``n``p`,若 `m * (p + q) ≡ (m * p) + (m * q)`,则满足右分配律。
104104

@@ -130,7 +130,7 @@ out these properties---or their lack---for instance by pointing out
130130
that a newly introduced operator is associative but not commutative.
131131
{:/}
132132

133-
正经来说,如果你在阅读技术论文时遇到了一个运算符,那么你可以考察它是否拥有一个幺元
133+
正经来说,如果你在阅读技术论文时遇到了一个运算符,那么你可以考察它是否拥有幺元
134134
是否满足结合律或分配律,或者是否对另一个运算符满足分配律,这能为你提供一种视角。
135135
细心的作者通常会指出它们是否满足这些性质,比如说指明一个新引入的运算符满足结合律
136136
但不满足交换律。
@@ -165,9 +165,15 @@ associative but is not commutative.
165165

166166
请给出一个运算符的例子,它拥有幺元、满足结合律但不满足交换律。
167167

168+
{::comment}
168169
```
169170
-- Your code goes here
170171
```
172+
{:/}
173+
174+
```
175+
-- 请将代码写在此处。
176+
```
171177

172178

173179
{::comment}
@@ -196,7 +202,7 @@ We can test the proposition by choosing specific numbers for the three
196202
variables:
197203
{:/}
198204

199-
我们可以为这三个变量选取特定的数值来测试此命题
205+
我们可以为这三个变量选取特定的数值来验证此命题
200206

201207
```
202208
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
@@ -221,7 +227,7 @@ until one reaches the simplest term (in this case, `12`), and
221227
then from the bottom up until one reaches the same term.
222228
{:/}
223229

224-
在这里,我们将计算过程写成了等式链,一行一个式子。这样的等式链通常非常易读,
230+
在这里,我们将计算过程写成了等式链,每行一个式子。这样的等式链通常非常易读,
225231
你可以从上到下,直到遇到最简形式(本例中为 `12`),也可以从下到上,直到回到同样的式子。
226232

227233
{::comment}
@@ -234,15 +240,15 @@ sure that associativity holds for _all_ the natural numbers?
234240
{:/}
235241

236242
该测试揭示了结合律可能没有它初看起来那么显然。为什么 `7 + 5``3 + 9` 相同?
237-
我们可能需要收集更多证据,选择其它的数值来测试此命题。但由于自然数是无限的,
243+
我们可能需要收集更多证据,选择其它的数值来验证此命题。但由于自然数是无限的,
238244
因此测试永远无法完成。那么我们还有其它可以确保结合律对于**所有**自然数都成立的方法吗?
239245

240246
{::comment}
241247
The answer is yes! We can prove a property holds for all naturals using
242248
_proof by induction_.
243249
{:/}
244250

245-
答案是肯定的!我们可以用**归纳证明(Proof by Induction)**
251+
当然有!我们可以用**归纳证明(Proof by Induction)**
246252
来确保某个性质对于所有的自然数都成立。
247253

248254

@@ -271,16 +277,16 @@ then show that the property must also hold for `suc m`.
271277
{:/}
272278

273279
归纳证明遵循此定义的结构。要通过归纳证明自然数的某个性质,我们需要两个步骤。
274-
其一是**起始步骤**我们需要证明此性质对 `zero` 成立。其二是**归纳步骤**
275-
我们假设此性质对一个任意自然数 `m` 成立(我们称之为**归纳假设(Induction
280+
其一是**起始步骤**即需要证明此性质对 `zero` 成立。其二是**归纳步骤**
281+
即假设此性质对一个任意自然数 `m` 成立(我们称之为**归纳假设(Induction
276282
Hypothesis)**),然后证明该性质对 `suc m` 必定成立。
277283

278284
{::comment}
279285
If we write `P m` for a property of `m`, then what we need to
280286
demonstrate are the following two inference rules:
281287
{:/}
282288

283-
若我们将 `m` 的某种性质(Property)写作 `P m`,那么我们需要证明的就是以下两个推导规则:
289+
若将 `m` 的某种性质(Property)写作 `P m`,那么我们需要证明的就是以下两个推导规则:
284290

285291
------
286292
P zero
@@ -297,7 +303,7 @@ inductive hypothesis---namely that `P` holds for `m`---then it follows that
297303
`P` also holds for `suc m`.
298304
{:/}
299305

300-
我们来分析一下这些规则。第一条规则是起始步骤,它需要我们证明性质 `P``zero`
306+
先来分析一下这些规则。第一条规则是起始步骤,它需要我们证明性质 `P``zero`
301307
成立。第二条规则是归纳步骤,它需要我们证明若归纳假设「`P``m` 成立」,
302308
那么 `P` 也对 `suc m` 成立。
303309

@@ -306,8 +312,7 @@ Why does this work? Again, it can be explained by a creation story.
306312
To start with, we know no properties:
307313
{:/}
308314

309-
为什么它能够起作用?同样,它也可以用创世故事来讲解。在最开始,我们对性质一无所知:
310-
315+
为什么可以这样做呢?它也可以用创世故事来讲解。起初,我们对性质一无所知:
311316

312317
{::comment}
313318
-- In the beginning, no properties are known.
@@ -325,8 +330,8 @@ apply:
325330
{:/}
326331

327332
现在我们对所有已知的性质应用上述两条规则。起始步骤告诉我们 `P zero` 成立,
328-
所以我们将它加入已知的性质集合中。归纳步骤告诉我们若(在昨天)`P m` 成立,
329-
那么(在今天)`P (suc m)` 也成立。我们在今天之前并不知道任何性质,
333+
所以我们将它加入已知的性质集合中。归纳步骤告诉我们若「昨天的」`P m` 成立,
334+
那么「今天的」`P (suc m)` 也成立。我们在今天之前并不知道任何性质,
330335
因此归纳步骤在这里不适用:
331336

332337
{::comment}
@@ -347,7 +352,7 @@ held yesterday, then `P (suc zero)` holds today:
347352

348353
然后我们重复此过程。在接下来的一天我们知道今天之前的所有性质,
349354
以及任何通过此规则添加的性质。起始步骤告诉我们 `P zero`
350-
成立,当然我们已经知道这件事了。而如今归纳步骤告诉我们,由于 `P zero`
355+
成立,我们已经知道这件事了。而如今归纳步骤告诉我们,由于 `P zero`
351356
在昨天成立,那么 `P (suc zero)` 今天也成立。
352357

353358
{::comment}
@@ -450,7 +455,7 @@ If we can demonstrate both of these, then associativity of addition
450455
follows by induction.
451456
{:/}
452457

453-
如果我们可以证明这两条规则,那么加法结合律就可根据归纳法来证明
458+
如果我们可以证明这两条规则,那么加法结合律就可以用归纳法来证明
454459

455460
{::comment}
456461
Here is the proposition's statement and proof:
@@ -487,7 +492,7 @@ We have named the proof `+-assoc`. In Agda, identifiers can consist of
487492
any sequence of characters not including spaces or the characters `@.(){};_`.
488493
{:/}
489494

490-
我们将此证明命名为 `+-assoc`。在 Agda 中,标识符可以由除空格或 `@.(){};_`
495+
我们将此证明命名为 `+-assoc`。在 Agda 中,标识符可以由除空格和 `@.(){};_`
491496
之外的任何字符序列构成。
492497

493498
{::comment}
@@ -537,7 +542,7 @@ be shown, and reading down from the top and up from the bottom takes us to
537542
{:/}
538543

539544
此式平凡成立。阅读此证明中起始步骤中的等式链,其最初和最末的式子分别匹配待证等式的两边,
540-
从上到下或从下到上读都会让我们在中间遇到 `n + p`此步骤除了化简外不需要其他额外的解释
545+
从上到下或从下到上读都会让我们在中间遇到 `n + p`此步骤无需多言,化简即可
541546

542547
{::comment}
543548
For the inductive case, we must show:
@@ -577,9 +582,9 @@ within angle brackets. The justification given is:
577582
{:/}
578583

579584
阅读此证明中归纳步骤的等式链,其最初和最末的式子分别匹配待证等式的两边,
580-
从上到下或从下到上读都会让我们到达上面化简等式的地方。剩下的等式
581-
不止用化简就行,因此我们需要为推理链使用一个附加的运算符 `_≡⟨_⟩_`
582-
为等式给出的依据会放在尖括号中。这里给出的依据是:
585+
从上到下或从下到上读都会让我们到达上面化简等式的地方。剩下的等式单化简还不行
586+
我们还需要为推理链使用一个附加的运算符 `_≡⟨_⟩_`
587+
并将等式的依据放在尖括号中。这里给出的依据是:
583588

584589
⟨ cong suc (+-assoc m n p) ⟩
585590

@@ -598,8 +603,8 @@ preserved by applying that function. If `e` is evidence that `x ≡ y`,
598603
then `cong f e` is evidence that `f x ≡ f y`, for any function `f`.
599604
{:/}
600605

601-
若某个关系在应用给定函数后仍然保持不变,则称该关系满足**合同性(Congruence)**
602-
`e``x ≡ y` 的证据,那么对于任意函数 `f``cong f e` `f x ≡ f y` 的证据。
606+
若某个关系在应用了给定的函数后仍然保持不变,则称该关系满足**合同性(Congruence)**
607+
`e``x ≡ y` 的证据,那么对于任意函数 `f``cong f e` 就是 `f x ≡ f y` 的证据。
603608

604609
{::comment}
605610
Here the inductive hypothesis is not assumed, but instead proved by a
@@ -622,8 +627,14 @@ recursion is one of the most appealing aspects of Agda.
622627

623628
## 归纳即递归
624629

630+
{::comment}
631+
As a concrete example of how induction corresponds to recursion, here
632+
is the computation that occurs when instantiating `m` to `2` in the
633+
proof of associativity.
634+
{:/}
635+
625636
下面是归纳如何对应于递归的具体例子,它是在结合律的证明中,将 `m` 实例化为 `2`
626-
时出现的计算
637+
时的计算过程
627638

628639
```
629640
+-assoc-2 : ∀ (n p : ℕ) → (2 + n) + p ≡ 2 + (n + p)
@@ -705,8 +716,8 @@ result type may mention (or depend upon) these variables; hence they
705716
are called _dependent functions_.
706717
{:/}
707718

708-
是等价的。它们不同于像 `ℕ → ℕ → ℕ` 这样的函数类型,其中的变量
709-
与每一个实参类型相关联,其结果类型可能会涉及(或依赖于)这些变量,
719+
是等价的。 `ℕ → ℕ → ℕ` 这样的函数类型不同,上述函数中的变量
720+
与每一个实参类型相关联,且其结果类型可能会涉及(或依赖于)这些变量,
710721
因此它们叫做**依赖函数**(Dependent Function)。
711722

712723

@@ -783,7 +794,7 @@ The signature states that we are defining the identifier `+-identityʳ` which
783794
provides evidence for the proposition:
784795
{:/}
785796

786-
其签名描述了我们定义的标识符 `+-identityʳ` 提供了以下命题的证据:
797+
其签名说明我们定义的标识符 `+-identityʳ` 提供了以下命题的证据:
787798

788799
∀ (m : ℕ) → m + zero ≡ m
789800

@@ -808,7 +819,7 @@ For the base case, we must show:
808819
Simplifying with the base case of addition, this is straightforward.
809820
{:/}
810821

811-
根据加法的起始步骤化简,这很直白
822+
根据加法的起始步骤化简,这很显然
812823

813824
{::comment}
814825
For the inductive case, we must show:
@@ -913,7 +924,7 @@ The signature states that we are defining the identifier `+-suc` which provides
913924
evidence for the proposition:
914925
{:/}
915926

916-
其签名描述了我们定义的标识符 `+-suc` 提供了以下命题的证据:
927+
其签名说明我们定义的标识符 `+-suc` 提供了以下命题的证据:
917928

918929
∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
919930

@@ -938,7 +949,7 @@ For the base case, we must show:
938949
Simplifying with the base case of addition, this is straightforward.
939950
{:/}
940951

941-
根据加法的起始步骤化简,这很直白
952+
根据加法的起始步骤化简,这很显然
942953

943954
{::comment}
944955
For the inductive case, we must show:
@@ -1026,7 +1037,7 @@ The first line states that we are defining the identifier
10261037
`+-comm` which provides evidence for the proposition:
10271038
{:/}
10281039

1029-
第一行描述了我们定义的标识符 `+-comm` 提供了以下命题的证据:
1040+
第一行说明我们定义的标识符 `+-comm` 提供了以下命题的证据:
10301041

10311042
∀ (m n : ℕ) → m + n ≡ n + m
10321043

@@ -1111,9 +1122,9 @@ the main proposition first, and the equations required to do so
11111122
will suggest what lemmas to prove.
11121123
{:/}
11131124

1114-
Agda 要求标识符必须在使用前定义,因此我们必须在主命题之前展示引理
1115-
如前例所示。在实践中,我们通常会先试着证明主命题,之后所需的等式会表明
1116-
需要证明的引理
1125+
Agda 要求标识符必须在使用前定义,因此我们必须在主命题之前列出引理
1126+
如前例所示。在实践中,我们通常会先试着证明主命题,之后所需的等式会说明
1127+
需要证明哪些引理
11171128

11181129

11191130
{::comment}
@@ -1215,7 +1226,7 @@ proof (or, equivalently, the recursive definition) as a creation story. This
12151226
time we are concerned with judgments asserting associativity:
12161227
{:/}
12171228

1218-
我们回到结合律的证明上来,把归纳证明(或等价地,递归定义)看做一个创世故事会有助于理解。
1229+
我们回到结合律的证明上来,把归纳证明(或等价的递归定义)看做一个创世故事会有助于理解。
12191230
这次我们专注于判断结合律的断言:
12201231

12211232
{::comment}
@@ -1470,7 +1481,6 @@ Begin by typing:
14701481
看看如何在 Emacs 中用 Agda 的交互式特性来构造另一种结合律的证明会很有启发性。
14711482
我们从输入以下内容开始:
14721483

1473-
14741484
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
14751485
+-assoc′ m n p = ?
14761486

@@ -1511,7 +1521,7 @@ the cursor into the hole and type `C-c C-c`. You will be given
15111521
the prompt:
15121522
{:/}
15131523

1514-
我们希望通过对 `m` 进行归纳来证明此命题。将光标移动到洞中并按下
1524+
我们希望对 `m` 进行归纳来证明此命题。将光标移动到洞中并按下
15151525
`C-c C-c`。它会给出提示:
15161526

15171527
pattern variables to case (empty for split on result):
@@ -1635,6 +1645,7 @@ is associative and commutative.
16351645

16361646
成立。无需归纳证明,只需应用前面满足结合律和交换律的结果即可。
16371647

1648+
{::comment}
16381649
```
16391650
-- Your code goes here
16401651
```
@@ -1820,7 +1831,7 @@ for all `m`, `n`, and `p`.
18201831

18211832
对于所有 `m``n``p` 成立。
18221833

1823-
1834+
{::comment}
18241835
#### Exercise `Bin-laws` (stretch) {#Bin-laws}
18251836
{:/}
18261837

@@ -1832,7 +1843,8 @@ Exercise [Bin]({{ site.baseurl }}/Naturals/#Bin)
18321843
defines a datatype of bitstrings representing natural numbers
18331844
{:/}
18341845

1835-
回想练习 [Bin][plfa.Naturals#Bin] 中定义了一种比特串数据类型来表示自然数
1846+
回想练习 [Bin]({{ site.baseurl }}/Naturals/#Bin)
1847+
中定义的一种表示自然数的比特串数据类型:
18361848

18371849
```
18381850
data Bin : Set where
@@ -1845,7 +1857,7 @@ data Bin : Set where
18451857
and asks you to define functions
18461858
{:/}
18471859

1848-
并要求你定义函数
1860+
以及要求你定义的函数
18491861

18501862
inc : Bin → Bin
18511863
to : ℕ → Bin

0 commit comments

Comments
 (0)