forked from DeathKing/Learning-SICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec4a.srt
4079 lines (3263 loc) · 107 KB
/
lec4a.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:22,340
[music]
2
00:00:22,340 --> 00:00:24,340
模式匹配:基于规则的代换
Pattern-matching: Rule-based Substitution
3
00:00:24,340 --> 00:00:29,340
教授:昨天 我们学习了一些符号操作
PROFESSOR: Well, yesterday we learned a bit about symbolic manipulation,
4
00:00:29,920 --> 00:00:35,120
编写了一个非常典型的程序
and we wrote a rather stylized program
5
00:00:35,152 --> 00:00:38,976
来实现教材中的微积分规则
to implement a pile of calculus rule from the calculus book.
6
00:00:39,616 --> 00:00:44,592
在这张幻灯片上
Here on the transparencies,
7
00:00:44,960 --> 00:00:48,816
有一些从书中摘录的微积分规则
we see a bunch of calculus rules from such a book.
8
00:00:49,472 --> 00:00:54,624
我们要把这些规则转化成计算机语言
And, of course, what we did is sort of translate these rules into the language of the computer.
9
00:00:55,140 --> 00:00:58,850
当然 这种策略很有趣
But, of course, that's a sort of funny strategy.
10
00:00:59,360 --> 00:01:04,800
但是我们为什么要把它们翻译成计算机语言呢?
Why should we have to translate these rules into the language of the computer?
11
00:01:05,008 --> 00:01:06,272
我的意思是---
And what do I really mean by that?
12
00:01:06,620 --> 00:01:11,020
我们昨天写的程序非常典型
These are--the program we wrote yesterday was very stylized.
13
00:01:11,216 --> 00:01:15,984
它是一个按表达式类型做分派的分情况分析语句
It was a conditional, a dispatch on the type of the expression
14
00:01:16,384 --> 00:01:18,480
规则就是这样的
as observed by the rules.
15
00:01:19,680 --> 00:01:21,552
这里的规则是说:
What we see here are rules that say
16
00:01:21,744 --> 00:01:25,488
我们考察的表达式如果是---
if the object being the derivative is being taken of,
17
00:01:25,488 --> 00:01:29,424
如果是常量 就做一些事情
if that expression is a constant, then do one thing.
18
00:01:29,420 --> 00:01:31,376
如果是变量 就做另一件事情
If it's a variable, do another thing.
19
00:01:31,600 --> 00:01:35,568
如果它是常量乘以变量 就做另外的事 等等
If it's a product of a constant times a variable, do something and so on.
20
00:01:36,000 --> 00:01:38,960
这是一种按类型的分派
There's sort of a dispatch there on a type.
21
00:01:41,400 --> 00:01:45,160
那么 既然它有如此典型的行为和结构
Well, since it has such a stylized behavior and structure,
22
00:01:45,952 --> 00:01:49,530
有没有其它方式把这个过程写得更加清晰?
is there some other way of writing this program that's more clear?
23
00:01:50,832 --> 00:01:53,456
首先要解决的是 这些规则是什么?
Well, what's a rule, first of all, What are these rules?
24
00:01:55,560 --> 00:01:58,500
我们来好好想一下 规则有好几个部分
Let's think about that. Rules have parts.
25
00:01:58,944 --> 00:02:02,352
如果仔细观察这些规则
If you look at these rules in detail,
26
00:02:03,712 --> 00:02:04,992
你就会发现
what you see, for example,
27
00:02:05,120 --> 00:02:09,696
这些规则都有左右两部分
is the rule has a left-hand side and a right-hand side.
28
00:02:10,360 --> 00:02:14,360
每一个规则都有左边部分和右边部分
Each of these rules has a left-hand side and the right-hand side.
29
00:02:15,152 --> 00:02:20,304
左边部分用来与对被求导表达式做比较
The left-hand side is somehow compared with the expression you're trying to take the derivative of.
30
00:02:21,520 --> 00:02:25,104
右边部分用于替换原表达式
The right-hand side is the replacement for that expression.
31
00:02:28,496 --> 00:02:33,104
这张纸上的所有规则都可以描述成这样——
So all rules on this page are something like this.
32
00:02:36,512 --> 00:02:38,064
我们有许多模式
I have patterns,
33
00:02:41,488 --> 00:02:48,300
有时候 给定一个模式 我们需要为其生成一个骨架
and somehow, I have to produce, given a pattern, a skeleton.
34
00:02:51,888 --> 00:02:52,816
这就是一个规则
This is a rule.
35
00:02:55,424 --> 00:02:57,136
模式是用于匹配的部分
A pattern is something that matches,
36
00:02:57,888 --> 00:03:03,264
将成功匹配的值代换到骨架里 就得到一个新的表达式
and a skeleton is something you substitute into in order to get a new expression.
37
00:03:06,464 --> 00:03:16,320
我的意思是:模式是用来匹配原表达式的
So what that means is that the pattern is matched against the expression, which is the source expression.
38
00:03:23,728 --> 00:03:28,512
应用规则会产生一个新的表达式
And the result of the application of the rule is to produce a new expression,
39
00:03:33,616 --> 00:03:34,912
我们称之为目标
which I'll call a target,
40
00:03:38,128 --> 00:03:39,888
这是通过骨架的实例化实现的
by instantiation of a skeleton.
41
00:03:41,632 --> 00:03:43,020
这个叫做实例化
That's called instantiation.
42
00:03:50,720 --> 00:03:54,736
这就是这些规则所描述的过程
So that is the process by which these rules are described.
43
00:03:55,696 --> 00:03:57,264
今天我想要做的是
What I'd like to do today
44
00:03:58,736 --> 00:04:01,088
构建一种语言
is build a language
45
00:04:02,200 --> 00:04:05,488
以及它的解释与执行方法
and a means of interpreting that language, a means of executing that language,
46
00:04:05,744 --> 00:04:08,432
使得这种语言可以直接表述这些规则
where that language allows us to directly express these rules.
47
00:04:10,592 --> 00:04:11,584
我们将要做的是
And what we're going to do
48
00:04:11,580 --> 00:04:17,568
与其通过将规则翻译为程序 让计算机理解并执行
instead of bringing the rules to the level of the computer by writing a program that is those rules
49
00:04:18,384 --> 00:04:21,560
这里主要指 Lisp 程序
in the computer's language--at the moment, in a Lisp--
50
00:04:22,160 --> 00:04:24,496
我们不如让计算机理解我们
we're going to bring the computer to the level of us
51
00:04:25,488 --> 00:04:29,150
我们可以写一些程序让计算机理解这些规则
by writing a way by which the computer can understand rules of this sort.
52
00:04:30,912 --> 00:04:34,768
这又稍微强调了上次的主旨
This is slightly emphasizing the idea that we had last time
53
00:04:35,440 --> 00:04:39,360
与其解决一个特定问题 不如解决一类问题
that we're trying to make a solution to a class of problems rather than a particular one.
54
00:04:39,776 --> 00:04:46,720
如果我为不同的数学运算写规则
The problem is if I want to write rules for a different piece of mathematics,
55
00:04:48,240 --> 00:04:51,392
比如简单代数的化简
say, to simple algebraic simplification or something like that,
56
00:04:51,984 --> 00:04:55,488
或者三角函数运算
or manipulation of trigonometric functions,
57
00:04:56,096 --> 00:05:01,160
如果按照昨天的方法 我就得重新写个不同的程序
I would have to write a different program in using yesterday's method.
58
00:05:01,160 --> 00:05:05,424
与之相反 我把程序中的共有逻辑给封装起来
Whereas I would like to encapsulate all of the things that are common to both of those programs,
59
00:05:06,128 --> 00:05:10,176
也就是匹配、实例化等概念 还有控制结构
meaning the idea of matching, instantiation, the control structure,
60
00:05:10,176 --> 00:05:12,464
这都是非常复杂的事情
which turns out to be very complicated for such a thing,
61
00:05:13,160 --> 00:05:18,460
我想把它们从规则中分开 并封装
I'd like to encapsulate that separately from the rules themselves.
62
00:05:20,064 --> 00:05:22,608
首先让我们看一下表示法
So let's look at, first of all, a representation.
63
00:05:22,624 --> 00:05:24,096
请大家看投影仪上的幻灯片
I'd like to use the overhead here.
64
00:05:24,672 --> 00:05:25,600
已经在这里了
I'd like-- there it is.
65
00:05:26,250 --> 00:05:32,272
我想要把求导的计算规则
I'd like to look at a representation of the rules of calculus for derivatives
66
00:05:33,712 --> 00:05:37,150
表示为我这里写的一种简单语言
in a sort of simple language that I'm writing right here.
67
00:05:38,112 --> 00:05:43,296
我会尽量避免去考虑语法
Now, I'm going to avoid--I'm going to avoid worrying about syntax.
68
00:05:44,280 --> 00:05:49,280
美化它很容易 虽然这个确实挺丑 但我并不关心
We can easily pretty this, and I'm not interested in making-- this is indeed ugly.
69
00:05:49,300 --> 00:05:56,416
这确实不能像dx/dt那样表示
This doesn't look like the beautiful text set dx by dt or something that I'd like to write,
70
00:05:56,768 --> 00:05:58,120
但这并不重要
but that's not essential.
71
00:05:58,880 --> 00:06:00,624
这是一个偶然现象
That's sort of an accidental phenomenon.
72
00:06:01,000 --> 00:06:04,448
这里 我只关心规则的结构
Here, we're just worrying about the fact that the structure of the rules
73
00:06:04,832 --> 00:06:11,700
规则的左边部分代表了我想要匹配的求导表达式
is that there is a left-hand side here, represents the thing I want to match against the derivative expression.
74
00:06:11,808 --> 00:06:13,568
这个表示是说
This is the representation I'm going to say
75
00:06:13,600 --> 00:06:18,320
一个匹配常量的模式变量c
for the derivative of a constant, which we will call c
76
00:06:18,848 --> 00:06:21,200
关于匹配任意表达式的模式变量v求导
respect to the variable we will call v.
77
00:06:23,088 --> 00:06:25,552
我们在右边部分得到的是0
And what we will get on the right-hand side is 0.
78
00:06:26,000 --> 00:06:28,064
这就代表了一个规则
So this represents a rule.
79
00:06:29,260 --> 00:06:34,048
下一条规则是 匹配变量的模式变量v
The next rule will be the derivative of a variable, which we will call v
80
00:06:34,224 --> 00:06:37,740
对同一个模式变量求导 得到的结果是1
respect to the same variable v, and we get a 1.
81
00:06:38,600 --> 00:06:42,176
然而 如果一个匹配变量的模式变量u
However, if we have the derivative of a variable called u
82
00:06:42,410 --> 00:06:44,848
关于另一个模式变量v求导
respect to a different variables v,
83
00:06:45,392 --> 00:06:47,050
那么 结果就是0
we will get 0.
84
00:06:47,840 --> 00:06:52,176
我想让大家看一下 这些规则是如何组织在一起的
I just want you look at these rules a little bit and see how they fit together.
85
00:06:52,512 --> 00:06:54,304
比如说 在这里
For example, over here,
86
00:06:54,736 --> 00:07:01,900
我们要求表达式x1、x2之和的导数
we're going to have the derivative of the sum of an expression called x1 and an expression called x2.
87
00:07:01,900 --> 00:07:05,856
在我们创造的这个语言中
These things that begin with question marks are called pattern variables
88
00:07:06,880 --> 00:07:08,624
以问号开头的叫模式变量
in the language that we're inventing,
89
00:07:08,930 --> 00:07:14,930
我们就像这样来构建这些用来匹配的模式变量
and you see we're just making it up, so pattern variables for matching.
90
00:07:14,930 --> 00:07:20,330
这里 表达式x1加上表达式x2
And so in this-- here we have the derivative of the sum of the expression which we will call x1.
91
00:07:20,330 --> 00:07:26,700
对变量v求导的结果等于右边这里的式子
And the expression we will call x2 with respect to the variable we call v will be-- here is the right-hand side:
92
00:07:26,700 --> 00:07:32,768
右边的式子是一个骨架 表示表达式X1关于变量v求导
the sum of the derivative of that expression x1 with respect to v-- the right-hand side is the skeleton--
93
00:07:33,824 --> 00:07:37,104
加上表达式X2对变量v求导的和
and the derivative of x2 with respect to v.
94
00:07:37,600 --> 00:07:42,384
这里的冒号表示要代换的对象
Colons here will stand for substitution objects.
95
00:07:43,632 --> 00:07:47,232
我们将它们称作“骨架求值”
They're--we'll call them skeleton evaluations.
96
00:07:48,512 --> 00:07:53,072
让我在黑板上写一些语法
So let me put up here on the blackboard for a second some syntax
97
00:07:53,232 --> 00:07:55,568
这样就能知道 在我们这门规则语言中会发生什么
so we'll know what's going on for this rule language.
98
00:07:56,688 --> 00:07:59,888
首先我们要处理模式匹配问题
First of all, we're going to have to worry about the pattern matching.
99
00:08:06,048 --> 00:08:13,120
第一条规则是 形如foo这样的符号与其自身匹配
We're going to have things like a symbol like foo matches exactly itself.
100
00:08:23,520 --> 00:08:31,344
形如(f a b)的表达式 可以匹配这样的表
The expression f of a and b will be used to match any list
101
00:08:36,304 --> 00:08:57,024
表的首元素是f、第二个元素是a、第三个元素是b
whose first element is f, whose second element is a, and whose third element is b.
102
00:08:58,624 --> 00:09:06,992
另外 模式中可能还有形如(? x)这样的规则
Also, another thing we might have in a pattern is that--a question mark with some variable like x.
103
00:09:08,576 --> 00:09:18,672
这个规则可以匹配任意表达式 并将其称为x
And what that means, it says matches anything, which we will call x.
104
00:09:25,456 --> 00:09:29,984
(?c x) 只匹配常量
Question mark c x will match only constants.
105
00:09:31,500 --> 00:09:40,960
并将匹配的常量记作x
So this is something which matches a constant called x.
106
00:09:44,560 --> 00:09:57,072
(?v x)匹配变量 并将匹配的变量记作x
And question mark v x will match a variable, which we call x.
107
00:10:01,664 --> 00:10:03,808
这就是我们正在构建的语言
This is sort of the language we're making up now.
108
00:10:04,192 --> 00:10:09,408
两个对象的比较是基于元素与元素间的比较
If I match two things against each other, then they are compared element by element
109
00:10:10,256 --> 00:10:15,856
模式中的元素可以包含这些语法变量、模式变量
But elements in the pattern may contain these syntactic variables,
110
00:10:17,072 --> 00:10:20,432
它们可以用来匹配任意对象
which will be used to match arbitrary objects.
111
00:10:22,128 --> 00:10:29,280
这样 我就可以用x作为名字取得被匹配对象的值
And we'll get that object as the value in the name x here, for example.
112
00:10:31,056 --> 00:10:37,552
现在 当我们为实例化准备骨架的时候
Now, when we make skeletons for instantiation.
113
00:10:39,504 --> 00:10:41,408
我们可能有这样的东西
Well, then we have things like this.
114
00:10:42,272 --> 00:10:46,336
符号foo实例化为它本身
foo, a symbol, instantiates to itself.
115
00:10:55,080 --> 00:11:05,920
形如(f a b)这样的表 实例化为
Something which is a list like f of a and b, instantiates to--
116
00:11:06,368 --> 00:11:14,752
实例化为一个三元素表
well, f instantiates to a 3-list, a list of three elements,
117
00:11:15,552 --> 00:11:33,376
其元素分别为f、a、b各自实例化后的结果
okay, which are the results of instantiating each of f, a, and b.
118
00:11:36,352 --> 00:11:54,272
(: x) 会被实例化为x的值--也就是被匹配的模式
And x well--we instantiate to the value of x as in the matched pattern.
119
00:12:03,056 --> 00:12:10,080
回头看看这里的幻灯片 我们发现这些都是对象
So going back to the overhead here, we see -- we see that all of those kinds of objects
120
00:12:10,784 --> 00:12:16,060
我们看到 这是一个用来匹配常量的模式变量
we see here a pattern variable which matches a constant,
121
00:12:16,560 --> 00:12:19,024
这是匹配变量的模式变量
a pattern variable which matches a variable,
122
00:12:19,392 --> 00:12:21,744
这是匹配任意表达式的模式变量
a pattern variable which will match anything.
123
00:12:22,720 --> 00:12:24,920
如果我们有了名字一样的两个实例
And if we have two instances of the same name,
124
00:12:25,080 --> 00:12:31,776
想这个是被称作v的单变量表达式
like this is the derivative of the expression which is a variable only whose name will be v
125
00:12:32,864 --> 00:12:36,300
关于一个称作v的任意表达式求导
with respect to some arbitrary expression which we will call v,
126
00:12:36,410 --> 00:12:38,016
因为这个v出现了两次
since this v appears twice,
127
00:12:38,656 --> 00:12:41,072
我们想约束它们相同
we're going to want that to mean they have to be the same.
128
00:12:42,688 --> 00:12:45,008
只有它俩完全一致才算是匹配
The only consistent match is that those are the same.
129
00:12:45,230 --> 00:12:47,230
所以在这里我们在构建一个语言
So here, we're making up a language.
130
00:12:47,600 --> 00:12:50,660
事实上 这是一件非常好的事情
And in fact, that's a very nice thing to be doing.
131
00:12:50,660 --> 00:12:52,600
构建一个语言非常有趣
It's so much fun to make up a language.
132
00:12:52,600 --> 00:12:54,330
并且大家一直在做这些
And you do this all the time.
133
00:12:54,330 --> 00:12:56,896
大家做过的真正强大的设计
And the really most powerful design things you ever do
134
00:12:57,232 --> 00:13:00,208
是构建一个语言来解决这样的问题
are sort of making up a language to solve problems like this.
135
00:13:02,064 --> 00:13:05,344
我们回头看看这些规则
Now, here we go back here and look at some of these rules.
136
00:13:05,808 --> 00:13:07,100
这就是它们的全部
Well, there's a whole set of them.
137
00:13:07,100 --> 00:13:12,430
我们有加法、乘法 就像我们之前看到的一样
I mean, there's one for addition and one for multiplication, just like we had before.
138
00:13:12,430 --> 00:13:17,376
x1+x2 关于变量v的导数等于
The derivative of the product of x1 and x2 with respect to v is
139
00:13:17,680 --> 00:13:26,528
x2对v求导乘以x1 加上 x1对v求导乘以x2
the sum of the product of x1 and the derivative x2 with respect to v and the product of the derivative of x1 and x2.
140
00:13:27,264 --> 00:13:29,100
这是指数运算的求导规则
And here we have exponentiation.
141
00:13:29,248 --> 00:13:32,110
虽然这里展示完了所有的规则 但还可以按照我们意愿添加
And, of course, we run off the end down here. We get as many as we like.
142
00:13:32,704 --> 00:13:39,104
我们在这里 建立了关于求导的规则列表
But the whole thing over here, I'm giving this--this list of rules the name "derivative rules."
143
00:13:40,400 --> 00:13:44,330
一旦我们有了这些 我们应该做什么呢?
What would we do with such a thing once we have it?
144
00:13:45,408 --> 00:13:47,840
恩 我将给你们展示最好的思想之一
Well, one of the nicest ideas, first of all,
145
00:13:48,448 --> 00:13:51,680
然后我们将花一整天来鼓捣它
is I'm going to write for you, and we're going to play with it all day.
146
00:13:52,288 --> 00:13:57,376
我将向大家展示一个叫做simplifier的程序
What I'm going to write for you is a program called simplifier,
147
00:13:57,824 --> 00:13:59,472
一个通用的化简器
the general-purpose simplifier.
148
00:14:00,090 --> 00:14:17,104
我们将求导规则deriv-rules送入simplifier从而产生dsimp
And we're going to say something like define dsimp to be a simplifier of the derivative rules.
149
00:14:23,744 --> 00:14:28,752
传给simplifier过程一套规则 它会返回给我们一个过程
And what simplifier is going to do is, given a set of rules, it will produce for me a procedure
150
00:14:29,328 --> 00:14:34,592
它根据这些规则对表达式进行化简
which will simplify expressions containing the things that are referred to by these rules.
151
00:14:37,392 --> 00:14:43,936
因此 这里会返回一个按照你制定的规则所构造的过程
So here will be a procedure constructed for your purposes to simplify things with derivatives in them
152
00:14:44,590 --> 00:14:49,568
使得在我们进入 Lisp 系统后 在命令提示符后面
such that, after that, if we're typing at some Lisp system, and we get a prompt,
153
00:14:49,888 --> 00:15:03,936
输入 (DSIMP '(dd (+ x y) x))
and we say dsimp, for example, of the derivative of the sum of x and y with respect to x--
154
00:15:06,992 --> 00:15:10,976
注意这里的引号 因为我们讨论的是表达式的求导
note the quote here because I'm talking about the expression which is the derivative--
155
00:15:13,296 --> 00:15:17,760
然后我将得到结果 (+ 1 0)
then I will get back as a result plus 1 0.
156
00:15:19,968 --> 00:15:24,600
因为 (x+y)' = x' + y'
Because the derivative of x plus y is the derivative of x plus derivative y.
157
00:15:24,600 --> 00:15:26,224
x'=1
The derivative of x with respect to x is 1.
158
00:15:26,384 --> 00:15:27,824
y'=0(关于x求导)
The derivative of y with respect to x is 0.
159
00:15:29,424 --> 00:15:30,464
这不是我想要的
It's not what we're going to get.
160
00:15:31,184 --> 00:15:34,656
我还没有在这里做代数化简
I haven't put any simplification at that level-- algebraic simplification--yet.
161
00:15:36,160 --> 00:15:41,536
当然一旦我有了这个东西那么我们可以 -- 我们可以看看其它的规则
Of course, once we have such a thing, then we can--then we can look at other rules.
162
00:15:41,960 --> 00:15:49,360
比如 我们看这张幻灯片
So, for example, we can, if we go to the slide, OK?
163
00:15:49,360 --> 00:15:54,128
这里是其它的规则 代数操作规则
Here, for example, are other rules that we might have, algebraic manipulation rules,
164
00:15:56,000 --> 00:15:58,384
它们可以用来化简代数表达式
ones that would be used for simplifying algebraic expressions.
165
00:15:59,008 --> 00:16:02,064
考察一下这些规则
For example, just looking at some of these,
166
00:16:03,040 --> 00:16:09,200
这条规则的左部分是说 某个运算符应用到常量e1和常量e2上
the left-hand side says any operator applied to a constant e1 and a constant e2
167
00:16:09,328 --> 00:16:14,512
其结果就是求(op e1 e2)的值
is the result of evaluating that operator on the constants e1 and e2.
168
00:16:15,888 --> 00:16:21,568
或者 当一个运算符应用在任意表达式e1和常量e2上
Or an operator, applied to e1, any expression e1 and a constant e2,
169
00:16:21,696 --> 00:16:23,872
化简结果会把常量前置
is going to move the constant forward.
170
00:16:24,528 --> 00:16:27,680
这就变成了((: op) (: e2) (: e1))
So that'll turn into the operator with e2 followed by e1.
171
00:16:28,592 --> 00:16:30,112
为什么要这么做?我不知道
Why I did that, I don't know.
172
00:16:30,224 --> 00:16:33,168
比如说 如果系统中有除法的话 这就不对
It wouldn't work if I had division, for example.
173
00:16:33,530 --> 00:16:35,312
换句话说 规则有漏洞
So there's a bug in the rules, if you like.
174
00:16:36,672 --> 00:16:40,864
所以0与任何表达式e的和 等于表达式e
So the sum of 0 and e is e.
175
00:16:42,176 --> 00:16:45,312
1乘以任何表达式e的结果是表达式e
The product of 1 and any expression e is e.
176
00:16:46,128 --> 00:16:49,136
0乘以任何表达式e的结果是0
The product of 0 and any expression e is 0.
177
00:16:49,330 --> 00:16:52,720
我们可以有任意复杂的规则
Just looking at some more of these rules, we could have arbitrarily complicated ones.
178
00:16:53,696 --> 00:16:54,816
比如说
We could have things like
179
00:16:55,360 --> 00:17:01,696
常量e1*(常量e2*任意表达式e3)
the product of the constant e1 and any constant e2 with e3
180
00:17:02,350 --> 00:17:11,968
可以化简为 (e1*e2)*e3
is the result of multiplying the result of multiplying now the constants e1 and e2 together and putting e3 there.
181
00:17:13,360 --> 00:17:16,768
这个规则是说 先把常量组合起来
So it says combine the constants that I had,
182
00:17:16,768 --> 00:17:22,704
如果有形如 e1*(e2*e3) 的式子 而且e1 e2都是常量 就先把常量乘起来
which was if I had a product of e1 and e2 and e3 just multiply--I mean and e1 and e2 are both constants, multiply them.
183
00:17:23,840 --> 00:17:25,488
你可以根据意愿来构建这些规则
And you can make up the rules as you like.
184
00:17:25,792 --> 00:17:26,944
这里还有很多规则
There are lots of them here.
185
00:17:27,424 --> 00:17:31,040
这些规则是很复杂的 比如--
There are things as complicated, for example, as--
186
00:17:31,260 --> 00:17:33,930
请看 这条规则是分配律
oh, I suppose down here some distributive law, you see.
187
00:17:33,930 --> 00:17:38,576
任何表达式c乘以d和e
The product of any object c and the sum of d and e
188
00:17:39,024 --> 00:17:43,664
等于 c与d的积加上c与e的积
gives the result as the same as the sum of the product of c and d and the product of c and e.
189
00:17:45,312 --> 00:17:48,672
我并不关心这些规则具体描述的什么
Now, what exactly these rules are doesn't very much interest me.
190
00:17:49,168 --> 00:17:52,976
我们将要构建一种语言 用来解释这些规则
We're going to be writing the language that will allow us to interpret these rules
191
00:17:55,504 --> 00:17:57,488
这样我们就可以按我们的意愿编写规则
so that we can, in fact, make up whatever rules we like,
192
00:17:58,352 --> 00:18:00,144
这是另外一种程序设计语言
another whole language of programming.
193
00:18:03,392 --> 00:18:04,048
来看看
Well, let's see.
194
00:18:05,184 --> 00:18:06,960
我还没告诉你我们要怎么做
I haven't told you how we're going to do this.
195
00:18:07,536 --> 00:18:10,064
当然我们马上就要讲了
And, of course, for a while, we're going to work on that.
196
00:18:10,896 --> 00:18:15,408
但真正的问题是:宏观地看 我要做什么?
But there's a real question of what is--what am I going to do at all at a large scale?
197
00:18:17,088 --> 00:18:18,224
这些规则是如何运作的?
How do these rules work?
198
00:18:19,008 --> 00:18:25,456
化简程序是如何用这些规则来输入的表达式 并返回一个合理的答案?
How is the simplifier program going to manipulate these rules with your expression to produce a reasonable answer?
199
00:18:26,224 --> 00:18:29,856
首先 我认为我们有一大堆的规则
Well, first, I'd like to think about these rules as being some sort of deck of them.
200
00:18:32,528 --> 00:18:34,224
这里有全部的规则
So here I have a whole bunch of rules,
201