forked from DeathKing/Learning-SICP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec4b_512kb.mp4.srt
7291 lines (5606 loc) · 114 KB
/
lec4b_512kb.mp4.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
0
00:00:00,000 --> 00:00:03,936
1
00:00:03,936 --> 00:00:04,279
[MUSIC-- "JESU, JOY OF
MAN'S DESIRING" BY
2
00:00:04,279 --> 00:00:05,529
JOHANN SEBASTIAN BACH]
3
00:00:05,529 --> 00:00:20,180
4
00:00:20,180 --> 00:00:21,840
PROFESSOR: So far in this course
we've been talking a
5
00:00:21,840 --> 00:00:23,780
lot about data abstraction.
6
00:00:23,780 --> 00:00:28,230
And remember the idea is that
we build systems that have
7
00:00:28,230 --> 00:00:31,980
these horizontal barriers in
them, these abstraction
8
00:00:31,980 --> 00:00:38,490
barriers that separate use,
the way you might use some
9
00:00:38,490 --> 00:00:41,180
data object, from the way
you might represent it.
10
00:00:41,180 --> 00:00:48,985
11
00:00:48,985 --> 00:00:51,760
Or another way to think of that
is up here you have the
12
00:00:51,760 --> 00:00:57,110
boss who's going to be using
some sort of data object.
13
00:00:57,110 --> 00:01:02,310
And down here is George
who's implemented it.
14
00:01:02,310 --> 00:01:05,760
Now this notion of separating
use from representation so you
15
00:01:05,760 --> 00:01:10,930
can think about these two
problems separately is a very,
16
00:01:10,930 --> 00:01:15,930
very powerful programming
methodology, data abstraction.
17
00:01:15,930 --> 00:01:21,040
On the other hand, it's not
really sufficient for really
18
00:01:21,040 --> 00:01:28,640
complex systems. And the problem
with this is George.
19
00:01:28,640 --> 00:01:32,110
Or actually, the problem
is that there
20
00:01:32,110 --> 00:01:34,630
are a lot of Georges.
21
00:01:34,630 --> 00:01:35,390
Let's be concrete.
22
00:01:35,390 --> 00:01:41,192
Let's suppose there is George,
and there's also Martha.
23
00:01:41,192 --> 00:01:46,040
OK, now George and Martha are
both working on this system,
24
00:01:46,040 --> 00:01:49,250
both designing representations,
and
25
00:01:49,250 --> 00:01:51,750
absolutely are incompatible.
26
00:01:51,750 --> 00:01:54,620
They wouldn't cooperate on a
representation under any
27
00:01:54,620 --> 00:01:57,250
circumstances.
28
00:01:57,250 --> 00:02:00,060
And the problem is you would
like to have some system where
29
00:02:00,060 --> 00:02:05,380
both George and Martha are
designing representations, and
30
00:02:05,380 --> 00:02:09,756
yet, if you're above this
abstraction barrier you don't
31
00:02:09,756 --> 00:02:12,360
want to have to worry about
that, whether something is
32
00:02:12,360 --> 00:02:14,180
done by George or by Martha.
33
00:02:14,180 --> 00:02:15,430
And you don't want George
and Martha to
34
00:02:15,430 --> 00:02:16,630
interfere with each other.
35
00:02:16,630 --> 00:02:20,310
Somehow in designing a system,
you not only want these
36
00:02:20,310 --> 00:02:26,300
horizontal barriers, but you
also want some kind of
37
00:02:26,300 --> 00:02:32,980
vertical barrier to keep George
and Martha separate.
38
00:02:32,980 --> 00:02:36,560
Let me be a little bit
more concrete.
39
00:02:36,560 --> 00:02:42,650
Imagine that you're thinking
about personnel records for a
40
00:02:42,650 --> 00:02:48,180
large company with a lot of
loosely linked divisions that
41
00:02:48,180 --> 00:02:50,430
don't cooperate very
well either.
42
00:02:50,430 --> 00:02:57,040
And imagine even that this
company is formed by merging a
43
00:02:57,040 --> 00:02:59,450
whole bunch of companies that
already have their personnel
44
00:02:59,450 --> 00:03:00,700
record system set up.
45
00:03:00,700 --> 00:03:03,250
46
00:03:03,250 --> 00:03:06,570
And imagine that once these
divisions are all linked in
47
00:03:06,570 --> 00:03:08,530
some kind of very sophisticated
satellite
48
00:03:08,530 --> 00:03:12,240
network, and all these databases
are put together.
49
00:03:12,240 --> 00:03:17,260
And what you'd like to do is,
from any place in the company,
50
00:03:17,260 --> 00:03:23,130
to be able to say things like,
oh, what's the name in a
51
00:03:23,130 --> 00:03:26,400
personnel record?
52
00:03:26,400 --> 00:03:30,540
Or, what's the job description
in a personnel record?
53
00:03:30,540 --> 00:03:34,840
And not have to worry about the
fact that each division
54
00:03:34,840 --> 00:03:36,760
obviously is going to have
completely separate
55
00:03:36,760 --> 00:03:41,580
conventions for how you might
implement these records.
56
00:03:41,580 --> 00:03:44,960
From this point you don't
want to know about that.
57
00:03:44,960 --> 00:03:48,430
Well how could you
possibly do that?
58
00:03:48,430 --> 00:03:52,640
One way, of course, is to send
down an edict from somewhere
59
00:03:52,640 --> 00:03:56,290
that everybody has to change
their format to some fixed
60
00:03:56,290 --> 00:03:58,070
compatible thing.
61
00:03:58,070 --> 00:04:01,820
That's what people often try,
and of course it never works.
62
00:04:01,820 --> 00:04:07,340
Another thing that you might
want to do is somehow arrange
63
00:04:07,340 --> 00:04:11,250
it so you can have these
vertical barriers.
64
00:04:11,250 --> 00:04:14,430
So that when you ask for the
name of a personnel record,
65
00:04:14,430 --> 00:04:17,970
somehow, whatever format it
happens to be, name will
66
00:04:17,970 --> 00:04:19,470
figure out how to do
the right thing.
67
00:04:19,470 --> 00:04:22,730
68
00:04:22,730 --> 00:04:26,260
We want name to be, so-called,
a generic operator.
69
00:04:26,260 --> 00:04:30,060
Generic operator means what it
sort of precisely does depends
70
00:04:30,060 --> 00:04:33,650
on the kind of data that
it's looking at.
71
00:04:33,650 --> 00:04:37,100
More than that, you'd like to
design the system so that the
72
00:04:37,100 --> 00:04:43,250
next time a new division comes
into the company they don't
73
00:04:43,250 --> 00:04:45,640
have to make any big changes in
what they're already doing
74
00:04:45,640 --> 00:04:50,110
to link into this system, and
the rest of the company
75
00:04:50,110 --> 00:04:53,500
doesn't have to make any big
changes to admit their stuff
76
00:04:53,500 --> 00:04:55,520
to the system.
77
00:04:55,520 --> 00:04:58,700
So that's the problem you should
be thinking about.
78
00:04:58,700 --> 00:05:00,770
Like it's sort of
just your work.
79
00:05:00,770 --> 00:05:02,390
You want to be able to
include new things by
80
00:05:02,390 --> 00:05:03,640
making minimal changes.
81
00:05:03,640 --> 00:05:05,980
82
00:05:05,980 --> 00:05:07,340
OK, well that's the problem
that we'll be
83
00:05:07,340 --> 00:05:09,440
talking about today.
84
00:05:09,440 --> 00:05:13,140
And you should have this sort
of distributed personnel
85
00:05:13,140 --> 00:05:14,240
record system in your mind.
86
00:05:14,240 --> 00:05:16,620
But actually the one I'll be
talking about is a problem
87
00:05:16,620 --> 00:05:18,900
that's a little bit more
self-contained than that.
88
00:05:18,900 --> 00:05:21,870
that'll bring up the issues,
I think, more clearly.
89
00:05:21,870 --> 00:05:25,300
That's the problem of doing a
system that does arithmetic on
90
00:05:25,300 --> 00:05:27,770
complex numbers.
91
00:05:27,770 --> 00:05:30,690
So let's take a look here.
92
00:05:30,690 --> 00:05:32,460
Just as a little review,
there are things
93
00:05:32,460 --> 00:05:35,250
called complex numbers.
94
00:05:35,250 --> 00:05:36,960
Complex number you can think
of as a point in
95
00:05:36,960 --> 00:05:39,370
the plane, or z.
96
00:05:39,370 --> 00:05:46,230
And you can represent a point
either by its real-part and
97
00:05:46,230 --> 00:05:47,190
its imaginary-part.
98
00:05:47,190 --> 00:05:51,690
So if this is z and its
real-part is this much, and
99
00:05:51,690 --> 00:05:54,880
its imaginary-part is that
much, and you write z
100
00:05:54,880 --> 00:05:56,130
equals x plus iy.
101
00:05:56,130 --> 00:05:59,110
102
00:05:59,110 --> 00:06:03,210
Or another way to represent a
complex number is by saying,
103
00:06:03,210 --> 00:06:10,900
what's the distance from the
origin, and what's the angle?
104
00:06:10,900 --> 00:06:13,540
So that represents a complex
number as its
105
00:06:13,540 --> 00:06:16,670
radius times an angle.
106
00:06:16,670 --> 00:06:19,520
107
00:06:19,520 --> 00:06:20,820
This one's called-- the
original one's called
108
00:06:20,820 --> 00:06:24,690
rectangular form, rectangular
representation, real- and
109
00:06:24,690 --> 00:06:28,640
imaginary-part, or polar
representation.
110
00:06:28,640 --> 00:06:30,040
Magnitude and angle--
111
00:06:30,040 --> 00:06:32,260
and if you know the real- and
imaginary-part, you can figure
112
00:06:32,260 --> 00:06:33,720
out the magnitude and angle.
113
00:06:33,720 --> 00:06:37,190
If you know x and y, you can
get r by this formula.
114
00:06:37,190 --> 00:06:39,480
Square root of sum of the
squares, and you can get the
115
00:06:39,480 --> 00:06:41,420
angle as an arctangent.
116
00:06:41,420 --> 00:06:44,420
Or conversely, if you knew
r and A you could
117
00:06:44,420 --> 00:06:45,800
figure out x and y.
118
00:06:45,800 --> 00:06:49,435
x is r times the cosine of A,
and y is r times the sine of
119
00:06:49,435 --> 00:06:52,490
A. All right, so there's
these two.
120
00:06:52,490 --> 00:06:54,130
They're complex numbers.
121
00:06:54,130 --> 00:06:55,810
You can think of them
either in polar form
122
00:06:55,810 --> 00:06:57,150
or rectangular form.
123
00:06:57,150 --> 00:06:59,830
What we would like to do is
make a system that does
124
00:06:59,830 --> 00:07:03,850
arithmetic on complex numbers.
125
00:07:03,850 --> 00:07:05,580
In other words, what
we'd like--
126
00:07:05,580 --> 00:07:07,380
just like the rational
number example--
127
00:07:07,380 --> 00:07:11,120
is to have some operations plus
c, which is going to take
128
00:07:11,120 --> 00:07:14,640
two complex numbers and add
them, subtract them, and
129
00:07:14,640 --> 00:07:16,910
multiply them, and
divide them.
130
00:07:16,910 --> 00:07:20,730
131
00:07:20,730 --> 00:07:25,280
OK, well there's little bit
of mathematics behind it.
132
00:07:25,280 --> 00:07:29,800
What are the actual formulas for
manipulating such things?
133
00:07:29,800 --> 00:07:34,270
And it's sort of not important
where they come from, but just
134
00:07:34,270 --> 00:07:36,120
as an implementer let's see--
135
00:07:36,120 --> 00:07:40,030
if you want to add two complex
numbers it's pretty easy to
136
00:07:40,030 --> 00:07:42,660
get its real-part and
its imaginary-part.
137
00:07:42,660 --> 00:07:47,810
The real-part of the sum of
two complex numbers, the
138
00:07:47,810 --> 00:07:53,720
real-part of the z1 plus z2 is
the real-part of z1 plus the
139
00:07:53,720 --> 00:07:54,970
real-part of z2.
140
00:07:54,970 --> 00:07:57,820
141
00:07:57,820 --> 00:08:02,770
And the imaginary-part of z1
plus z2 is the imaginary part
142
00:08:02,770 --> 00:08:07,410
of z1 plus the imaginary
part of z2.
143
00:08:07,410 --> 00:08:09,480
So it's pretty easy to
add complex numbers.
144
00:08:09,480 --> 00:08:12,320
You just add the corresponding
parts and make a new complex
145
00:08:12,320 --> 00:08:13,400
number with those parts.
146
00:08:13,400 --> 00:08:17,180
If you want to multiply them,
it's kind of nice to do it in
147
00:08:17,180 --> 00:08:17,840
polar form.
148
00:08:17,840 --> 00:08:21,810
Because if you have two complex
numbers, the magnitude
149
00:08:21,810 --> 00:08:26,285
of their product is here, the
product of the magnitudes.
150
00:08:26,285 --> 00:08:28,850
151
00:08:28,850 --> 00:08:35,809
And the angle of the product
is the sum of the angles.
152
00:08:35,809 --> 00:08:39,179
So that's sort of mathematics
that allows you to do
153
00:08:39,179 --> 00:08:40,549
arithmetic on complex numbers.
154
00:08:40,549 --> 00:08:43,720
Let's actually think about
the implementation.
155
00:08:43,720 --> 00:08:49,330
Well we do it just like
rational numbers.
156
00:08:49,330 --> 00:08:52,200
We come down, we assume
we have some
157
00:08:52,200 --> 00:08:53,840
constructors and selectors.
158
00:08:53,840 --> 00:08:55,330
What would we like?
159
00:08:55,330 --> 00:08:58,890
Well let's assume that we make
a data object cloud, which is
160
00:08:58,890 --> 00:09:02,510
a complex number that has some
stuff in it, and that we can
161
00:09:02,510 --> 00:09:05,870
get out from a complex number
the real-part, or the
162
00:09:05,870 --> 00:09:12,150
imaginary-part, or the
magnitude, or the angle.
163
00:09:12,150 --> 00:09:14,320
We want some ways of making
complex numbers-- not only
164
00:09:14,320 --> 00:09:16,800
selectors, but constructors.
165
00:09:16,800 --> 00:09:20,160
So we'll assume we have a thing
called make-rectangular.
166
00:09:20,160 --> 00:09:24,510
What make-rectangular is going
to do is take a real-part and
167
00:09:24,510 --> 00:09:28,610
an imaginary-part and construct
a complex number
168
00:09:28,610 --> 00:09:31,920
with those parts.
169
00:09:31,920 --> 00:09:35,010
Similarly, we can have
make-polar which will take a
170
00:09:35,010 --> 00:09:42,550
magnitude and an angle, and
construct a complex number
171
00:09:42,550 --> 00:09:44,680
which has that magnitude
and angle.
172
00:09:44,680 --> 00:09:45,460
So here's a system.
173
00:09:45,460 --> 00:09:48,910
We'll have two constructors
and four selectors.
174
00:09:48,910 --> 00:09:55,150
And now, just like before, in
terms of that abstract data
175
00:09:55,150 --> 00:09:59,220
we'll go ahead and implement our
complex number operations.
176
00:09:59,220 --> 00:10:03,280
And here you can see translated
into Lisp code just
177
00:10:03,280 --> 00:10:08,330
the arithmetic formulas
I put down before.
178
00:10:08,330 --> 00:10:13,450
If I want to add two complex
numbers I will make a complex
179
00:10:13,450 --> 00:10:16,630
number out of its real-
and imaginary-parts.
180
00:10:16,630 --> 00:10:19,680
The real part of the complex
number I'm going to make is
181
00:10:19,680 --> 00:10:23,310
the sum of the real-parts.
182
00:10:23,310 --> 00:10:25,250
The imaginary part of the
complex number I'm going to
183
00:10:25,250 --> 00:10:27,005
make is the sum of the
imaginary-parts.
184
00:10:27,005 --> 00:10:30,310
185
00:10:30,310 --> 00:10:31,990
I put those together, make
a complex number.
186
00:10:31,990 --> 00:10:35,780
That's how I implement complex
number addition.
187
00:10:35,780 --> 00:10:39,650
Subtraction is essentially
the same.
188
00:10:39,650 --> 00:10:45,140
All I do is subtract the parts
rather than add them.
189
00:10:45,140 --> 00:10:47,980
To multiply two complex
numbers, I
190
00:10:47,980 --> 00:10:49,270
use the other formula.
191
00:10:49,270 --> 00:10:55,350
I'll make a complex number out
of a magnitude and angle.
192
00:10:55,350 --> 00:10:58,740
The magnitude is going to be the
product of the magnitudes
193
00:10:58,740 --> 00:11:00,465
of the two complex numbers
I'm multiplying.
194
00:11:00,465 --> 00:11:03,710
195
00:11:03,710 --> 00:11:06,980
And the angle is going to be the
sum of the angles of the
196
00:11:06,980 --> 00:11:09,620
two complex numbers
I'm multiplying.
197
00:11:09,620 --> 00:11:11,230
So there's multiplication.
198
00:11:11,230 --> 00:11:17,370
And then division, division
is almost the same.
199
00:11:17,370 --> 00:11:19,660
Here I divide the magnitudes
and subtract the angles.
200
00:11:19,660 --> 00:11:28,640
201
00:11:28,640 --> 00:11:31,870
Now I've implemented
the operations.
202
00:11:31,870 --> 00:11:33,640
And what do we do?
203
00:11:33,640 --> 00:11:36,060
We call on George.
204
00:11:36,060 --> 00:11:38,070
We've done the use, let's
worry about the
205
00:11:38,070 --> 00:11:38,800
representation.
206
00:11:38,800 --> 00:11:42,200
We'll call on George and say to
George, go ahead and build
207
00:11:42,200 --> 00:11:45,250
us a complex number
representation.
208
00:11:45,250 --> 00:11:47,770
Well that's fine.
209
00:11:47,770 --> 00:11:52,660
George can say, we'll implement
a complex number
210
00:11:52,660 --> 00:11:56,400
simply as a pair that has
the real-part and the
211
00:11:56,400 --> 00:11:57,200
imaginary-part.
212