forked from DeathKing/Learning-SICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec8a.srt
3421 lines (2736 loc) · 75.3 KB
/
lec8a.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1
00:00:00,000 --> 00:00:02,672
Learning-SICP学习小组
倾情制作
2
00:00:18,270 --> 00:00:19,680
教授:上节课中 我们学习了
PROFESSOR: The last time we began having a look
3
00:00:19,728 --> 00:00:21,264
如何构造语言
at how languages are constructed.
4
00:00:22,416 --> 00:00:25,888
核心点就是 像Lisp这样的求值器
Remember the main point that an evaluator for, LISP, say,
5
00:00:26,080 --> 00:00:27,580
有两个主要部分
has two main elements.
6
00:00:27,580 --> 00:00:28,400
一个是EVAL
There is EVAL,
7
00:00:31,040 --> 00:00:37,424
EVAL接受一个表达式EXP和环境ENV
and EVAL's job is to take in an expression and an environment
8
00:00:38,912 --> 00:00:44,448
然后返回一个过程和相关的实际参数
and turn that into a procedure and some arguments
9
00:00:45,424 --> 00:00:47,056
并把它们传递给APPLY
and pass that off to APPLY.
10
00:00:49,410 --> 00:00:51,296
APPLY接收这些过程和实际参数
And APPLY takes the procedure in the arguments,
11
00:00:51,696 --> 00:00:55,120
通常来说 APPLY会返回另一个表达式
turns that back into, in a general case, another expression
12
00:00:55,392 --> 00:00:57,712
返回一个在其它环境中求值的表达式
to be evaluated in another environment
13
00:00:57,744 --> 00:01:00,000
表达式就像这样在EVAL-APPLY之间传递
and passes that off to EVAL, which passes it to APPLY,
14
00:01:00,272 --> 00:01:01,440
这就是整个元循环
and there's this whole big circle
15
00:01:01,470 --> 00:01:02,944
表达式在这里面循环往复
where things go around and around and around
16
00:01:03,024 --> 00:01:06,560
直到最后求值为基本数据或基本过程
until you get either to some very primitive data or to a primitive procedure.
17
00:01:07,740 --> 00:01:09,248
这个循环要做的就是
See, what this cycle has to do with
18
00:01:09,440 --> 00:01:12,576
把语言中的组合手段
is unwinding the means of combination
19
00:01:12,590 --> 00:01:14,368
和抽象手段展开
and the means of abstraction in the language.
20
00:01:15,020 --> 00:01:17,728
比如说在Lisp中 你有一个过程
So for instance, you have a procedure in LISP--
21
00:01:17,744 --> 00:01:20,528
定义过程是为了
a procedure is a general way of saying,
22
00:01:20,540 --> 00:01:22,576
让表达式的计算过程
I want to be able to evaluate this expression
23
00:01:22,672 --> 00:01:24,410
适用于任意的参数
for any value of the arguments,
24
00:01:25,760 --> 00:01:27,184
这就是这里面发生的事情
and that's sort of what's going on here.
25
00:01:27,670 --> 00:01:28,510
这就是APPLY做的事
That's what APPLY does.
26
00:01:28,510 --> 00:01:30,688
当一个带参数的一般性表达式进入以后
It says the general thing coming in with the arguments
27
00:01:30,720 --> 00:01:32,704
它将其归约为过程体的表达式
reduces to the expression that's the body,
28
00:01:33,056 --> 00:01:34,720
如果归约得到的是复合表达式
and then if that's a compound expression
29
00:01:34,832 --> 00:01:36,464
或者是另外的过程应用
or another procedure application,
30
00:01:36,784 --> 00:01:38,448
那么这个循环就会不断地进行
the thing will go around and around the circle.
31
00:01:40,336 --> 00:01:44,080
这基本上就是 -- 大部分解释器的基本结构了
Anyway, that's sort of the basic structure of gee, pretty much any interpreter.
32
00:01:45,200 --> 00:01:46,256
另外一点就是
The other thing that you saw
33
00:01:46,288 --> 00:01:47,660
一旦你有了一个解释器
once you have the interpreter in your hands,
34
00:01:47,696 --> 00:01:49,870
你就有了操作这门语言的所有能力
you have all this power to start playing with the language.
35
00:01:49,870 --> 00:01:51,520
因此你可以让它成为动态作用域
So you can make it dynamically scoped,
36
00:01:51,840 --> 00:01:54,560
你也可以引入正则序求值
or you can put in normal order evaluation,
37
00:01:54,590 --> 00:01:56,480
你也可以为语言添加新的形式
or you can add new forms to the language,
38
00:01:56,860 --> 00:01:57,504
想怎么样都行
whatever you like.
39
00:01:57,584 --> 00:01:58,624
或者更一般地说
Or more generally,
40
00:01:58,768 --> 00:02:01,328
这种元语言抽象的概念
there's this notion of metalinguistic abstraction,
41
00:02:02,640 --> 00:02:06,016
它告诉我们 作为一名软件工程师
which says that part of your perspective
42
00:02:07,616 --> 00:02:10,528
从广义的“工程师”的角度来看
as an engineer, as a software engineer, but as an engineer in general
43
00:02:11,392 --> 00:02:13,888
有时你可以通过发明新的语言
is that you can gain control of complexity
44
00:02:14,960 --> 00:02:17,168
来获得控制复杂度的能力
by inventing new languages sometimes.
45
00:02:18,010 --> 00:02:20,816
一种思考计算机程序设计的方法就是
See, one way to think about computer programming
46
00:02:21,552 --> 00:02:26,270
它只是偶然地让计算机执行某事儿
is that it only incidentally has to do with getting a computer to do something.
47
00:02:26,440 --> 00:02:28,976
计算机程序的主要工作却是
Primarily what a computer program has to do with,
48
00:02:29,008 --> 00:02:32,520
用来表达和交换想法
it's a way of expressing ideas with communicating ideas.
49
00:02:33,168 --> 00:02:34,048
有时
And sometimes
50
00:02:34,896 --> 00:02:36,624
当我们想要表达新的想法时
when you want to communicate new kinds of ideas,
51
00:02:36,656 --> 00:02:38,736
我们就想要发明新的模式来表达它们
you'd like to invent new modes of expressing that.
52
00:02:39,824 --> 00:02:44,992
那么 今天我们就将按照这个框架来创建新语言
Well, today we're going to apply this framework to build a new language.
53
00:02:45,730 --> 00:02:48,000
一旦我们了解了解释器的基本结构
See, once we have the basic idea of the interpreter,
54
00:02:48,032 --> 00:02:50,272
我们就可以按意愿来构造任意的语言
you can pretty much go build any language that you like.
55
00:02:50,830 --> 00:02:53,216
比如说 我们可以构造Pascal(的解释器)
So for example, we can go off and build Pascal.
56
00:02:54,370 --> 00:02:55,152
以及
And...
57
00:02:56,170 --> 00:02:58,192
我们需要操心语法的表示与解析
gee, we would worry about syntax and parsing
58
00:02:58,192 --> 00:03:00,510
还有一大堆的编译器优化
and various kinds of compiler optimizations,
59
00:03:01,120 --> 00:03:03,296
还有一些人会这样做
and there are people who make honest livings doing that,
60
00:03:03,856 --> 00:03:07,600
但是就在我们所讨论的抽象层次来说
but at the level of abstraction that we're talking,
61
00:03:08,048 --> 00:03:10,992
一个Pascal语言的解释器看起来
a Pascal interpreter would not look very different at all
62
00:03:12,032 --> 00:03:13,760
跟Gerry教授上节课所讲的大同小异
from what you saw Gerry do last time.
63
00:03:15,024 --> 00:03:18,960
但是今天 我们要构建一门与众不同的语言
Instead of that, we'll spend today building a really different language,
64
00:03:20,510 --> 00:03:22,816
这门语言
a language that encourages you
65
00:03:23,056 --> 00:03:26,040
不推荐你用过程式的思维来思考程序设计
to think about programming not in terms of procedures,
66
00:03:26,240 --> 00:03:27,648
而是用一种非常不同的方式
but in a really different way.
67
00:03:29,090 --> 00:03:31,024
今天的课程呢
And the lecture today is
68
00:03:31,744 --> 00:03:34,640
将会在两个层次中同时进行
going to be at two levels simultaneously.
69
00:03:34,810 --> 00:03:35,520
一方面
On the one hand,
70
00:03:35,904 --> 00:03:37,710
我会向大家介绍这门语言是如何使用的
I'm going to show you what this language looks like,
71
00:03:38,960 --> 00:03:41,080
另一方面呢 我会带领大家实现这门语言
and on the other hand, I'll show you how it's implemented.
72
00:03:41,320 --> 00:03:42,960
我们将会用Lisp来实现
And we'll build an implementation in LISP
73
00:03:42,992 --> 00:03:43,900
并观察它的运行原理
and see how that works.
74
00:03:44,048 --> 00:03:48,256
你应该在两个层次上学到知识
And you should be drawing lessons on two levels.
75
00:03:48,688 --> 00:03:53,000
首先要认识到 语言之间可以有多么地“不同”
The first is to realize just how different a language can be.
76
00:03:53,790 --> 00:03:58,144
如果你认为Fortran和Lisp算是天差地别的话
So if you think that the jump from Fortran to LISP is a big deal,
77
00:03:58,240 --> 00:03:59,360
那就小巫见大巫了
you haven't seen anything yet.
78
00:04:01,560 --> 00:04:03,680
其次
And secondly,
79
00:04:03,776 --> 00:04:06,544
甚至于在这门与众不同的语言中
you'll see that even with such a very different language,
80
00:04:07,360 --> 00:04:09,520
这门既不讨论函数
which will turn out to not have procedures at all
81
00:04:09,920 --> 00:04:11,648
也没有过程的语言中
and not talk about functions at all,
82
00:04:12,200 --> 00:04:15,720
其中也有基本的EVAL-APPLY循环
there will still be this basic cycle of eval and apply
83
00:04:16,192 --> 00:04:19,984
也就是对组合手段和抽象手段的展开
that's unwinds the means of combination and the means an abstraction.
84
00:04:20,950 --> 00:04:24,688
第三点 是一个不太重要但非常优雅的技术技巧
And then thirdly, as kind of a minor but elegant technical point,
85
00:04:24,890 --> 00:04:28,528
就是如何巧妙地使用流来避免回溯
you'll see a nice use of streams to avoid backtracking.
86
00:04:32,330 --> 00:04:34,400
好吧 我说过这门语言与众不同
OK, well, I said that this language is very different.
87
00:04:35,860 --> 00:04:36,640
为了解释这点
To explain that,
88
00:04:37,050 --> 00:04:42,816
让我们回到这门课最初的理念上
let's go back to the very first idea that we talked about in this course,
89
00:04:43,260 --> 00:04:46,544
就是要区别
and that was the idea of the distinction between
90
00:04:46,720 --> 00:04:49,520
数学中“陈述性”的知识
the declarative knowledge of mathematics--
91
00:04:50,192 --> 00:04:54,144
比如平方根的定义就是一条数学事实
the definition of a square root as a mathematical truth--
92
00:04:55,488 --> 00:04:59,568
而计算机科学讨论的是“如何做”的知识
and the idea that computer science talks about the how to knowledge--
93
00:04:59,760 --> 00:05:04,592
“什么是平方根”和“如何计算平方根”是不同的
contrast that definition of square root with a program to compute a square root.
94
00:05:05,970 --> 00:05:07,072
我们是从这里开始的
That's where we started off.
95
00:05:08,512 --> 00:05:09,520
如果我们能够通过某种方式
Well, wouldn't it be great
96
00:05:09,888 --> 00:05:12,160
弥合这种差距 岂不是更好么?
if you could somehow bridge this gap
97
00:05:12,810 --> 00:05:16,432
我们创建一门这样的语言
and make a programming language which sort of did things,
98
00:05:16,672 --> 00:05:21,610
以声明式的方式、用数学事实来完成计算
but you talked about it in terms of truth, in declarative terms?
99
00:05:22,380 --> 00:05:25,504
你用这种该语言来指定事实
So that would be a programming language in which you specify facts.
100
00:05:27,690 --> 00:05:28,880
你告诉它
You tell it what is.
101
00:05:28,880 --> 00:05:29,968
什么是事实
You say what is true.
102
00:05:30,950 --> 00:05:33,072
而当你需要一个答案时
And then when you want an answer,
103
00:05:33,216 --> 00:05:36,384
语言已经自动地内建了
somehow the language has built into it automatically
104
00:05:37,600 --> 00:05:39,456
有关于“如何做”的一般性知识
general kinds of how to knowledge
105
00:05:39,472 --> 00:05:40,640
这样它就可以根据你给出的事实
so it can just take your facts
106
00:05:40,896 --> 00:05:42,832
自行地演进这些方法
and it can evolve these methods on its own
107
00:05:43,312 --> 00:05:46,128
通过你给定的事实和某种一般性的逻辑规则
using the facts you gave it and maybe some general rules of logic.
108
00:05:49,330 --> 00:05:50,544
就比如说
So for instance,
109
00:05:52,064 --> 00:05:55,120
我会告诉程序下述事实
I might go up to this program and start telling it some things.
110
00:05:56,000 --> 00:06:07,080
我告诉它 (SON-OF ADAM ABEL)
So I might tell it that the son of Adam is Abel.
111
00:06:08,920 --> 00:06:16,512
同时告诉它 (SON-OF ADAM CAIN)
And I might tell it that the son of Adam is Cain.
112
00:06:17,660 --> 00:06:25,088
以及 (SON-OF CAIN ENOCH)
And I might tell it that the son of Cain is Enoch.
113
00:06:27,792 --> 00:06:34,896
还有 (SON-OF ENOCH IRAD)
And I might tell it that the son of Enoch is Irad,
114
00:06:37,024 --> 00:06:40,720
以及《创世纪》章节中的其它人物
and all through the rest of our chapter whatever of Genesis,
115
00:06:41,152 --> 00:06:43,184
最后终止于ADAH
which ends up ending in Adah, by the way,
116
00:06:43,328 --> 00:06:46,784
这些是从ADAH到CAIN的家谱
and this shows the genealogy of Adah from Cain.
117
00:06:48,440 --> 00:06:50,672
总之 一旦你指明了这些事实
Anyway, once you tell it these facts,
118
00:06:52,352 --> 00:06:53,408
你就可以提出问题
you might ask it things.
119
00:06:53,510 --> 00:06:55,056
你可以对语言系统发问
You might go up to your language and say,
120
00:06:56,064 --> 00:06:59,296
谁是ADAM的孩子?
who's the son of Adam?
121
00:07:00,420 --> 00:07:04,912
可以很容易地想到一个通用搜索程序
And you can very easily imagine having a little general purpose search program
122
00:07:05,520 --> 00:07:06,960
它会遍历所有的事实
which would be able to go through
123
00:07:07,008 --> 00:07:09,260
然后回答:“哦 有两个答案”
and in response to that say, oh yeah, there are two answers:
124
00:07:09,296 --> 00:07:10,448
ABEL是ADAM的孩子
the son of Adam is Abel
125
00:07:10,688 --> 00:07:12,176
CAIN也是ADAM的孩子
and the son of Adam is Cain.
126
00:07:14,140 --> 00:07:14,976
你也可以这样问
Or you might say,
127
00:07:15,070 --> 00:07:16,890
基于同样的事实
based on the very same facts,
128
00:07:18,048 --> 00:07:19,952
CAIN是谁的孩子?
who is Cain the son of?
129
00:07:21,950 --> 00:07:27,024
你们就会想到生成另外一个略微不同的搜索程序
And then you can imagine generating another slightly different search program
130
00:07:27,920 --> 00:07:29,216
它也会遍历所有的事实
which would be able to go through
131
00:07:29,450 --> 00:07:33,056
检查谁的孩子是CAIN
and checked for who is Cain, and son of,
132
00:07:33,520 --> 00:07:34,440
发现结果是ADAM
and come up with Adam.
133
00:07:35,890 --> 00:07:36,992
你也可以问
Or you might say,
134
00:07:38,016 --> 00:07:41,408
CAIN和ENOCH之间是什么关系?
what's the relationship between Cain and Enoch?
135
00:07:42,070 --> 00:07:45,088
又会生成另一个略微不同的搜索程序
And again, a minor variant on that search program.
136
00:07:46,340 --> 00:07:48,160
得到的结果是亲子关系(SON-OF)
You could figure out that it said son of.
137
00:07:52,880 --> 00:07:54,928
在这个非常简单的例子中
But even here in this very simple example,
138
00:07:56,144 --> 00:07:58,448
我们发现 即使是单条事实
what you see is that a single fact,
139
00:07:58,816 --> 00:08:01,520
比如说 (SON-OF ADAM CAIN)
see, a single fact like the son of Adam is Cain
140
00:08:02,848 --> 00:08:05,520
可以被用来回答不同种类的问题
can be used to answer different kinds of questions.
141
00:08:06,520 --> 00:08:08,128
你可以问CAIN是谁的孩子?
You can say, who's Cain the son of,
142
00:08:08,144 --> 00:08:10,928
你也可以问ADAM的孩子是谁?
or you can say who's the son of Adam,
143
00:08:10,944 --> 00:08:12,864
你也可以问ADAM和CAIN之间的关系是什么?
or you can say what's the relation between Adam and Cain?
144
00:08:12,880 --> 00:08:14,480
这些由不同的传统程序
Those are different questions
145
00:08:15,536 --> 00:08:18,544
所解答的不同的问题
being run by different traditional procedures
146
00:08:18,688 --> 00:08:20,720
都基于同样的事实
all based on the same fact.
147
00:08:22,752 --> 00:08:25,920
这正是这种程序设计风格的威力所在
And that's going to be the essence of the power of this programming style,
148
00:08:26,912 --> 00:08:29,504
也就是一条陈述性知识
that one piece of declarative knowledge
149
00:08:30,040 --> 00:08:34,016
可以作为大量关于“如何做”的各种知识的基础
can be used as the basis for a lot of different kinds of how-to knowledge,
150
00:08:34,816 --> 00:08:37,088
这跟我们正在编写的过程是不同的
as opposed to the kinds of procedures we're writing
151
00:08:37,152 --> 00:08:39,552
我们编写的过程描述了输入
where you sort of tell it what input you're giving in
152
00:08:39,616 --> 00:08:40,656
以及想要的输出
and what answer you want.
153
00:08:41,490 --> 00:08:44,704
比如说 我们的平方根程序可以完美地回答
So for instance, our square root program can perfectly well answer the question,
154
00:08:44,768 --> 00:08:47,168
144的平方根是多少?
what's the square root of 144?
155
00:08:48,900 --> 00:08:49,776
但从原理上来说
But in principle,
156
00:08:49,824 --> 00:08:52,830
平方根的数学定义告诉了你另外的东西
the mathematical definition of square root tells you other things.
157
00:08:52,848 --> 00:08:56,430
就比如说 17是谁的平方根
Like it could say, what is 17 the square root of?
158
00:08:57,590 --> 00:08:59,712
这就需要另外一个程序来解答
And that would be have to be answered by a different program.
159
00:09:01,920 --> 00:09:03,504
因此 数学定义
So the mathematical definition,
160
00:09:03,980 --> 00:09:05,120
或者更一般地说
or in general, the
161
00:09:05,536 --> 00:09:10,300
你给定的事实 对于问题是没有偏向性的
the facts that you give it are somehow unbiased as to what the question is.
162
00:09:10,900 --> 00:09:12,816
而我们倾向于编写专门的程序
Whereas the programs we tend to write specifically
163
00:09:12,830 --> 00:09:14,208
因为它们是关于“如何做”的知识
because they are how-to knowledge
164
00:09:14,240 --> 00:09:16,368
倾向于寻找特定的答案
tend to be looking for a specific answer.
165
00:09:17,568 --> 00:09:20,120
所以这是我们正在讨论的一个特点
So that's going to be one characteristic of what we're talking about.
166
00:09:21,810 --> 00:09:22,608
然而我们可以更进一步
We can go on.
167
00:09:23,480 --> 00:09:27,520
想象一下 我们可以向语言给定一些事实
We can imagine that we've given our language some sort of facts.
168
00:09:27,710 --> 00:09:29,616
现在 我们给它一些推理规则
Now let's give it some rules of inference.
169
00:09:30,020 --> 00:09:31,360
比如说
We can say, for instance,
170
00:09:31,952 --> 00:09:36,192
这里 我们先用某种语法表示
if the-- make up some syntax here--
171
00:09:36,448 --> 00:09:41,536
如果(SON-OF ?X ?Y)成立
if the son of x is y--
172
00:09:41,680 --> 00:09:45,210
在这里 我用问号来标识变量
I'll put question marks to indicate variables here--
173
00:09:45,616 --> 00:09:56,060
如果(SON-OF ?X ?Y)和(SON-OF ?Y ?Z)都成立
if the son of x is y and the son of y is z,
174
00:09:58,960 --> 00:10:08,464
那么就有(GRANSON ?X ?Z)
then the grandson of x is z.
175
00:10:09,320 --> 00:10:13,408
想象一下 如果把这条规则告诉机器
So I can imagine telling my machine that rule
176
00:10:15,008 --> 00:10:17,280
那么我们就可以这么来询问
and then being able to say, for instance,
177
00:10:17,440 --> 00:10:18,688
谁是ADAM的孙子?
who's the grandson of Adam?
178
00:10:20,610 --> 00:10:23,648
或者说 IRAD是谁的孙子?
Or who is Irad the grandson of?
179
00:10:24,790 --> 00:10:29,088
或者从这些信息中尽可能地推断出所有的祖孙关系
Or deduce all grandson relationships you possibly can from this information.
180
00:10:31,136 --> 00:10:35,600
我们可以想象 语言知道如何自动求解
We can imagine somehow the language knowing how to do that automatically.
181
00:10:40,224 --> 00:10:45,200
好吧 我再举一个更具体一点的例子
Ok, Let me give you maybe a little bit more concrete example.
182
00:10:45,776 --> 00:10:51,952
这是个用来合并两个有序表的过程
Here's a procedure that merges two sorted lists.
183
00:10:53,920 --> 00:11:00,272
X和Y是两个由数字构成的表
So x and y are two, say, lists of numbers,
184
00:11:00,304 --> 00:11:04,208
我们可以认为它们是严格升序的表
lists of distinct numbers, if you like, that are in increasing order.
185
00:11:04,768 --> 00:11:07,530
MERGE会把这两个表
And what merge does is take two such lists
186
00:11:07,712 --> 00:11:10,384
合并成一个有序的表
and combine them into a list where everything's in increasing order,
187
00:11:11,210 --> 00:11:15,000
这个程序非常简单
and this is a pretty easy programs
188
00:11:15,024 --> 00:11:16,144
你们可以轻松地写出来
that you ought to be able to write.
189
00:11:16,390 --> 00:11:18,640
也就是 如果X为空 那么结果就是Y
It says, if x is empty, the answer is y.
190
00:11:18,860 --> 00:11:20,464
如果Y为空 那结果就是X
If y is empty, the answer is x.
191
00:11:21,180 --> 00:11:22,990
否则的话 就要比较为首的两个元素
Otherwise, you compare the first two elements.
192
00:11:22,990 --> 00:11:24,464
取出X中的第一个元素
So you pick out the first thing in x
193
00:11:24,848 --> 00:11:26,016
以及Y中的第一个元素
and the first thing in y,
194
00:11:26,810 --> 00:11:31,680
把它们当中谁是最小的那一个
and then depending on which of those first elements is less,
195
00:11:32,832 --> 00:11:36,608
CONS在递归地调用MERGE的结果上
you stick the lower one on to the result a recursively merging,
196
00:11:37,872 --> 00:11:39,920
要么就是(MERGE (CDR X) Y)
either chopping the first one off x
197
00:11:40,112 --> 00:11:41,616
要么就是(MERGE X (CDR Y))
or chopping the first one off y.
198
00:11:42,400 --> 00:11:43,960
这是标准的程序
That's a standard kind of program.
199
00:11:46,470 --> 00:11:48,416
我们来考察下其中的逻辑
Let's look at the logic.
200
00:11:48,620 --> 00:11:49,792
先不考虑程序
Let's forget about the program