1 Star 0 Fork 0

jacklisp/Learning-SICP

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lec4b.eng.ass 120.19 KB
一键复制 编辑 原始数据 按行查看 历史
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: TV.601
PlayResX: 640
PlayResY: 480
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: EN,Calisto MT,21,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1
Style: Declare,微软雅黑,30,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,2,0,8,10,10,10,1
Style: staff,微软雅黑,30,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,2,5,10,10,10,1
Style: title,微软雅黑,35,&H001D64D9,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,1,5,10,10,10,1
Style: Default,雅黑宋体,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,1,0,2,10,10,30,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:11.40,0:00:16.50,EN,,0,0,0,,Generic Operators
Dialogue: 0,0:00:20.18,0:00:21.84,EN,,0,0,0,,PROFESSOR: So far in this course we've been talking
Dialogue: 0,0:00:21.84,0:00:23.78,EN,,0,0,0,,a lot about data abstraction.
Dialogue: 0,0:00:23.78,0:00:27.15,EN,,0,0,0,,And remember the idea is that we build systems
Dialogue: 0,0:00:27.74,0:00:32.56,EN,,0,0,0,,that have these horizontal barriers in them, these abstraction barriers
Dialogue: 0,0:00:33.42,0:00:39.21,EN,,0,0,0,,that separate use, the way you might use some data object,
Dialogue: 0,0:00:39.93,0:00:41.18,EN,,0,0,0,,from the way you might represent it.
Dialogue: 0,0:00:49.40,0:00:52.03,EN,,0,0,0,,Or another way to think of that is up here you have the boss
Dialogue: 0,0:00:52.11,0:00:55.50,EN,,0,0,0,,who's going to be using some sort of data object.
Dialogue: 0,0:00:57.11,0:01:02.31,EN,,0,0,0,,And down here is George who's implemented it.
Dialogue: 0,0:01:02.31,0:01:05.42,EN,,0,0,0,,Now this notion of separating use from representation
Dialogue: 0,0:01:05.44,0:01:09.76,EN,,0,0,0,,so you can think about these two problems separately
Dialogue: 0,0:01:10.60,0:01:14.76,EN,,0,0,0,,is a very,very powerful programming methodology, data abstraction.
Dialogue: 0,0:01:15.93,0:01:18.81,EN,,0,0,0,,On the other hand, it's not really sufficient
Dialogue: 0,0:01:19.56,0:01:21.84,EN,,0,0,0,,for really complex systems.
Dialogue: 0,0:01:22.96,0:01:27.64,EN,,0,0,0,,And the problem with this is George.
Dialogue: 0,0:01:28.64,0:01:32.09,EN,,0,0,0,,Or actually, the problem is that
Dialogue: 0,0:01:32.09,0:01:32.78,EN,,0,0,0,,there are a lot of Georges.
Dialogue: 0,0:01:34.63,0:01:35.39,EN,,0,0,0,,Let's be concrete.
Dialogue: 0,0:01:35.39,0:01:39.18,EN,,0,0,0,,Let's suppose there is George,and there's also Martha.
Dialogue: 0,0:01:41.19,0:01:44.22,EN,,0,0,0,,OK, now George and Martha are both working on this system,
Dialogue: 0,0:01:46.04,0:01:47.29,EN,,0,0,0,,both designing representations,
Dialogue: 0,0:01:48.41,0:01:50.67,EN,,0,0,0,,and absolutely are incompatible.
Dialogue: 0,0:01:51.75,0:01:53.62,EN,,0,0,0,,They wouldn't cooperate on a representation
Dialogue: 0,0:01:54.01,0:01:55.34,EN,,0,0,0,,under any circumstances.
Dialogue: 0,0:01:57.48,0:01:59.72,EN,,0,0,0,,And the problem is you would like to have some system
Dialogue: 0,0:02:00.06,0:02:02.60,EN,,0,0,0,,where both George and Martha are designing representations,
Dialogue: 0,0:02:03.82,0:02:08.08,EN,,0,0,0,,and, yet, if you're above this abstraction barrier
Dialogue: 0,0:02:09.40,0:02:11.04,EN,,0,0,0,,you don't want to have to worry about that,
Dialogue: 0,0:02:11.66,0:02:14.18,EN,,0,0,0,,whether something is done by George or by Martha.
Dialogue: 0,0:02:14.18,0:02:15.43,EN,,0,0,0,,And you don't want George and Martha to
Dialogue: 0,0:02:15.43,0:02:16.48,EN,,0,0,0,,interfere with each other.
Dialogue: 0,0:02:16.63,0:02:20.31,EN,,0,0,0,,Somehow in designing a system, you not only want these
Dialogue: 0,0:02:20.31,0:02:23.84,EN,,0,0,0,,horizontal barriers, but you also want some kind of
Dialogue: 0,0:02:25.82,0:02:30.64,EN,,0,0,0,,some kind of vertical barrier to keep George and Martha separate.
Dialogue: 0,0:02:32.98,0:02:35.40,EN,,0,0,0,,Let me be a little bit more concrete.
Dialogue: 0,0:02:36.56,0:02:40.54,EN,,0,0,0,,Imagine that you're thinking about personnel records
Dialogue: 0,0:02:41.18,0:02:46.11,EN,,0,0,0,,for a large company with a lot of loosely linked divisions
Dialogue: 0,0:02:47.90,0:02:49.71,EN,,0,0,0,,that don't cooperate very well either.
Dialogue: 0,0:02:50.43,0:02:57.04,EN,,0,0,0,,And imagine even that this company is formed by merging a
Dialogue: 0,0:02:57.04,0:02:59.45,EN,,0,0,0,,whole bunch of companies that already have their personnel
Dialogue: 0,0:02:59.45,0:03:00.70,EN,,0,0,0,,record system set up.
Dialogue: 0,0:03:03.25,0:03:06.57,EN,,0,0,0,,And imagine that once these divisions are all linked in
Dialogue: 0,0:03:06.57,0:03:08.53,EN,,0,0,0,,some kind of very sophisticated satellite
Dialogue: 0,0:03:08.53,0:03:10.52,EN,,0,0,0,,network, and all these databases are put together.
Dialogue: 0,0:03:12.24,0:03:13.85,EN,,0,0,0,,And what you'd like to do
Dialogue: 0,0:03:14.84,0:03:16.33,EN,,0,0,0,,is from any place in the company,
Dialogue: 0,0:03:17.26,0:03:23.13,EN,,0,0,0,,to be able to say things like,oh, what's the name in a
Dialogue: 0,0:03:23.13,0:03:23.87,EN,,0,0,0,,personnel record?
Dialogue: 0,0:03:26.30,0:03:29.15,EN,,0,0,0,,Or, what's the job description in a personnel record?
Dialogue: 0,0:03:30.54,0:03:34.40,EN,,0,0,0,,And not have to worry about the fact that each division
Dialogue: 0,0:03:34.84,0:03:36.76,EN,,0,0,0,,obviously is going to have completely separate
Dialogue: 0,0:03:36.76,0:03:39.37,EN,,0,0,0,,conventions for how you might implement these records.
Dialogue: 0,0:03:41.58,0:03:43.26,EN,,0,0,0,,From this point you don't want to know about that.
Dialogue: 0,0:03:44.96,0:03:47.92,EN,,0,0,0,,Well how could you possibly do that?
Dialogue: 0,0:03:48.43,0:03:52.41,EN,,0,0,0,,One way, of course, is to send down an edict from somewhere
Dialogue: 0,0:03:52.64,0:03:56.29,EN,,0,0,0,,that everybody has to change their format to some fixed
Dialogue: 0,0:03:56.29,0:03:57.24,EN,,0,0,0,,compatible thing.
Dialogue: 0,0:03:58.07,0:04:00.12,EN,,0,0,0,,That's what people often try, and of course it never works.
Dialogue: 0,0:04:01.82,0:04:07.34,EN,,0,0,0,,Another thing that you might want to do is somehow arrange
Dialogue: 0,0:04:08.33,0:04:09.90,EN,,0,0,0,,it so you can have these vertical barriers.
Dialogue: 0,0:04:11.25,0:04:14.40,EN,,0,0,0,,So that when you ask for the name of a personnel record,
Dialogue: 0,0:04:14.43,0:04:17.97,EN,,0,0,0,,somehow, whatever format it happens to be, name will
Dialogue: 0,0:04:17.97,0:04:19.42,EN,,0,0,0,,figure out how to do the right thing.
Dialogue: 0,0:04:22.73,0:04:25.53,EN,,0,0,0,,We want name to be, so-called, a generic operator.
Dialogue: 0,0:04:26.26,0:04:30.06,EN,,0,0,0,,Generic operator means what it sort of precisely does depends
Dialogue: 0,0:04:30.06,0:04:31.69,EN,,0,0,0,,on the kind of data that it's looking at.
Dialogue: 0,0:04:33.65,0:04:36.62,EN,,0,0,0,,More than that, you'd like to design the system so that the
Dialogue: 0,0:04:36.92,0:04:39.79,EN,,0,0,0,,next time a new division comes into the company
Dialogue: 0,0:04:42.51,0:04:45.64,EN,,0,0,0,,they don't have to make any big changes in what they're already doing
Dialogue: 0,0:04:45.64,0:04:50.11,EN,,0,0,0,,to link into this system, and the rest of the company
Dialogue: 0,0:04:50.11,0:04:52.01,EN,,0,0,0,,doesn't have to make any big changes
Dialogue: 0,0:04:52.27,0:04:53.93,EN,,0,0,0,,to admit their stuff to the system.
Dialogue: 0,0:04:55.52,0:04:57.52,EN,,0,0,0,,So that's the problem you should be thinking about.
Dialogue: 0,0:04:58.70,0:05:00.77,EN,,0,0,0,,Like it's sort of just your work.
Dialogue: 0,0:05:00.77,0:05:03.77,EN,,0,0,0,,You want to be able to include new things by making minimal changes.
Dialogue: 0,0:05:05.98,0:05:08.12,EN,,0,0,0,,OK, well that's the problem that we'll be talking about today.
Dialogue: 0,0:05:09.44,0:05:14.22,EN,,0,0,0,,And you should have this sort of distributed personnel record system in your mind.
Dialogue: 0,0:05:14.24,0:05:16.62,EN,,0,0,0,,But actually the one I'll be talking about is a problem
Dialogue: 0,0:05:16.62,0:05:18.48,EN,,0,0,0,,that's a little bit more self-contained than that.
Dialogue: 0,0:05:19.29,0:05:21.76,EN,,0,0,0,,that'll bring up the issues, I think, more clearly.
Dialogue: 0,0:05:21.87,0:05:26.01,EN,,0,0,0,,That's the problem of doing a system that does arithmetic on complex numbers.
Dialogue: 0,0:05:27.77,0:05:28.92,EN,,0,0,0,,So let's take a look here.
Dialogue: 0,0:05:30.69,0:05:31.74,EN,,0,0,0,,Just as a little review,
Dialogue: 0,0:05:32.04,0:05:33.53,EN,,0,0,0,,there are things called complex numbers.
Dialogue: 0,0:05:35.25,0:05:38.22,EN,,0,0,0,,Complex number you can think of as a point in the plane, or z.
Dialogue: 0,0:05:39.37,0:05:47.19,EN,,0,0,0,,And you can represent a point either by its real-part and its imaginary-part.
Dialogue: 0,0:05:47.19,0:05:50.83,EN,,0,0,0,,So if this is z and its real-part is this much,
Dialogue: 0,0:05:51.50,0:05:53.24,EN,,0,0,0,,and its imaginary-part is that much,
Dialogue: 0,0:05:54.33,0:05:56.44,EN,,0,0,0,,and you write z equals x plus iy.
Dialogue: 0,0:05:59.11,0:06:03.21,EN,,0,0,0,,Or another way to represent a complex number is by saying,
Dialogue: 0,0:06:03.21,0:06:09.00,EN,,0,0,0,,what's the distance from the origin, and what's the angle?
Dialogue: 0,0:06:11.32,0:06:16.67,EN,,0,0,0,,So that represents a complex number as its radius times an angle.
Dialogue: 0,0:06:19.52,0:06:21.92,EN,,0,0,0,,This one's called -- the original one's called rectangular form,
Dialogue: 0,0:06:22.59,0:06:25.45,EN,,0,0,0,,rectangular representation, real- and imaginary-part
Dialogue: 0,0:06:26.20,0:06:30.04,EN,,0,0,0,,or polar representation magnitude and angle--
Dialogue: 0,0:06:30.04,0:06:31.48,EN,,0,0,0,,and if you know the real- and imaginary-part,
Dialogue: 0,0:06:31.53,0:06:33.36,EN,,0,0,0,,you can figure out the magnitude and angle.
Dialogue: 0,0:06:33.72,0:06:36.97,EN,,0,0,0,,If you know x and y, you can get r by this formula.
Dialogue: 0,0:06:37.19,0:06:39.48,EN,,0,0,0,,Square root of sum of the squares, and you can get the
Dialogue: 0,0:06:39.48,0:06:40.76,EN,,0,0,0,,angle as an arctangent.
Dialogue: 0,0:06:41.42,0:06:44.42,EN,,0,0,0,,Or conversely, if you knew r and A you could
Dialogue: 0,0:06:44.42,0:06:45.31,EN,,0,0,0,,figure out x and y.
Dialogue: 0,0:06:45.80,0:06:49.43,EN,,0,0,0,,x is r times the cosine of A, and y is r times the sine of A.
Dialogue: 0,0:06:51.34,0:06:53.66,EN,,0,0,0,,All right, so there's these two. They're complex numbers.
Dialogue: 0,0:06:54.13,0:06:57.15,EN,,0,0,0,,You can think of them either in polar form or rectangular form.
Dialogue: 0,0:06:57.15,0:06:58.12,EN,,0,0,0,,What we would like to do
Dialogue: 0,0:06:58.32,0:07:01.32,EN,,0,0,0,,is make a system that does arithmetic on complex numbers.
Dialogue: 0,0:07:03.95,0:07:05.12,EN,,0,0,0,,In other words, what we'd like--
Dialogue: 0,0:07:05.58,0:07:06.99,EN,,0,0,0,,just like the rational number example--
Dialogue: 0,0:07:07.38,0:07:10.20,EN,,0,0,0,,is to have some operations plus c,
Dialogue: 0,0:07:10.73,0:07:13.90,EN,,0,0,0,,which is going to take two complex numbers and add them, subtract them,
Dialogue: 0,0:07:14.35,0:07:16.94,EN,,0,0,0,,and multiply them, and divide them.
Dialogue: 0,0:07:20.73,0:07:25.28,EN,,0,0,0,,OK, well there's little bit of mathematics behind it.
Dialogue: 0,0:07:25.28,0:07:28.36,EN,,0,0,0,,What are the actual formulas for manipulating such things?
Dialogue: 0,0:07:30.41,0:07:31.92,EN,,0,0,0,,And it's sort of not important where they come from,
Dialogue: 0,0:07:34.00,0:07:35.79,EN,,0,0,0,,but just as an implementer let's see--
Dialogue: 0,0:07:35.80,0:07:37.95,EN,,0,0,0,,if you want to add two complex numbers it's pretty easy to
Dialogue: 0,0:07:39.13,0:07:42.66,EN,,0,0,0,,it's pretty easy to get its real-part and its imaginary-part.
Dialogue: 0,0:07:42.66,0:07:45.93,EN,,0,0,0,,The real-part of the sum of two complex numbers
Dialogue: 0,0:07:47.72,0:07:49.72,EN,,0,0,0,,real-part of the z1 plus z2
Dialogue: 0,0:07:50.06,0:07:54.64,EN,,0,0,0,,is the real-part of z1 plus the real-part of z2.
Dialogue: 0,0:07:57.82,0:08:01.60,EN,,0,0,0,,And the imaginary-part of z1 plus z2
Dialogue: 0,0:08:01.74,0:08:05.66,EN,,0,0,0,,is the imaginary part of z1 plus the imaginary part of z2.
Dialogue: 0,0:08:07.41,0:08:09.48,EN,,0,0,0,,So it's pretty easy to add complex numbers.
Dialogue: 0,0:08:09.48,0:08:10.99,EN,,0,0,0,,You just add the corresponding parts
Dialogue: 0,0:08:11.31,0:08:13.18,EN,,0,0,0,,and make a new complex number with those parts.
Dialogue: 0,0:08:13.37,0:08:14.73,EN,,0,0,0,,If you want to multiply them,
Dialogue: 0,0:08:15.53,0:08:17.82,EN,,0,0,0,,it's kind of nice to do it in polar form.
Dialogue: 0,0:08:17.82,0:08:20.38,EN,,0,0,0,,Because if you have two complex numbers,
Dialogue: 0,0:08:20.40,0:08:26.54,EN,,0,0,0,,the magnitude of their product is here, the product of the magnitudes.
Dialogue: 0,0:08:28.85,0:08:33.88,EN,,0,0,0,,And the angle of the product is the sum of the angles.
Dialogue: 0,0:08:35.80,0:08:40.54,EN,,0,0,0,,So that's sort of mathematics that allows you to do arithmetic on complex numbers.
Dialogue: 0,0:08:40.54,0:08:42.38,EN,,0,0,0,,Let's actually think about the implementation.
Dialogue: 0,0:08:43.72,0:08:47.39,EN,,0,0,0,,Well we do it just like rational numbers.
Dialogue: 0,0:08:49.84,0:08:53.47,EN,,0,0,0,,We come down, we assume we have some constructors and selectors.
Dialogue: 0,0:08:53.76,0:08:54.52,EN,,0,0,0,,What would we like?
Dialogue: 0,0:08:55.33,0:08:58.16,EN,,0,0,0,,Well let's assume that we make a data object cloud,
Dialogue: 0,0:08:58.54,0:09:00.78,EN,,0,0,0,,which is a complex number that has some stuff in it,
Dialogue: 0,0:09:01.79,0:09:04.67,EN,,0,0,0,,and that we can get out from a complex number the real-part,
Dialogue: 0,0:09:05.52,0:09:09.64,EN,,0,0,0,,or the imaginary-part, or the magnitude, or the angle.
Dialogue: 0,0:09:12.15,0:09:14.01,EN,,0,0,0,,We want some ways of making complex numbers--
Dialogue: 0,0:09:14.03,0:09:15.64,EN,,0,0,0,,not only selectors, but constructors.
Dialogue: 0,0:09:16.80,0:09:19.52,EN,,0,0,0,,So we'll assume we have a thing called make-rectangular.
Dialogue: 0,0:09:19.53,0:09:24.27,EN,,0,0,0,,What make-rectangular is going to do is take a real-part and
Dialogue: 0,0:09:24.51,0:09:29.36,EN,,0,0,0,,an imaginary-part and construct a complex number with those parts.
Dialogue: 0,0:09:31.92,0:09:35.01,EN,,0,0,0,,Similarly, we can have make-polar which will taking
Dialogue: 0,0:09:35.01,0:09:37.85,EN,,0,0,0,,a magnitude and an angle,
Dialogue: 0,0:09:40.83,0:09:43.90,EN,,0,0,0,,and construct a complex number which has that magnitude and angle.
Dialogue: 0,0:09:44.68,0:09:45.46,EN,,0,0,0,,So here's a system.
Dialogue: 0,0:09:45.46,0:09:47.77,EN,,0,0,0,,We'll have two constructors and four selectors.
Dialogue: 0,0:09:48.91,0:09:55.15,EN,,0,0,0,,And now, just like before, in terms of that abstract data
Dialogue: 0,0:09:55.15,0:09:59.22,EN,,0,0,0,,we'll go ahead and implement our complex number operations.
Dialogue: 0,0:09:59.22,0:10:02.30,EN,,0,0,0,,And here you can see translated into Lisp code
Dialogue: 0,0:10:03.23,0:10:07.47,EN,,0,0,0,,just the arithmetic formulas I put down before.
Dialogue: 0,0:10:08.06,0:10:09.98,EN,,0,0,0,,If I want to add two complex numbers
Dialogue: 0,0:10:11.76,0:10:15.56,EN,,0,0,0,,I will make a complex number out of its real- and imaginary-parts.
Dialogue: 0,0:10:16.72,0:10:19.02,EN,,0,0,0,,The real part of the complex number I'm going to make
Dialogue: 0,0:10:19.40,0:10:21.80,EN,,0,0,0,,is the sum of the real-parts.
Dialogue: 0,0:10:23.31,0:10:25.37,EN,,0,0,0,,The imaginary part of the complex number I'm going to make
Dialogue: 0,0:10:25.40,0:10:27.52,EN,,0,0,0,,is the sum of the imaginary-parts.
Dialogue: 0,0:10:30.31,0:10:32.09,EN,,0,0,0,,I put those together, make a complex number.
Dialogue: 0,0:10:32.16,0:10:34.44,EN,,0,0,0,,That's how I implement complex number addition.
Dialogue: 0,0:10:35.78,0:10:38.49,EN,,0,0,0,,Subtraction is essentially the same.
Dialogue: 0,0:10:39.65,0:10:42.97,EN,,0,0,0,,All I do is subtract the parts rather than add them.
Dialogue: 0,0:10:45.14,0:10:47.07,EN,,0,0,0,,To multiply two complex numbers,
Dialogue: 0,0:10:47.74,0:10:49.02,EN,,0,0,0,,I use the other formula.
Dialogue: 0,0:10:49.27,0:10:53.84,EN,,0,0,0,,I'll make a complex number out of a magnitude and angle.
Dialogue: 0,0:10:55.35,0:10:56.44,EN,,0,0,0,,The magnitude
Dialogue: 0,0:10:56.65,0:11:00.97,EN,,0,0,0,,is going to be the product of the magnitudesof the two complex numbers I'm multiplying.
Dialogue: 0,0:11:03.71,0:11:05.93,EN,,0,0,0,,And the angle is going to be the sum
Dialogue: 0,0:11:06.16,0:11:08.51,EN,,0,0,0,,of the angles of the z1two complex numbers I'm multiplying.
Dialogue: 0,0:11:09.62,0:11:10.96,EN,,0,0,0,,So there's multiplication.
Dialogue: 0,0:11:11.23,0:11:12.25,EN,,0,0,0,,And then division,
Dialogue: 0,0:11:14.27,0:11:15.90,EN,,0,0,0,,division is almost the same.
Dialogue: 0,0:11:17.37,0:11:19.58,EN,,0,0,0,,Here I divide the magnitudes and subtract the angles.
Dialogue: 0,0:11:28.36,0:11:30.46,EN,,0,0,0,,Now I've implemented the operations.
Dialogue: 0,0:11:31.87,0:11:33.64,EN,,0,0,0,,And what do we do?
Dialogue: 0,0:11:33.64,0:11:34.52,EN,,0,0,0,,We call on George.
Dialogue: 0,0:11:36.06,0:11:38.79,EN,,0,0,0,,We've done the use, let's worry about the representation.
Dialogue: 0,0:11:38.80,0:11:40.94,EN,,0,0,0,,We'll call on George and say to George,
Dialogue: 0,0:11:40.97,0:11:43.61,EN,,0,0,0,,go ahead and build us a complex number representation.
Dialogue: 0,0:11:45.25,0:11:47.44,EN,,0,0,0,,Well that's fine...ahhh
Dialogue: 0,0:11:47.77,0:11:52.66,EN,,0,0,0,,George can say, we'll implement a complex number
Dialogue: 0,0:11:52.66,0:11:57.15,EN,,0,0,0,,simply as a pair that has the real-part and the imaginary-part.
Dialogue: 0,0:11:57.20,0:12:02.62,EN,,0,0,0,,So if I want to make a complex number with a certain real-part and an imaginary-part,
Dialogue: 0,0:12:03.36,0:12:05.55,EN,,0,0,0,,I'll just use cons to form a pair, and that will--
Dialogue: 0,0:12:06.03,0:12:08.11,EN,,0,0,0,,that's George's representation of a complex number.
Dialogue: 0,0:12:09.78,0:12:12.42,EN,,0,0,0,,So if I want to get out the real-part of something, I just
Dialogue: 0,0:12:12.42,0:12:14.12,EN,,0,0,0,,extract the car, the first part.
Dialogue: 0,0:12:14.35,0:12:16.67,EN,,0,0,0,,If I want to get the imaginary-part, I extract the cdr
Dialogue: 0,0:12:19.64,0:12:21.77,EN,,0,0,0,,How do I deal with the magnitude and angle?
Dialogue: 0,0:12:22.22,0:12:25.75,EN,,0,0,0,,Well if I want to extract the magnitude of one of these things
Dialogue: 0,0:12:25.75,0:12:32.30,EN,,0,0,0,,I get the square root of the sum of the square of the car plus the square of the cdr.
Dialogue: 0,0:12:33.79,0:12:39.26,EN,,0,0,0,,If I want to get the angle, I compute the arctangent of the cdr in the car.
Dialogue: 0,0:12:39.53,0:12:42.86,EN,,0,0,0,,This is a lisp procedure for computing arctangent.
Dialogue: 0,0:12:44.97,0:12:48.59,EN,,0,0,0,,And if somebody hands me a magnitude and an angle
Dialogue: 0,0:12:48.94,0:12:50.56,EN,,0,0,0,,and says, make me a complex number,well I compute the
Dialogue: 0,0:12:50.89,0:12:56.24,EN,,0,0,0,,well I compute the real-part and the imaginary-part, r * cosine of a and r * sine of a,
Dialogue: 0,0:12:57.77,0:12:59.05,EN,,0,0,0,,and stick them together into a pair.
Dialogue: 0,0:13:01.46,0:13:02.26,EN,,0,0,0,,OK so we're done.
Dialogue: 0,0:13:02.26,0:13:04.75,EN,,0,0,0,,In fact, what I just did, conceptually,
Dialogue: 0,0:13:06.89,0:13:09.37,EN,,0,0,0,,is absolutely no different from the rational number
Dialogue: 0,0:13:10.60,0:13:12.44,EN,,0,0,0,,representation that we looked at last time.
Dialogue: 0,0:13:12.75,0:13:13.91,EN,,0,0,0,,It's the same sort of idea.
Dialogue: 0,0:13:13.91,0:13:16.28,EN,,0,0,0,,You implement the operators, you pick a representation.
Dialogue: 0,0:13:18.07,0:13:18.65,EN,,0,0,0,,Nothing different.
Dialogue: 0,0:13:20.07,0:13:21.56,EN,,0,0,0,,Now let's worry about Martha.
Dialogue: 0,0:13:23.21,0:13:24.52,EN,,0,0,0,,See, Martha has a different idea.
Dialogue: 0,0:13:26.67,0:13:28.57,EN,,0,0,0,,She doesn't want to represent a complex number
Dialogue: 0,0:13:28.59,0:13:30.90,EN,,0,0,0,,as a pair of a real-part and an imaginary-part.
Dialogue: 0,0:13:30.90,0:13:34.17,EN,,0,0,0,,What she would like to do is represent a complex number as
Dialogue: 0,0:13:34.17,0:13:37.69,EN,,0,0,0,,a pair of a magnitude and an angle.
Dialogue: 0,0:13:39.55,0:13:42.13,EN,,0,0,0,,So if instead of calling up George we ask Martha to design
Dialogue: 0,0:13:42.13,0:13:43.74,EN,,0,0,0,,our representation, we get something like this.
Dialogue: 0,0:13:44.57,0:13:47.16,EN,,0,0,0,,We get make-polar.
Dialogue: 0,0:13:47.16,0:13:50.22,EN,,0,0,0,,Sure, if I give you a magnitude and an angle we're
Dialogue: 0,0:13:50.22,0:13:53.07,EN,,0,0,0,,just going to form a pair that has magnitude and angle.
Dialogue: 0,0:13:55.43,0:13:57.68,EN,,0,0,0,,If you want to extract the magnitude, that's easy.
Dialogue: 0,0:13:58.24,0:13:59.37,EN,,0,0,0,,You just pull out the car or the pair.
Dialogue: 0,0:13:59.78,0:14:02.67,EN,,0,0,0,,If you want to extract the angle, sure, that's easy.
Dialogue: 0,0:14:02.67,0:14:03.63,EN,,0,0,0,,You just pull out the cdr.
Dialogue: 0,0:14:04.81,0:14:07.02,EN,,0,0,0,,If you want to look for real-parts and imaginary-parts,
Dialogue: 0,0:14:07.42,0:14:08.49,EN,,0,0,0,,well then you have to do some work.
Dialogue: 0,0:14:08.88,0:14:14.58,EN,,0,0,0,,If you want the real-part, you have to get r cosine a.
Dialogue: 0,0:14:14.58,0:14:19.99,EN,,0,0,0,,In other words, r, the car of the pair, times the cosine of
Dialogue: 0,0:14:19.99,0:14:20.95,EN,,0,0,0,,the cdr of the pair.
Dialogue: 0,0:14:20.95,0:14:26.23,EN,,0,0,0,,So this is r times the cosine of a,
Dialogue: 0,0:14:26.54,0:14:27.48,EN,,0,0,0,,and that's the real-part.
Dialogue: 0,0:14:28.33,0:14:31.40,EN,,0,0,0,,If you want to get the imaginary-part, it's r times the sine of a.
Dialogue: 0,0:14:32.66,0:14:37.93,EN,,0,0,0,,And if I hand you a real-part and an imaginary-part and say,
Dialogue: 0,0:14:37.93,0:14:42.03,EN,,0,0,0,,make me a complex number with that real-part and
Dialogue: 0,0:14:42.03,0:14:44.17,EN,,0,0,0,,imaginary-part, well I figure out what the magnitude and
Dialogue: 0,0:14:44.17,0:14:45.54,EN,,0,0,0,,angle should be.
Dialogue: 0,0:14:45.54,0:14:47.85,EN,,0,0,0,,The magnitude's the square root of the sum of the squares
Dialogue: 0,0:14:48.09,0:14:49.23,EN,,0,0,0,,and the angle's the arctangent.
Dialogue: 0,0:14:49.23,0:14:50.22,EN,,0,0,0,,I put those together to make a pair.
Dialogue: 0,0:14:52.09,0:14:54.17,EN,,0,0,0,,So there's Martha's idea.
Dialogue: 0,0:14:56.69,0:14:57.37,EN,,0,0,0,,Well which is better?
Dialogue: 0,0:14:59.68,0:15:03.15,EN,,0,0,0,,Well if you're doing a lot of additions, probably George's is better
Dialogue: 0,0:15:03.16,0:15:05.61,EN,,0,0,0,,is better, because you're doing a lot of real-parts and imaginary-parts.
Dialogue: 0,0:15:05.85,0:15:08.40,EN,,0,0,0,,If mostly you're going to be doing multiplications and divisions,
Dialogue: 0,0:15:09.48,0:15:11.14,EN,,0,0,0,,then maybe Martha's idea is better.
Dialogue: 0,0:15:11.14,0:15:14.84,EN,,0,0,0,,Or maybe, and this is the real point, you can't decide.
Dialogue: 0,0:15:16.59,0:15:22.32,EN,,0,0,0,,Or maybe you just have to let them both hang around, for personality reasons.
Dialogue: 0,0:15:23.48,0:15:26.76,EN,,0,0,0,,Maybe you just really can't ever decide what you would like.
Dialogue: 0,0:15:28.56,0:15:32.32,EN,,0,0,0,,And again, what we would really like is a system that looks like this.
Dialogue: 0,0:15:32.65,0:15:36.17,EN,,0,0,0,,That somehow there's George over here, who has built
Dialogue: 0,0:15:36.83,0:15:39.64,EN,,0,0,0,,rectangular complex numbers.
Dialogue: 0,0:15:41.47,0:15:44.25,EN,,0,0,0,,And Martha, who has polar complex numbers.
Dialogue: 0,0:15:46.12,0:15:49.69,EN,,0,0,0,,And somehow we have operations
Dialogue: 0,0:15:50.28,0:15:56.89,EN,,0,0,0,,that can add, and subtract, and multiply, and divide
Dialogue: 0,0:15:57.56,0:15:58.76,EN,,0,0,0,,and it shouldn't matter
Dialogue: 0,0:15:59.34,0:16:02.79,EN,,0,0,0,,that there are two incompatible representations of complex
Dialogue: 0,0:16:02.79,0:16:03.98,EN,,0,0,0,,numbers floating around this system.
Dialogue: 0,0:16:04.41,0:16:08.33,EN,,0,0,0,,In other words, not only like an abstraction barrier here
Dialogue: 0,0:16:09.64,0:16:11.84,EN,,0,0,0,,that has things in it like a real-part,
Dialogue: 0,0:16:15.77,0:16:21.71,EN,,0,0,0,,and an imaginary-part, and magnitude,and angle.
Dialogue: 0,0:16:23.83,0:16:25.36,EN,,0,0,0,,So not only is there an abstraction barrier
Dialogue: 0,0:16:25.39,0:16:28.38,EN,,0,0,0,,that hides the actual representation from us,
Dialogue: 0,0:16:29.10,0:16:31.52,EN,,0,0,0,,but also there's some kind of vertical barrier here
Dialogue: 0,0:16:32.19,0:16:35.02,EN,,0,0,0,,that allows both of these representations to exist
Dialogue: 0,0:16:35.87,0:16:37.40,EN,,0,0,0,,without interfering with each other.
Dialogue: 0,0:16:38.57,0:16:41.07,EN,,0,0,0,,The idea is that the things in here--
Dialogue: 0,0:16:41.90,0:16:44.12,EN,,0,0,0,,real-part, imaginary-part,magnitude, and angle--
Dialogue: 0,0:16:44.12,0:16:46.49,EN,,0,0,0,,will be generic operators.
Dialogue: 0,0:16:47.31,0:16:49.45,EN,,0,0,0,,If you ask for the real-part, it will worry about
Dialogue: 0,0:16:49.98,0:16:51.31,EN,,0,0,0,,what representation it's looking at.
Dialogue: 0,0:16:53.88,0:16:55.10,EN,,0,0,0,,OK, well how can we do that?
Dialogue: 0,0:16:56.84,0:16:59.23,EN,,0,0,0,,There's actually a really obvious idea,
Dialogue: 0,0:16:59.84,0:17:01.68,EN,,0,0,0,,if you're used to thinking about complex numbers.
Dialogue: 0,0:17:02.52,0:17:04.44,EN,,0,0,0,,If you're used to thinking about compound data.
Dialogue: 0,0:17:06.33,0:17:10.99,EN,,0,0,0,,See, suppose you could just tell by looking at a complex number
Dialogue: 0,0:17:12.17,0:17:13.95,EN,,0,0,0,,whether it was constructed by George or Martha.
Dialogue: 0,0:17:15.79,0:17:18.90,EN,,0,0,0,,In other words, so it's not that what's floating around
Dialogue: 0,0:17:18.90,0:17:20.91,EN,,0,0,0,,here are ordinary, just complex numbers, right?
Dialogue: 0,0:17:20.91,0:17:22.94,EN,,0,0,0,,They're fancy, designer complex numbers.
Dialogue: 0,0:17:24.39,0:17:28.04,EN,,0,0,0,,So you look at a complex numbers as it's not just a complex number
Dialogue: 0,0:17:28.04,0:17:29.16,EN,,0,0,0,,it's got a label on it that says,
Dialogue: 0,0:17:29.19,0:17:30.75,EN,,0,0,0,,that one is by Martha.
Dialogue: 0,0:17:31.45,0:17:34.22,EN,,0,0,0,,Or this is a complex number by George.
Dialogue: 0,0:17:34.48,0:17:35.39,EN,,0,0,0,,Right? They're signed.
Dialogue: 0,0:17:36.86,0:17:40.15,EN,,0,0,0,,See, and then whenever we looked at a complex number we
Dialogue: 0,0:17:40.15,0:17:45.48,EN,,0,0,0,,could just read the label, and then we'd know how you expect
Dialogue: 0,0:17:45.80,0:17:46.72,EN,,0,0,0,,to operate on that.
Dialogue: 0,0:17:48.03,0:17:51.19,EN,,0,0,0,,In other words, what we want is not just ordinary data objects.
Dialogue: 0,0:17:51.19,0:17:54.37,EN,,0,0,0,,We want to introduce the notion of what's called typed data.
Dialogue: 0,0:17:59.76,0:18:02.81,EN,,0,0,0,,Typed data means, again, there's some sort of cloud.
Dialogue: 0,0:18:03.94,0:18:08.93,EN,,0,0,0,,And what it's got in it is an ordinary data object like
Dialogue: 0,0:18:08.93,0:18:09.90,EN,,0,0,0,,we've been thinking about.
Dialogue: 0,0:18:13.18,0:18:16.54,EN,,0,0,0,,Pulled out the contents, sort of the actual data.
Dialogue: 0,0:18:19.32,0:18:21.56,EN,,0,0,0,,But also a thing called a type,
Dialogue: 0,0:18:22.56,0:18:25.24,EN,,0,0,0,,but it's signed by either George or Martha.
Dialogue: 0,0:18:25.99,0:18:28.27,EN,,0,0,0,,So we're going to go from regular data to type data.
Dialogue: 0,0:18:31.95,0:18:32.71,EN,,0,0,0,,How do we build that?
Dialogue: 0,0:18:32.71,0:18:33.50,EN,,0,0,0,,Well that's easy.
Dialogue: 0,0:18:33.84,0:18:35.32,EN,,0,0,0,,We know how to build clouds.
Dialogue: 0,0:18:35.80,0:18:36.88,EN,,0,0,0,,We can build them out of pairs.
Dialogue: 0,0:18:37.92,0:18:41.82,EN,,0,0,0,,So here's a little representation that supports typed data.
Dialogue: 0,0:18:43.51,0:18:49.64,EN,,0,0,0,,There's a thing called take a type and attach it to a piece of contents,
Dialogue: 0,0:18:49.69,0:18:50.64,EN,,0,0,0,,and we just use cons.
Dialogue: 0,0:18:51.64,0:18:54.11,EN,,0,0,0,,And if we have a piece of typed data, we can look at the type
Dialogue: 0,0:18:55.21,0:18:56.00,EN,,0,0,0,,which is the car.
Dialogue: 0,0:18:56.29,0:18:58.30,EN,,0,0,0,,We can look at the contents,which is the cdr.
Dialogue: 0,0:18:59.96,0:19:04.28,EN,,0,0,0,,Now along with that, the way we use our type data will test,
Dialogue: 0,0:19:05.29,0:19:07.26,EN,,0,0,0,,when we're given a piece of data, what type it is.
Dialogue: 0,0:19:07.52,0:19:09.26,EN,,0,0,0,,So we have some type predicates with us.
Dialogue: 0,0:19:10.51,0:19:13.73,EN,,0,0,0,,For example, to see whether a complex number is one of
Dialogue: 0,0:19:13.73,0:19:16.86,EN,,0,0,0,,George's, whether it's rectangular, we just check to
Dialogue: 0,0:19:16.86,0:19:21.85,EN,,0,0,0,,see if the type of that is the symbol rectangular,
Dialogue: 0,0:19:23.68,0:19:25.05,EN,,0,0,0,,right? The symbol rectangular.
Dialogue: 0,0:19:27.20,0:19:30.33,EN,,0,0,0,,And to check whether a complex number is one of Martha's,
Dialogue: 0,0:19:30.33,0:19:33.42,EN,,0,0,0,,we check to see whether the type is the symbol polar.
Dialogue: 0,0:19:36.46,0:19:39.21,EN,,0,0,0,,So that's a way to test what kind of number we're looking at.
Dialogue: 0,0:19:40.75,0:19:42.81,EN,,0,0,0,,Now let's think about how we can use that to build the system.
Dialogue: 0,0:19:43.87,0:19:46.73,EN,,0,0,0,,So let's suppose that George and Martha were off working separately,
Dialogue: 0,0:19:47.36,0:19:52.64,EN,,0,0,0,,and each of them had designed their complex number representation packages.
Dialogue: 0,0:19:52.64,0:19:58.52,EN,,0,0,0,,What do they have to do to become part of the system,
Dialogue: 0,0:19:58.73,0:20:00.14,EN,,0,0,0,,to exist compatibly?
Dialogue: 0,0:20:00.14,0:20:02.11,EN,,0,0,0,,Well it's really pretty easy.
Dialogue: 0,0:20:02.72,0:20:04.51,EN,,0,0,0,,Remember, George had this package.
Dialogue: 0,0:20:05.97,0:20:08.48,EN,,0,0,0,,Here's George's original package, or half of it.
Dialogue: 0,0:20:08.98,0:20:11.15,EN,,0,0,0,,And underlined in red are the changes he has to make.
Dialogue: 0,0:20:12.09,0:20:16.43,EN,,0,0,0,,So before, when George made a complex number out of an x and y
Dialogue: 0,0:20:17.52,0:20:19.85,EN,,0,0,0,,he just put them together to make a pair.
Dialogue: 0,0:20:20.93,0:20:23.39,EN,,0,0,0,,And the only difference is that now he signs them.
Dialogue: 0,0:20:24.09,0:20:28.08,EN,,0,0,0,,He attaches the type, which is the symbol rectangular to that pair.
Dialogue: 0,0:20:30.60,0:20:33.26,EN,,0,0,0,,Everything else George does is the same, except that--
Dialogue: 0,0:20:33.92,0:20:38.06,EN,,0,0,0,,see, George and Martha both have procedures named real-part and imaginary-part.
Dialogue: 0,0:20:38.70,0:20:42.96,EN,,0,0,0,,So to allow them both to exist in the same Lisp environment,
Dialogue: 0,0:20:44.22,0:20:45.92,EN,,0,0,0,,George had changed the names of his procedures.
Dialogue: 0,0:20:45.92,0:20:49.14,EN,,0,0,0,,So we'll say, this is George's real-part procedure.
Dialogue: 0,0:20:49.14,0:20:51.16,EN,,0,0,0,,It's the real-part-rectangular procedure,
Dialogue: 0,0:20:51.48,0:20:54.06,EN,,0,0,0,,the imaginary-part-rectangular procedure.
Dialogue: 0,0:20:55.42,0:20:57.24,EN,,0,0,0,,And then here's the rest of George's package.
Dialogue: 0,0:20:59.13,0:21:02.06,EN,,0,0,0,,He'd had magnitude and angle, just renames them magnitude
Dialogue: 0,0:21:02.06,0:21:04.16,EN,,0,0,0,,rectangular and angle rectangular.
Dialogue: 0,0:21:06.08,0:21:07.96,EN,,0,0,0,,And Martha has to do basically the same thing.
Dialogue: 0,0:21:09.86,0:21:16.22,EN,,0,0,0,,Martha previously, when she made a complex number out of a magnitude and angle,
Dialogue: 0,0:21:18.14,0:21:19.27,EN,,0,0,0,,she just cons them.
Dialogue: 0,0:21:19.27,0:21:20.86,EN,,0,0,0,,Now she attaches the type polar,
Dialogue: 0,0:21:23.95,0:21:25.61,EN,,0,0,0,,and she changes the name
Dialogue: 0,0:21:25.66,0:21:29.85,EN,,0,0,0,,so her real-part procedure won't conflict in name with George's.
Dialogue: 0,0:21:30.71,0:21:32.99,EN,,0,0,0,,It's a real-part-polar,imaginary-part-polar,
Dialogue: 0,0:21:34.54,0:21:38.06,EN,,0,0,0,,magnitude polar, and angle polar.
Dialogue: 0,0:21:45.00,0:21:46.13,EN,,0,0,0,,Now we have the system.
Dialogue: 0,0:21:46.13,0:21:47.92,EN,,0,0,0,,Right there's George and Martha.
Dialogue: 0,0:21:49.16,0:21:51.68,EN,,0,0,0,,And now we've got to get some kind of manager to look at these types.
Dialogue: 0,0:21:52.83,0:21:56.48,EN,,0,0,0,,How are these things actually going to work now
Dialogue: 0,0:21:57.05,0:21:59.40,EN,,0,0,0,,that George and Martha have supplied us with typed data?
Dialogue: 0,0:22:00.53,0:22:04.30,EN,,0,0,0,,Well what we have are a bunch of generic selectors.
Dialogue: 0,0:22:05.26,0:22:10.63,EN,,0,0,0,,Generic selectors for complex numbers real-part,imaginary-part, magnitude, and angle.
Dialogue: 0,0:22:14.14,0:22:15.40,EN,,0,0,0,,Let's look at them more closely.
Dialogue: 0,0:22:17.93,0:22:19.00,EN,,0,0,0,,What does a real-part do?
Dialogue: 0,0:22:19.31,0:22:22.76,EN,,0,0,0,,If I ask for the real part of a complex number,
Dialogue: 0,0:22:24.07,0:22:24.91,EN,,0,0,0,,well I look at it.
Dialogue: 0,0:22:25.80,0:22:26.69,EN,,0,0,0,,I look at its type.
Dialogue: 0,0:22:26.69,0:22:28.12,EN,,0,0,0,,I say, is it rectangular?
Dialogue: 0,0:22:31.02,0:22:35.36,EN,,0,0,0,,If so, I apply George's real part procedure
Dialogue: 0,0:22:36.06,0:22:37.92,EN,,0,0,0,,to the contents of that complex number.
Dialogue: 0,0:22:41.07,0:22:42.94,EN,,0,0,0,,This is a number that has a type on it.
Dialogue: 0,0:22:43.72,0:22:47.66,EN,,0,0,0,,I strip off the type using contents and apply George's procedure.
Dialogue: 0,0:22:50.70,0:22:52.86,EN,,0,0,0,,Or is this a polar complex number?
Dialogue: 0,0:22:53.95,0:22:54.97,EN,,0,0,0,,If I want the real part,
Dialogue: 0,0:22:55.45,0:22:58.78,EN,,0,0,0,,I apply Martha's real-part procedure to the contents of that number.
Dialogue: 0,0:22:59.85,0:23:01.15,EN,,0,0,0,,So that's how real part works.
Dialogue: 0,0:23:02.26,0:23:05.66,EN,,0,0,0,,And then similarly there's imaginary-part, which is almost the same.
Dialogue: 0,0:23:06.51,0:23:09.60,EN,,0,0,0,,Right? It looks at the number and if it's rectangular, uses
Dialogue: 0,0:23:09.60,0:23:11.13,EN,,0,0,0,,George's imaginary-part procedure.
Dialogue: 0,0:23:11.13,0:23:12.83,EN,,0,0,0,,If it's polar, uses Martha's.
Dialogue: 0,0:23:13.38,0:23:17.40,EN,,0,0,0,,And then there's a magnitude and an angle.
Dialogue: 0,0:23:19.71,0:23:21.02,EN,,0,0,0,,So there's a system.
Dialogue: 0,0:23:23.00,0:23:24.26,EN,,0,0,0,,Has three parts.
Dialogue: 0,0:23:24.26,0:23:26.59,EN,,0,0,0,,There's sort of George, and Martha, and the manager.
Dialogue: 0,0:23:26.76,0:23:28.97,EN,,0,0,0,,And that's how you get generic operators implemented.
Dialogue: 0,0:23:28.97,0:23:32.92,EN,,0,0,0,,Let's look at just a simple example, just to pin it down.
Dialogue: 0,0:23:33.50,0:23:35.12,EN,,0,0,0,,But exactly how this is going to work,
Dialogue: 0,0:23:36.54,0:23:43.98,EN,,0,0,0,,suppose you're going to be looking at the complex number who's real-part is one,
Dialogue: 0,0:23:44.52,0:23:46.09,EN,,0,0,0,,and who's imaginary-part is two.
Dialogue: 0,0:23:46.09,0:23:48.44,EN,,0,0,0,,So that would be one plus 2i.
Dialogue: 0,0:23:50.31,0:23:52.64,EN,,0,0,0,,What would happen is up here,
Dialogue: 0,0:23:55.28,0:23:57.53,EN,,0,0,0,,up here above where the operations have to happen,
Dialogue: 0,0:23:57.63,0:24:08.27,EN,,0,0,0,,that number would be represented as a pair of 1 and 2 together with type data.
Dialogue: 0,0:24:10.48,0:24:11.39,EN,,0,0,0,,That would be the contents.
Dialogue: 0,0:24:11.87,0:24:17.96,EN,,0,0,0,,And the whole data would be that thing with the symbol rectangular added onto that.
Dialogue: 0,0:24:18.14,0:24:21.53,EN,,0,0,0,,And that's the way that complex number would exist in the system.
Dialogue: 0,0:24:22.33,0:24:24.92,EN,,0,0,0,,When you went to take the real-part,
Dialogue: 0,0:24:25.84,0:24:28.89,EN,,0,0,0,,the manager will look at this and say, oh it's one of George's.
Dialogue: 0,0:24:30.27,0:24:31.53,EN,,0,0,0,,He'll strip off the type
Dialogue: 0,0:24:33.34,0:24:36.91,EN,,0,0,0,,and hand down to George the pair 1, 2.
Dialogue: 0,0:24:38.00,0:24:42.27,EN,,0,0,0,,And that's the kind of data that George developed his system to use.
Dialogue: 0,0:24:44.36,0:24:45.92,EN,,0,0,0,,So it gets stripped down.
Dialogue: 0,0:24:46.52,0:24:49.76,EN,,0,0,0,,Later on, if you ask George to construct a complex number,
Dialogue: 0,0:24:51.24,0:24:54.56,EN,,0,0,0,,George would construct some complex number as a pair,
Dialogue: 0,0:24:55.07,0:24:58.24,EN,,0,0,0,,and before he passes it back up through the manager would
Dialogue: 0,0:24:59.42,0:25:01.13,EN,,0,0,0,,attach the type rectangular.
Dialogue: 0,0:25:03.92,0:25:04.65,EN,,0,0,0,,So you see what happens.
Dialogue: 0,0:25:04.65,0:25:05.85,EN,,0,0,0,,There's no confusion in this system.
Dialogue: 0,0:25:05.85,0:25:10.84,EN,,0,0,0,,It doesn't matter in the least that the pair 1, 2
Dialogue: 0,0:25:13.50,0:25:15.75,EN,,0,0,0,,means something completely different in Martha's world.
Dialogue: 0,0:25:15.75,0:25:18.44,EN,,0,0,0,,In Martha's world this pair means the complex number whose
Dialogue: 0,0:25:18.44,0:25:20.78,EN,,0,0,0,,magnitude is 1 and whose angle is 2.
Dialogue: 0,0:25:21.19,0:25:22.19,EN,,0,0,0,,And there's no confusion,
Dialogue: 0,0:25:22.22,0:25:27.25,EN,,0,0,0,,because by the time any pair like this gets handed back through the manager to the
Dialogue: 0,0:25:27.25,0:25:29.61,EN,,0,0,0,,main system it's going to have the type polar attached.
Dialogue: 0,0:25:31.21,0:25:33.67,EN,,0,0,0,,Whereas this one would have the type rectangular attached.
Dialogue: 0,0:25:36.93,0:25:37.90,EN,,0,0,0,,OK, let's take a break.
Dialogue: 0,0:25:40.77,0:25:55.55,EN,,0,0,0,,[JESU, JOY OF MAN'S DESIRING]
Dialogue: 0,0:25:55.69,0:25:57.77,EN,,0,0,0,,The Structure And Interpretation of Computer Programs
Dialogue: 0,0:25:57.77,0:25:59.76,EN,,0,0,0,,By: Prof. Harold Abelson && Gerald Jay Sussman
Dialogue: 0,0:26:05.21,0:26:11.95,EN,,0,0,0,,The Structure And Interpretation of Computer Programs
Dialogue: 0,0:26:12.84,0:26:16.75,EN,,0,0,0,,Generic Operators
Dialogue: 0,0:26:20.21,0:26:24.15,EN,,0,0,0,,We just looked at a strategy for implementing generic operators.
Dialogue: 0,0:26:24.15,0:26:31.40,EN,,0,0,0,,That strategy has a name: it's called dispatch on type.
Dialogue: 0,0:26:34.31,0:26:39.36,EN,,0,0,0,,And the idea is that you break your system into a bunch of pieces.
Dialogue: 0,0:26:39.36,0:26:42.67,EN,,0,0,0,,There's George and Martha, who are making representations,
Dialogue: 0,0:26:43.37,0:26:44.38,EN,,0,0,0,,and then there's the manager.
Dialogue: 0,0:26:46.12,0:26:48.06,EN,,0,0,0,,Looks at the types on the data
Dialogue: 0,0:26:48.51,0:26:50.59,EN,,0,0,0,,and then dispatches them to the right person.
Dialogue: 0,0:26:51.99,0:26:56.01,EN,,0,0,0,,Well what criticisms can we make of that as a system organization?
Dialogue: 0,0:26:58.15,0:27:00.40,EN,,0,0,0,,Well first of all there was this little, annoying problem
Dialogue: 0,0:27:00.40,0:27:03.05,EN,,0,0,0,,that George and Martha had to change the names of their procedures
Dialogue: 0,0:27:04.00,0:27:05.95,EN,,0,0,0,,George originally had a real-part procedure,
Dialogue: 0,0:27:05.98,0:27:08.28,EN,,0,0,0,,and he had to go name it real-part rectangular
Dialogue: 0,0:27:08.30,0:27:10.83,EN,,0,0,0,,so it wouldn't interfere with Martha's real-part procedure,
Dialogue: 0,0:27:10.84,0:27:12.76,EN,,0,0,0,,which is now named real-part-polar,
Dialogue: 0,0:27:13.64,0:27:16.68,EN,,0,0,0,,so it wouldn't interfere with the manager's real-part procedure, who's now named real-part.
Dialogue: 0,0:27:17.31,0:27:18.94,EN,,0,0,0,,That's kind of an annoying problem.
Dialogue: 0,0:27:19.46,0:27:21.13,EN,,0,0,0,,But I'm not going to talk about that one now.
Dialogue: 0,0:27:21.27,0:27:22.35,EN,,0,0,0,,We'll see later on
Dialogue: 0,0:27:23.26,0:27:26.12,EN,,0,0,0,,when we think about the structure of Lisp names and environments
Dialogue: 0,0:27:26.12,0:27:30.39,EN,,0,0,0,,that there really are ways to package all those so-called name spaces separately so they
Dialogue: 0,0:27:30.39,0:27:31.56,EN,,0,0,0,,don't interfere with each other.
Dialogue: 0,0:27:32.50,0:27:34.01,EN,,0,0,0,,Not going to think about that problem now.
Dialogue: 0,0:27:35.72,0:27:38.19,EN,,0,0,0,,The problem that I actually want to focus on is
Dialogue: 0,0:27:38.36,0:27:43.24,EN,,0,0,0,,what happens when you bring somebody new into the system.
Dialogue: 0,0:27:44.51,0:27:45.32,EN,,0,0,0,,What has to happen?
Dialogue: 0,0:27:45.32,0:27:46.81,EN,,0,0,0,,Well George and Martha don't care.
Dialogue: 0,0:27:47.42,0:27:50.73,EN,,0,0,0,,George is sitting there in his rectangular world,
Dialogue: 0,0:27:52.20,0:27:53.84,EN,,0,0,0,,has his procedures and his types.
Dialogue: 0,0:27:54.09,0:27:55.74,EN,,0,0,0,,Martha sits in her polar world.
Dialogue: 0,0:27:55.93,0:27:57.02,EN,,0,0,0,,She doesn't care.
Dialogue: 0,0:27:59.38,0:28:00.54,EN,,0,0,0,,But let's look at the manager.
Dialogue: 0,0:28:00.62,0:28:02.84,EN,,0,0,0,,What's the manager have to do?
Dialogue: 0,0:28:03.18,0:28:06.20,EN,,0,0,0,,The manager comes through and had these operations.
Dialogue: 0,0:28:07.36,0:28:09.04,EN,,0,0,0,,There was a test for rectangular
Dialogue: 0,0:28:09.04,0:28:10.14,EN,,0,0,0,,and a test for polar.
Dialogue: 0,0:28:10.14,0:28:14.91,EN,,0,0,0,,If Harry comes in with some new kind of complex number,
Dialogue: 0,0:28:17.21,0:28:19.96,EN,,0,0,0,,and Harry has a new type, Harry type complex number, the
Dialogue: 0,0:28:20.27,0:28:23.28,EN,,0,0,0,,manager has to go in and change all those procedures.
Dialogue: 0,0:28:25.24,0:28:26.94,EN,,0,0,0,,So the inflexibility in the system,
Dialogue: 0,0:28:26.96,0:28:32.41,EN,,0,0,0,,the place where work has to happen to accommodate change, is in the manager.
Dialogue: 0,0:28:34.89,0:28:35.99,EN,,0,0,0,,That's pretty annoying.
Dialogue: 0,0:28:35.99,0:28:37.21,EN,,0,0,0,,It's even more annoying
Dialogue: 0,0:28:39.05,0:28:41.21,EN,,0,0,0,,It's even more annoying when you realize the manager's not doing anything
Dialogue: 0,0:28:42.59,0:28:44.67,EN,,0,0,0,,The manager is just being a paper pusher.
Dialogue: 0,0:28:45.84,0:28:51.13,EN,,0,0,0,,Let's look again at these programs. What are they doing?
Dialogue: 0,0:28:51.76,0:28:52.72,EN,,0,0,0,,What does real-part do?
Dialogue: 0,0:28:52.88,0:28:56.17,EN,,0,0,0,,Real-part says, oh, is it the kind of complex number that
Dialogue: 0,0:28:56.17,0:28:57.00,EN,,0,0,0,,George can handle?
Dialogue: 0,0:28:57.00,0:28:58.27,EN,,0,0,0,,If so, send it off to George.
Dialogue: 0,0:28:59.41,0:29:01.76,EN,,0,0,0,,Is it the kind of complex number that Martha can handle?
Dialogue: 0,0:29:01.82,0:29:04.06,EN,,0,0,0,,If so, send it off to Martha.
Dialogue: 0,0:29:05.04,0:29:08.72,EN,,0,0,0,,So it's really annoying that the bottleneck in this system,
Dialogue: 0,0:29:08.72,0:29:11.66,EN,,0,0,0,,the thing that's preventing flexibility and change,
Dialogue: 0,0:29:12.09,0:29:14.36,EN,,0,0,0,,is completely in the bureaucracy.
Dialogue: 0,0:29:15.00,0:29:17.02,EN,,0,0,0,,It's not in anybody who's doing any of the work.
Dialogue: 0,0:29:19.70,0:29:21.80,EN,,0,0,0,,Not an uncommon situation, unfortunately.
Dialogue: 0,0:29:23.18,0:29:24.41,EN,,0,0,0,,See, what's really going on--
Dialogue: 0,0:29:24.48,0:29:26.97,EN,,0,0,0,,abstractly in the system, there's a table.
Dialogue: 0,0:29:28.10,0:29:30.08,EN,,0,0,0,,So what's really happening is somewhere there's a table.
Dialogue: 0,0:29:30.84,0:29:33.64,EN,,0,0,0,,There're types.
Dialogue: 0,0:29:34.40,0:29:38.96,EN,,0,0,0,,There's polar and rectangular.
Dialogue: 0,0:29:41.55,0:29:43.02,EN,,0,0,0,,And Harry's may be over here.
Dialogue: 0,0:29:44.38,0:29:46.56,EN,,0,0,0,,And there are operators.
Dialogue: 0,0:29:48.05,0:29:58.24,EN,,0,0,0,,There's an operator like real-part. Or imaginary-part.
Dialogue: 0,0:30:00.01,0:30:04.22,EN,,0,0,0,,Or a magnitude and angle.
Dialogue: 0,0:30:05.83,0:30:18.97,EN,,0,0,0,,And sitting in this table are the right procedures.
Dialogue: 0,0:30:19.28,0:30:21.99,EN,,0,0,0,,So sitting here for the type polar and real-part is
Dialogue: 0,0:30:21.99,0:30:27.56,EN,,0,0,0,,Martha's procedure real-part-polar.
Dialogue: 0,0:30:30.57,0:30:36.62,EN,,0,0,0,,And over here in the table is George's procedure real-part-rectangular.
Dialogue: 0,0:30:37.74,0:30:43.07,EN,,0,0,0,,And over here would be, say, Martha's procedure magnitude-polar,
Dialogue: 0,0:30:44.46,0:30:49.76,EN,,0,0,0,,and George's procedure magnitude-rectangular, right, and so on.
Dialogue: 0,0:30:49.76,0:30:51.24,EN,,0,0,0,,The rest of this table's filled in.
Dialogue: 0,0:30:52.39,0:30:54.26,EN,,0,0,0,,And that's really what's going on.
Dialogue: 0,0:30:57.63,0:31:01.74,EN,,0,0,0,,So in some sense, all the manager is doing
Dialogue: 0,0:31:02.11,0:31:04.11,EN,,0,0,0,,is acting as this table.
Dialogue: 0,0:31:06.86,0:31:08.70,EN,,0,0,0,,Well how do we fix our system?
Dialogue: 0,0:31:11.74,0:31:13.77,EN,,0,0,0,,Well, how do you fix bureaucracies a lot of the time?
Dialogue: 0,0:31:13.77,0:31:15.44,EN,,0,0,0,,What you do is you get rid of the manager.
Dialogue: 0,0:31:16.01,0:31:19.55,EN,,0,0,0,,We just take the manager and replace him by a computer.
Dialogue: 0,0:31:20.17,0:31:21.76,EN,,0,0,0,,We're going to automate him out of existence.
Dialogue: 0,0:31:23.32,0:31:26.57,EN,,0,0,0,,Namely, instead of having the manager who basically consults this table,
Dialogue: 0,0:31:27.45,0:31:29.32,EN,,0,0,0,,we'll have our system use the table directly.
Dialogue: 0,0:31:31.02,0:31:32.11,EN,,0,0,0,,What do I mean by that?
Dialogue: 0,0:31:32.11,0:31:36.19,EN,,0,0,0,,Let's assume, again using data abstraction,
Dialogue: 0,0:31:37.71,0:31:40.40,EN,,0,0,0,,that we have some kind of data structure that's a table.
Dialogue: 0,0:31:40.88,0:31:43.61,EN,,0,0,0,,And we have ways of sticking things in and ways of getting things out.
Dialogue: 0,0:31:44.35,0:31:49.04,EN,,0,0,0,,And to be explicit, let me assume that there's an operation called "put."
Dialogue: 0,0:31:50.30,0:31:58.32,EN,,0,0,0,,And put is going to take, case two things I'll call "keys." key1 and key2.
Dialogue: 0,0:32:00.13,0:32:00.99,EN,,0,0,0,,And a value.
Dialogue: 0,0:32:06.20,0:32:11.12,EN,,0,0,0,,And that stores the value in the table under key1 and key2.
Dialogue: 0,0:32:11.49,0:32:13.16,EN,,0,0,0,,And then we'll assume there's a thing called "get,"
Dialogue: 0,0:32:15.23,0:32:18.72,EN,,0,0,0,,such that if later on I say, get me what's in the table
Dialogue: 0,0:32:19.40,0:32:22.76,EN,,0,0,0,,stored under key1 and key2,
Dialogue: 0,0:32:23.40,0:32:25.39,EN,,0,0,0,,it'll retrieve whatever value was stored there.
Dialogue: 0,0:32:26.73,0:32:29.44,EN,,0,0,0,,And let's not worry about how tables are implemented.
Dialogue: 0,0:32:30.00,0:32:32.52,EN,,0,0,0,,That's yet another data abstraction, George's problem.
Dialogue: 0,0:32:33.06,0:32:34.36,EN,,0,0,0,,And maybe we'll see later--
Dialogue: 0,0:32:34.70,0:32:36.97,EN,,0,0,0,,talk about how you might actually build tables in Lisp.
Dialogue: 0,0:32:40.71,0:32:45.50,EN,,0,0,0,,Well given this organization,what did George and Martha have to do?
Dialogue: 0,0:32:47.38,0:32:49.07,EN,,0,0,0,,Well when they build their system,
Dialogue: 0,0:32:49.13,0:32:51.08,EN,,0,0,0,,they each have the responsibility
Dialogue: 0,0:32:51.44,0:32:53.82,EN,,0,0,0,,to set up their appropriate column in the table.
Dialogue: 0,0:32:55.21,0:32:57.47,EN,,0,0,0,,So what George does, for example,
Dialogue: 0,0:32:59.79,0:33:02.06,EN,,0,0,0,,when he defines his procedures all he has to do
Dialogue: 0,0:33:02.27,0:33:07.99,EN,,0,0,0,,is go off and put into the table under the type-rectangular.
Dialogue: 0,0:33:09.82,0:33:12.12,EN,,0,0,0,,And the name of the operation is real-part,
Dialogue: 0,0:33:13.31,0:33:15.26,EN,,0,0,0,,his procedure real-part-rectangular.
Dialogue: 0,0:33:16.25,0:33:17.78,EN,,0,0,0,,So notice what's going into this table.
Dialogue: 0,0:33:17.78,0:33:22.10,EN,,0,0,0,,The two keys here are symbols, rectangular and real-part.
Dialogue: 0,0:33:22.10,0:33:22.75,EN,,0,0,0,,That's the quote.
Dialogue: 0,0:33:24.40,0:33:26.75,EN,,0,0,0,,And what's going into the table is the actual
Dialogue: 0,0:33:26.84,0:33:29.21,EN,,0,0,0,,procedure that he wrote, real-part rectangular.
Dialogue: 0,0:33:31.85,0:33:34.30,EN,,0,0,0,,And then puts an imaginary part into the table,
Dialogue: 0,0:33:34.59,0:33:37.80,EN,,0,0,0,,filed under the keys rectangular and imaginary-part,
Dialogue: 0,0:33:38.62,0:33:42.88,EN,,0,0,0,,and magnitude under the keys rectangular magnitude,
Dialogue: 0,0:33:43.61,0:33:45.20,EN,,0,0,0,,angle under rectangular-angle.
Dialogue: 0,0:33:47.04,0:33:50.84,EN,,0,0,0,,Okay? So that's what George has to do to be part of this system.
Dialogue: 0,0:33:54.42,0:33:58.86,EN,,0,0,0,,Martha similarly sets up the column and the table under polar.
Dialogue: 0,0:33:59.43,0:34:00.65,EN,,0,0,0,,Polar and real-part.
Dialogue: 0,0:34:01.69,0:34:03.58,EN,,0,0,0,,Right? Is the procedure real-part-polar?
Dialogue: 0,0:34:04.34,0:34:07.29,EN,,0,0,0,,And imaginary-part, and magnitude, and angle.
Dialogue: 0,0:34:08.91,0:34:11.40,EN,,0,0,0,,So this is what Martha has to do to be part of the system.
Dialogue: 0,0:34:11.40,0:34:13.55,EN,,0,0,0,,Everyone who makes a representation has the
Dialogue: 0,0:34:13.55,0:34:17.63,EN,,0,0,0,,responsibility for setting up a column in the table.
Dialogue: 0,0:34:17.76,0:34:19.90,EN,,0,0,0,,And what does Harry do when Harry comes in with his
Dialogue: 0,0:34:19.90,0:34:21.80,EN,,0,0,0,,brilliant idea for implementing complex numbers?
Dialogue: 0,0:34:21.80,0:34:23.96,EN,,0,0,0,,Well he makes whatever procedure he wants and
Dialogue: 0,0:34:24.04,0:34:26.52,EN,,0,0,0,,builds a new column in this table.
Dialogue: 0,0:34:28.55,0:34:30.04,EN,,0,0,0,,OK, well what happened to the manager?
Dialogue: 0,0:34:31.33,0:34:34.61,EN,,0,0,0,,The manager has been automated out of existence and is
Dialogue: 0,0:34:34.61,0:34:37.11,EN,,0,0,0,,replaced by a procedure called operate.
Dialogue: 0,0:34:37.11,0:34:39.55,EN,,0,0,0,,And this is the key procedure in the whole system.
Dialogue: 0,0:34:40.38,0:34:45.92,EN,,0,0,0,,Let's say define operate.
Dialogue: 0,0:34:51.06,0:34:56.09,EN,,0,0,0,,Operate is going to take an operation that you want to do,
Dialogue: 0,0:34:57.75,0:34:58.88,EN,,0,0,0,,the name of an operation,
Dialogue: 0,0:34:59.20,0:35:03.28,EN,,0,0,0,,and an object that you would like to apply that operation to.
Dialogue: 0,0:35:04.21,0:35:09.76,EN,,0,0,0,,So for example, the real-part of some particular complex number, what does it do?
Dialogue: 0,0:35:09.95,0:35:11.90,EN,,0,0,0,,Well the first thing it does, it looks in the table.
Dialogue: 0,0:35:12.64,0:35:13.87,EN,,0,0,0,,Goes into the table
Dialogue: 0,0:35:14.80,0:35:22.56,EN,,0,0,0,,and tries to find a procedure that's stored in the table.
Dialogue: 0,0:35:23.15,0:35:24.80,EN,,0,0,0,,So it gets from the table,
Dialogue: 0,0:35:25.50,0:35:33.92,EN,,0,0,0,,using as keys the type of the object and the operator,
Dialogue: 0,0:35:38.92,0:35:40.14,EN,,0,0,0,,but looks on the table and sees
Dialogue: 0,0:35:40.38,0:35:42.72,EN,,0,0,0,,what's stored under the type of the object and the operator
Dialogue: 0,0:35:42.89,0:35:44.35,EN,,0,0,0,,sees if anything's stored.
Dialogue: 0,0:35:44.44,0:35:45.93,EN,,0,0,0,,Let's assume that get is implemented.
Dialogue: 0,0:35:45.93,0:35:47.72,EN,,0,0,0,,So if nothing is stored there,
Dialogue: 0,0:35:48.11,0:35:51.79,EN,,0,0,0,,it'll return a nil, return the empty list.
Dialogue: 0,0:35:52.67,0:35:55.39,EN,,0,0,0,,So it says, if there's actually something stored there,
Dialogue: 0,0:35:56.62,0:36:00.43,EN,,0,0,0,,if the procedure here is not no,
Dialogue: 0,0:36:03.15,0:36:07.12,EN,,0,0,0,,then it'll take the procedure that it found in the table
Dialogue: 0,0:36:09.79,0:36:15.00,EN,,0,0,0,,procedure that it found in the table and apply it to the contents of the object.
Dialogue: 0,0:36:18.25,0:36:20.40,EN,,0,0,0,,And otherwise if there was nothing stored there,
Dialogue: 0,0:36:20.67,0:36:22.51,EN,,0,0,0,,it'll-- well we can decide.
Dialogue: 0,0:36:22.81,0:36:27.12,EN,,0,0,0,,In this case let's have it put out an error message saying, undefined operator.
Dialogue: 0,0:36:28.48,0:36:30.24,EN,,0,0,0,,No operator for this type.
Dialogue: 0,0:36:33.07,0:36:34.72,EN,,0,0,0,,Or some appropriate error message.
Dialogue: 0,0:36:39.07,0:36:39.48,EN,,0,0,0,,OK?
Dialogue: 0,0:36:39.72,0:36:41.04,EN,,0,0,0,,And that replaces the manager.
Dialogue: 0,0:36:41.89,0:36:42.91,EN,,0,0,0,,How do we really use it?
Dialogue: 0,0:36:43.96,0:36:49.80,EN,,0,0,0,,Well what we say is we'll go off and define our generic selectors using operate.
Dialogue: 0,0:36:50.04,0:36:56.75,EN,,0,0,0,,We'll say that the real-part of an object is found by
Dialogue: 0,0:36:57.14,0:37:05.66,EN,,0,0,0,,operating on the object with the name of the operation being real-part.
Dialogue: 0,0:37:08.07,0:37:12.22,EN,,0,0,0,,And then similarly, imaginary-part is operate using the name imaginary-part
Dialogue: 0,0:37:12.22,0:37:13.98,EN,,0,0,0,,and magnitude and angle.
Dialogue: 0,0:37:15.36,0:37:17.43,EN,,0,0,0,,That's our implementation.
Dialogue: 0,0:37:17.43,0:37:20.48,EN,,0,0,0,,That plus the type plus the operate procedure.
Dialogue: 0,0:37:21.33,0:37:24.00,EN,,0,0,0,,And the table effectively replaces what the manager used to do.
Dialogue: 0,0:37:24.06,0:37:27.69,EN,,0,0,0,,Let's just go through that slowly to show you what's going on.
Dialogue: 0,0:37:27.90,0:37:33.00,EN,,0,0,0,,Suppose I have one of Martha's complex numbers.
Dialogue: 0,0:37:33.53,0:37:38.80,EN,,0,0,0,,It's got magnitude 1 and angle 2.
Dialogue: 0,0:37:39.10,0:37:40.22,EN,,0,0,0,,And it's one of Martha's.
Dialogue: 0,0:37:40.22,0:37:45.45,EN,,0,0,0,,So it's labeled here, polar.
Dialogue: 0,0:37:47.24,0:37:48.00,EN,,0,0,0,,Let's call that z.
Dialogue: 0,0:37:48.00,0:37:48.91,EN,,0,0,0,,Suppose that's z.
Dialogue: 0,0:37:51.77,0:37:54.46,EN,,0,0,0,,And suppose with this implementation someone comes up
Dialogue: 0,0:37:54.80,0:37:57.92,EN,,0,0,0,,asks for the real-part of z.
Dialogue: 0,0:38:04.87,0:38:07.96,EN,,0,0,0,,Well real-part now is defined in terms of operate.
Dialogue: 0,0:38:09.16,0:38:10.57,EN,,0,0,0,,So that's equivalent to saying
Dialogue: 0,0:38:12.09,0:38:24.81,EN,,0,0,0,,operate with the name of the operator being real-part, the symbol real-part on z.
Dialogue: 0,0:38:27.06,0:38:28.09,EN,,0,0,0,,And now operate comes.
Dialogue: 0,0:38:28.09,0:38:29.24,EN,,0,0,0,,It's going to look in the table,
Dialogue: 0,0:38:31.04,0:38:34.36,EN,,0,0,0,,and it's going to try and find something stored under--
Dialogue: 0,0:38:39.00,0:38:46.22,EN,,0,0,0,,the operation is going to apply by looking in the table under the type of the object.
Dialogue: 0,0:38:46.72,0:38:48.22,EN,,0,0,0,,And the type of z is polar.
Dialogue: 0,0:38:48.79,0:38:51.37,EN,,0,0,0,,So it's going to look and say, can I get using polar?
Dialogue: 0,0:38:52.99,0:38:58.57,EN,,0,0,0,,And the operation name, which was real-part.
Dialogue: 0,0:39:05.96,0:39:13.63,EN,,0,0,0,,It's going to look in there and apply that to the contents of z.
Dialogue: 0,0:39:14.83,0:39:17.13,EN,,0,0,0,,What's that is if everything was set up correctly,
Dialogue: 0,0:39:17.74,0:39:21.70,EN,,0,0,0,,this thing is the procedure that Martha put there.
Dialogue: 0,0:39:21.70,0:39:22.95,EN,,0,0,0,,This is real-part-polar.
Dialogue: 0,0:39:31.05,0:39:35.13,EN,,0,0,0,,And this is z without its type.
Dialogue: 0,0:39:35.44,0:39:38.94,EN,,0,0,0,,The thing that Martha originally designed those procedures to work on,
Dialogue: 0,0:39:39.40,0:39:40.43,EN,,0,0,0,,which is 1, 2.
Dialogue: 0,0:39:43.71,0:39:45.87,EN,,0,0,0,,And so operate sort of does uniformly
Dialogue: 0,0:39:46.46,0:39:48.89,EN,,0,0,0,,what the manager used to do sort of all over the system.
Dialogue: 0,0:39:49.45,0:39:52.59,EN,,0,0,0,,It finds the right thing, looks in the table, strips off the type,
Dialogue: 0,0:39:53.58,0:39:57.52,EN,,0,0,0,,and passes it down into the person who handles it.
Dialogue: 0,0:39:58.88,0:40:05.48,EN,,0,0,0,,This is another, and, you can see, more flexible for most purposes,
Dialogue: 0,0:40:06.22,0:40:08.04,EN,,0,0,0,,way of implementing generic operators.
Dialogue: 0,0:40:08.08,0:40:15.69,EN,,0,0,0,,And it's called data-directed programming.
Dialogue: 0,0:40:20.35,0:40:21.96,EN,,0,0,0,,And the idea of that is
Dialogue: 0,0:40:23.42,0:40:25.55,EN,,0,0,0,,And the idea of that is in some sense the data objects themselves,
Dialogue: 0,0:40:26.04,0:40:28.35,EN,,0,0,0,,those little complex numbers that are floating around the system,
Dialogue: 0,0:40:28.73,0:40:33.16,EN,,0,0,0,,are carrying with them the information about how you should operate on them.
Dialogue: 0,0:40:35.74,0:40:36.78,EN,,0,0,0,,Let's break for questions.
Dialogue: 0,0:40:41.00,0:40:41.24,EN,,0,0,0,,Yes.
Dialogue: 0,0:40:41.24,0:40:43.39,EN,,0,0,0,,AUDIENCE: What do you have stored in that data object?
Dialogue: 0,0:40:43.39,0:40:47.10,EN,,0,0,0,,You have the data itself, you have its type,
Dialogue: 0,0:40:47.10,0:40:49.60,EN,,0,0,0,,the operations for that type?
Dialogue: 0,0:40:49.69,0:40:53.08,EN,,0,0,0,,Or where are the operations that you found?
Dialogue: 0,0:40:53.60,0:40:54.17,EN,,0,0,0,,PROFESSOR: OK, let me--
Dialogue: 0,0:40:54.98,0:40:56.50,EN,,0,0,0,,yeah, that's a good question.
Dialogue: 0,0:40:56.50,0:41:00.46,EN,,0,0,0,,Because it raises other possibilities of how you might do it.
Dialogue: 0,0:41:00.75,0:41:02.48,EN,,0,0,0,,And of course there are a lot of possibilities.
Dialogue: 0,0:41:04.20,0:41:06.14,EN,,0,0,0,,In this particular implementation,
Dialogue: 0,0:41:06.24,0:41:09.72,EN,,0,0,0,,what's sitting in this data object, for example,
Dialogue: 0,0:41:10.44,0:41:13.45,EN,,0,0,0,,is the data itself-- which in this case is a pair of 1 and 2--
Dialogue: 0,0:41:14.98,0:41:16.55,EN,,0,0,0,,and also a symbol.
Dialogue: 0,0:41:16.55,0:41:19.07,EN,,0,0,0,,This is the symbol, the word P-O-L-A-R,
Dialogue: 0,0:41:20.60,0:41:22.33,EN,,0,0,0,,And that what's sitting in this data object.
Dialogue: 0,0:41:24.24,0:41:26.69,EN,,0,0,0,,OK, where are the operations themselves?
Dialogue: 0,0:41:26.69,0:41:29.00,EN,,0,0,0,,The operations are sitting in the table.
Dialogue: 0,0:41:29.85,0:41:31.07,EN,,0,0,0,,So in this table,
Dialogue: 0,0:41:32.30,0:41:36.46,EN,,0,0,0,,the rows and columns of the table are labeled by symbols.
Dialogue: 0,0:41:38.23,0:41:40.08,EN,,0,0,0,,So when I store something in this table,
Dialogue: 0,0:41:40.09,0:41:47.02,EN,,0,0,0,,the key might be the symbol polar and the symbol magnitude.
Dialogue: 0,0:41:48.24,0:41:51.31,EN,,0,0,0,,And I think by writing it this way I've been very confusing.
Dialogue: 0,0:41:51.31,0:41:52.70,EN,,0,0,0,,Because what's really sitting here isn't--
Dialogue: 0,0:41:53.16,0:41:54.57,EN,,0,0,0,,when I wrote magnitude polar,
Dialogue: 0,0:41:57.04,0:41:59.23,EN,,0,0,0,,what I mean is the procedure magnitude polar.
Dialogue: 0,0:41:59.85,0:42:01.85,EN,,0,0,0,,And probably what I really should have written--
Dialogue: 0,0:42:02.58,0:42:04.20,EN,,0,0,0,,except it's too small for me to write
Dialogue: 0,0:42:04.20,0:42:05.07,EN,,0,0,0,,in this little space--
Dialogue: 0,0:42:05.58,0:42:08.92,EN,,0,0,0,,is something like lambda of z,
Dialogue: 0,0:42:10.60,0:42:12.75,EN,,0,0,0,,the thing that Martha wrote to implement.
Dialogue: 0,0:42:14.71,0:42:15.72,EN,,0,0,0,,And then you can see from that,
Dialogue: 0,0:42:15.74,0:42:17.44,EN,,0,0,0,,there's another way that I alluded to
Dialogue: 0,0:42:17.71,0:42:19.82,EN,,0,0,0,,of solving this name conflict problem
Dialogue: 0,0:42:20.04,0:42:23.15,EN,,0,0,0,,which is that George and Martha never have to name their procedures at all.
Dialogue: 0,0:42:23.15,0:42:25.37,EN,,0,0,0,,They can just stick the lambda, the lambda...
Dialogue: 0,0:42:25.39,0:42:28.12,EN,,0,0,0,,the anonymous things generated by lambda directly into the table.
Dialogue: 0,0:42:28.66,0:42:31.76,EN,,0,0,0,,There's also another thing that your question raises,
Dialogue: 0,0:42:32.35,0:42:34.06,EN,,0,0,0,,is the possibility that maybe
Dialogue: 0,0:42:34.83,0:42:37.92,EN,,0,0,0,,what I would like somehow is to store in this data object
Dialogue: 0,0:42:37.95,0:42:39.48,EN,,0,0,0,,not the symbol P-O-L-A-R but
Dialogue: 0,0:42:39.93,0:42:42.35,EN,,0,0,0,,maybe actually all the operations themselves.
Dialogue: 0,0:42:43.90,0:42:45.63,EN,,0,0,0,,And that's another way to organize the system,
Dialogue: 0,0:42:45.66,0:42:46.60,EN,,0,0,0,,called message passing.
Dialogue: 0,0:42:48.65,0:42:49.92,EN,,0,0,0,,So there are a lot of ways you can do it.
Dialogue: 0,0:42:54.64,0:42:58.04,EN,,0,0,0,,AUDIENCE: Therefore if Martha and George had used the same
Dialogue: 0,0:42:58.04,0:43:01.23,EN,,0,0,0,,procedure names, it would be OK because it wouldn't look
Dialogue: 0,0:43:01.23,0:43:02.56,EN,,0,0,0,,it wouldn't look into it
Dialogue: 0,0:43:02.56,0:43:04.68,EN,,0,0,0,,PROFESSOR: That's right.That's right.
Dialogue: 0,0:43:04.80,0:43:07.85,EN,,0,0,0,,See, they wouldn't even have to name their procedures at all.
Dialogue: 0,0:43:08.04,0:43:09.36,EN,,0,0,0,,What George and Martha could writ --,
Dialogue: 0,0:43:09.50,0:43:10.62,EN,,0,0,0,,what George could have written
Dialogue: 0,0:43:10.83,0:43:15.28,EN,,0,0,0,,instead of saying put in the table under rectangular- and real-part,
Dialogue: 0,0:43:16.22,0:43:17.98,EN,,0,0,0,,the procedure real-part rectangular,
Dialogue: 0,0:43:18.03,0:43:21.15,EN,,0,0,0,,George could have written put under rectangular real-part,
Dialogue: 0,0:43:21.24,0:43:23.69,EN,,0,0,0,,lambda of z, such and such, such and such,
Dialogue: 0,0:43:24.54,0:43:26.84,EN,,0,0,0,,And the system would work completely the same.
Dialogue: 0,0:43:27.33,0:43:29.24,EN,,0,0,0,,AUDIENCE: My question is, Martha could put
Dialogue: 0,0:43:29.84,0:43:33.60,EN,,0,0,0,,could have put key1 key2 real-part,
Dialogue: 0,0:43:33.95,0:43:37.64,EN,,0,0,0,,and George could have put key1 key2 real-part,
Dialogue: 0,0:43:37.96,0:43:39.60,EN,,0,0,0,,and as long as they defined them differently
Dialogue: 0,0:43:39.80,0:43:41.26,EN,,0,0,0,,they wouldn't have had any conflicts, right?
Dialogue: 0,0:43:41.29,0:43:43.80,EN,,0,0,0,,PROFESSOR: Yes, that would all be OK except for the fact
Dialogue: 0,0:43:44.97,0:43:47.13,EN,,0,0,0,,that if you imagine George and Martha typing at the same
Dialogue: 0,0:43:47.13,0:43:49.20,EN,,0,0,0,,console with the same meanings for all their names,
Dialogue: 0,0:43:49.82,0:43:51.23,EN,,0,0,0,,and it would get confused by real-part,
Dialogue: 0,0:43:51.24,0:43:52.80,EN,,0,0,0,,but there are ways to arrange that, too.
Dialogue: 0,0:43:52.80,0:43:54.80,EN,,0,0,0,,And in principle you're absolutely right.
Dialogue: 0,0:43:54.98,0:43:56.29,EN,,0,0,0,,If their names didn't conflict--
Dialogue: 0,0:43:56.29,0:43:58.19,EN,,0,0,0,,it's the objects that go in the table, not the names.
Dialogue: 0,0:44:08.20,0:44:09.05,EN,,0,0,0,,OK, let's take a break.
Dialogue: 0,0:44:12.91,0:44:20.48,EN,,0,0,0,,[JESU, JOY OF MAN'S DESIRING]
Dialogue: 0,0:44:20.96,0:44:23.29,EN,,0,0,0,,The Structure And Interpretation of Computer Programs
Dialogue: 0,0:44:23.45,0:44:25.29,EN,,0,0,0,,By: Prof. Harold Abelson && Gerald Jay Sussman
Dialogue: 0,0:44:57.42,0:45:05.07,EN,,0,0,0,,The Structure And Interpretation of Computer Programs
Dialogue: 0,0:45:05.47,0:45:09.24,EN,,0,0,0,,Generic Operators
Dialogue: 0,0:45:12.88,0:45:16.88,EN,,0,0,0,,RPOFESSOR: All right, well we just looked at data-directed programming
Dialogue: 0,0:45:17.68,0:45:22.84,EN,,0,0,0,,as a way of implementing a system that does arithmetic on complex numbers.
Dialogue: 0,0:45:27.60,0:45:32.48,EN,,0,0,0,,So I had these operations in it called plus C and minus C,
Dialogue: 0,0:45:32.88,0:45:37.24,EN,,0,0,0,,and multiply, and divide,and maybe some others.
Dialogue: 0,0:45:38.23,0:45:45.72,EN,,0,0,0,,And that sat on top of-- and this is the key point--
Dialogue: 0,0:45:45.74,0:45:49.60,EN,,0,0,0,,sat on top of two different representations.
Dialogue: 0,0:45:50.34,0:45:55.44,EN,,0,0,0,,A rectangular package here, and a polar package.
Dialogue: 0,0:45:58.14,0:45:59.15,EN,,0,0,0,,And maybe some more.
Dialogue: 0,0:45:59.15,0:46:02.80,EN,,0,0,0,,And we saw that the whole idea is that maybe some more are now very easy to add.
Dialogue: 0,0:46:04.67,0:46:08.35,EN,,0,0,0,,But that doesn't really show the power of this methodology.
Dialogue: 0,0:46:08.90,0:46:10.15,EN,,0,0,0,,Shows you what's going on.
Dialogue: 0,0:46:10.15,0:46:12.33,EN,,0,0,0,,The power of the methodology only becomes apparent
Dialogue: 0,0:46:12.94,0:46:15.79,EN,,0,0,0,,when you start embedding this in some more complex system.
Dialogue: 0,0:46:16.17,0:46:17.74,EN,,0,0,0,,So let... What I'm going to do now
Dialogue: 0,0:46:17.87,0:46:20.01,EN,,0,0,0,,is embed this in some more complex system.
Dialogue: 0,0:46:20.25,0:46:25.28,EN,,0,0,0,,Let's assume that what we really have is a general kind of arithmetic system.
Dialogue: 0,0:46:25.28,0:46:27.24,EN,,0,0,0,,So called generic arithmetic system.
Dialogue: 0,0:46:27.24,0:46:28.54,EN,,0,0,0,,And at the top level here,
Dialogue: 0,0:46:30.76,0:46:35.92,EN,,0,0,0,,somebody can say add twothings, or subtract two things,
Dialogue: 0,0:46:37.45,0:46:41.05,EN,,0,0,0,,or multiply two things, or divide two things.
Dialogue: 0,0:46:44.14,0:46:46.52,EN,,0,0,0,,And underneath that there's an abstraction barrier.
Dialogue: 0,0:46:47.93,0:46:49.15,EN,,0,0,0,,And underneath this barrier,
Dialogue: 0,0:46:49.50,0:46:52.48,EN,,0,0,0,,is, say, a complex arithmetic package.
Dialogue: 0,0:46:53.02,0:46:54.96,EN,,0,0,0,,And you can say, add two complex numbers.
Dialogue: 0,0:46:55.04,0:46:58.83,EN,,0,0,0,,Or you might also have--remember we did a rational number package
Dialogue: 0,0:46:58.88,0:46:59.93,EN,,0,0,0,,you might have that sitting there.
Dialogue: 0,0:47:00.19,0:47:01.72,EN,,0,0,0,,And there might be a rational thing.
Dialogue: 0,0:47:04.76,0:47:06.22,EN,,0,0,0,,And the rational number package,
Dialogue: 0,0:47:07.16,0:47:14.75,EN,,0,0,0,,well, has the things we implemented. Plus rat, and times rat, and so on.
Dialogue: 0,0:47:15.39,0:47:17.01,EN,,0,0,0,,Or you might have ordinary Lisp numbers.
Dialogue: 0,0:47:17.01,0:47:18.99,EN,,0,0,0,,You might say add three and four.
Dialogue: 0,0:47:19.42,0:47:20.94,EN,,0,0,0,,So we might have ordinary numbers,
Dialogue: 0,0:47:28.28,0:47:34.67,EN,,0,0,0,,in which case we have the Lisp supplied plus, and minus, and times, and slash.
Dialogue: 0,0:47:36.67,0:47:39.12,EN,,0,0,0,,OK, so we might imagine this complex number system
Dialogue: 0,0:47:39.44,0:47:44.44,EN,,0,0,0,,sitting in a more complicated generic operator structure at the next level up.
Dialogue: 0,0:47:47.73,0:47:48.73,EN,,0,0,0,,Well how can we make that?
Dialogue: 0,0:47:49.05,0:47:52.32,EN,,0,0,0,,We already have the idea, we're just going to do it again.
Dialogue: 0,0:47:52.78,0:47:54.72,EN,,0,0,0,,We've implemented a rational number package.
Dialogue: 0,0:47:54.72,0:47:56.89,EN,,0,0,0,,Let's look at how it has to be changed.
Dialogue: 0,0:48:01.48,0:48:03.40,EN,,0,0,0,,In fact, at this level it doesn't have to be changed at all.
Dialogue: 0,0:48:03.73,0:48:05.88,EN,,0,0,0,,This is exactly the code that we wrote last time.
Dialogue: 0,0:48:07.18,0:48:08.97,EN,,0,0,0,,To add two rational numbers,
Dialogue: 0,0:48:09.85,0:48:10.91,EN,,0,0,0,,remember there was this formula.
Dialogue: 0,0:48:11.14,0:48:13.37,EN,,0,0,0,,You make a rational number whose numerator--
Dialogue: 0,0:48:13.98,0:48:17.56,EN,,0,0,0,,is the numerator of the first times the denominator of the second
Dialogue: 0,0:48:17.93,0:48:21.52,EN,,0,0,0,,plus the denominator of the first times the numerator of the second.
Dialogue: 0,0:48:21.52,0:48:23.79,EN,,0,0,0,,And who's denominator is the product of the denominators.
Dialogue: 0,0:48:25.76,0:48:29.07,EN,,0,0,0,,And minus rat, and star rat, and slash rat.
Dialogue: 0,0:48:30.36,0:48:35.12,EN,,0,0,0,,And this is exactly the rational number package that we made before.
Dialogue: 0,0:48:36.31,0:48:38.89,EN,,0,0,0,,We're ignoring the GCD problem,but let's not worry about that.
Dialogue: 0,0:48:39.08,0:48:42.59,EN,,0,0,0,,How do we install... As implementers of this rational number package,
Dialogue: 0,0:48:42.80,0:48:45.10,EN,,0,0,0,,how do we install it in the generic arithmetic system?
Dialogue: 0,0:48:45.57,0:48:46.22,EN,,0,0,0,,Well that's easy.
Dialogue: 0,0:48:47.29,0:48:51.56,EN,,0,0,0,,Go off... There's only one thing we have to do differently.
Dialogue: 0,0:48:51.84,0:48:55.71,EN,,0,0,0,,Whereas previously we said that to make a rational number
Dialogue: 0,0:48:56.27,0:48:59.98,EN,,0,0,0,,you built a pair of the numerator and denominator,
Dialogue: 0,0:49:00.96,0:49:03.20,EN,,0,0,0,,here we'll not only build the pair, but we'll sign it.
Dialogue: 0,0:49:03.30,0:49:04.56,EN,,0,0,0,,We'll attach the type rational.
Dialogue: 0,0:49:06.36,0:49:08.09,EN,,0,0,0,,That's the only thing we have to do different,
Dialogue: 0,0:49:08.56,0:49:10.09,EN,,0,0,0,,make it a typed data object.
Dialogue: 0,0:49:12.38,0:49:14.08,EN,,0,0,0,,And now we'll stick our operations in the table.
Dialogue: 0,0:49:14.36,0:49:18.20,EN,,0,0,0,,We'll put under the symbol rational and the operation add
Dialogue: 0,0:49:18.92,0:49:20.25,EN,,0,0,0,,our procedure -- +rat.
Dialogue: 0,0:49:21.82,0:49:23.24,EN,,0,0,0,,And, again, note this is a symbol.
Dialogue: 0,0:49:23.74,0:49:23.93,EN,,0,0,0,,Right?
Dialogue: 0,0:49:24.03,0:49:25.29,EN,,0,0,0,,Quote, and quote,
Dialogue: 0,0:49:25.31,0:49:28.01,EN,,0,0,0,,but the actual thing we're putting in the table is the procedure.
Dialogue: 0,0:49:29.82,0:49:31.77,EN,,0,0,0,,And for how to subtract,
Dialogue: 0,0:49:31.79,0:49:36.81,EN,,0,0,0,,well you subtract rationals with minus rat.
Dialogue: 0,0:49:38.27,0:49:40.24,EN,,0,0,0,,And multiply, and divide.
Dialogue: 0,0:49:41.09,0:49:43.64,EN,,0,0,0,,And that is exactly and precisely what we have to do
Dialogue: 0,0:49:44.14,0:49:46.97,EN,,0,0,0,,to fit inside this generic arithmetic system.
Dialogue: 0,0:49:48.51,0:49:49.88,EN,,0,0,0,,Well how does the whole thing work?
Dialogue: 0,0:49:51.56,0:49:58.40,EN,,0,0,0,,See, what we want to do is have some generic operators.
Dialogue: 0,0:49:59.34,0:50:02.80,EN,,0,0,0,,Right? Have add and sub and mul and div be generic operators.
Dialogue: 0,0:50:03.99,0:50:17.36,EN,,0,0,0,,So we're going to define add and say, to add x and y,
Dialogue: 0,0:50:18.62,0:50:22.12,EN,,0,0,0,,that will be operate--
Dialogue: 0,0:50:26.08,0:50:27.49,EN,,0,0,0,,we were going to call it operate-2.
Dialogue: 0,0:50:27.49,0:50:30.78,EN,,0,0,0,,This is our operator procedure, but set up for two arguments
Dialogue: 0,0:50:31.60,0:50:35.84,EN,,0,0,0,,using add on x and y.
Dialogue: 0,0:50:37.60,0:50:39.76,EN,,0,0,0,,And so this is the analog to operate.
Dialogue: 0,0:50:40.42,0:50:41.68,EN,,0,0,0,,Let's look at the code for a second.
Dialogue: 0,0:50:41.68,0:50:42.93,EN,,0,0,0,,It's almost like operate.
Dialogue: 0,0:50:45.79,0:50:52.49,EN,,0,0,0,,Right? To operate with some operator on an argument1 and an argument2
Dialogue: 0,0:50:55.04,0:50:56.65,EN,,0,0,0,,well the first thing we're going to do is check
Dialogue: 0,0:50:56.83,0:51:00.73,EN,,0,0,0,,and see if the two arguments have the same type.
Dialogue: 0,0:51:01.90,0:51:02.96,EN,,0,0,0,,So we'll say,
Dialogue: 0,0:51:02.99,0:51:07.77,EN,,0,0,0,,is the type of the first argument the same as the type of the second argument?
Dialogue: 0,0:51:10.35,0:51:13.36,EN,,0,0,0,,And if they're not, if they're not
Dialogue: 0,0:51:13.58,0:51:15.63,EN,,0,0,0,,we'll go off and complain, and say, that's an error.
Dialogue: 0,0:51:15.67,0:51:16.67,EN,,0,0,0,,We don't know how to do that.
Dialogue: 0,0:51:19.14,0:51:20.49,EN,,0,0,0,,If they do have the same type,
Dialogue: 0,0:51:20.51,0:51:22.08,EN,,0,0,0,,we'll do exactly what we did before.
Dialogue: 0,0:51:22.08,0:51:26.46,EN,,0,0,0,,We'll go look and filed under the type of the argument--
Dialogue: 0,0:51:26.76,0:51:29.61,EN,,0,0,0,,arg 1 and arg 2 have the same type, so it doesn't matter.
Dialogue: 0,0:51:30.42,0:51:32.59,EN,,0,0,0,,So we'll look in the table, find the procedure.
Dialogue: 0,0:51:33.64,0:51:35.87,EN,,0,0,0,,If there is a procedure there,
Dialogue: 0,0:51:37.53,0:51:41.74,EN,,0,0,0,,then we'll apply it to the contents of the arg1 and the contents of arg2.
Dialogue: 0,0:51:43.03,0:51:44.76,EN,,0,0,0,,And otherwise we'll say, error.
Dialogue: 0,0:51:44.76,0:51:45.72,EN,,0,0,0,,Undefined operator.
Dialogue: 0,0:51:46.89,0:51:48.16,EN,,0,0,0,,And so there's operate-2.
Dialogue: 0,0:51:51.72,0:51:54.03,EN,,0,0,0,,And that's all we have to do.
Dialogue: 0,0:51:55.16,0:51:57.45,EN,,0,0,0,,We just built the complex number package before.
Dialogue: 0,0:51:57.64,0:52:01.00,EN,,0,0,0,,How do we embed that complex number package in this generic system?
Dialogue: 0,0:52:02.14,0:52:02.91,EN,,0,0,0,,Almost the same.
Dialogue: 0,0:52:06.41,0:52:08.59,EN,,0,0,0,,We make a procedure called make-complex
Dialogue: 0,0:52:09.95,0:52:12.81,EN,,0,0,0,,that takes whatever George and Martha hand to us
Dialogue: 0,0:52:13.64,0:52:15.00,EN,,0,0,0,,and add the type complex.
Dialogue: 0,0:52:18.17,0:52:23.87,EN,,0,0,0,,And then we say, to add complex numbers, plus complex,
Dialogue: 0,0:52:25.84,0:52:28.78,EN,,0,0,0,,we use our internal procedure, plus c,
Dialogue: 0,0:52:30.78,0:52:32.24,EN,,0,0,0,,and attach a type,
Dialogue: 0,0:52:32.24,0:52:33.42,EN,,0,0,0,,make that a complex number.
Dialogue: 0,0:52:37.68,0:52:42.52,EN,,0,0,0,,So our original package had names plus c and minus c
Dialogue: 0,0:52:42.68,0:52:44.75,EN,,0,0,0,,that we're using to communicate with George and Martha.
Dialogue: 0,0:52:45.25,0:52:47.39,EN,,0,0,0,,And then to communicate with the outside world,
Dialogue: 0,0:52:47.40,0:52:53.04,EN,,0,0,0,,we have a thing called plus-complex and minus-complex.
Dialogue: 0,0:52:55.92,0:52:56.53,EN,,0,0,0,,And so on.
Dialogue: 0,0:52:56.53,0:52:59.98,EN,,0,0,0,,And the only difference is that these return values that are typed
Dialogue: 0,0:53:01.12,0:53:02.41,EN,,0,0,0,,So they can be looked at up here.
Dialogue: 0,0:53:02.85,0:53:05.02,EN,,0,0,0,,And these are internal operations.
Dialogue: 0,0:53:09.25,0:53:10.68,EN,,0,0,0,,Let's go look at that slide again.
Dialogue: 0,0:53:10.68,0:53:13.04,EN,,0,0,0,,There's one more thing we do.
Dialogue: 0,0:53:13.74,0:53:15.61,EN,,0,0,0,,After defining plus-complex,
Dialogue: 0,0:53:15.68,0:53:20.52,EN,,0,0,0,,we put under the type complex and the symbol add,
Dialogue: 0,0:53:21.31,0:53:22.75,EN,,0,0,0,,that procedure plus complex.
Dialogue: 0,0:53:23.20,0:53:26.75,EN,,0,0,0,,And then similarly for subtracting complex numbers,
Dialogue: 0,0:53:27.13,0:53:29.13,EN,,0,0,0,,and multiplying them, and dividing them.
Dialogue: 0,0:53:31.70,0:53:33.48,EN,,0,0,0,,OK, how do we install ordinary numbers?
Dialogue: 0,0:53:35.25,0:53:36.12,EN,,0,0,0,,Exactly the same way.
Dialogue: 0,0:53:38.16,0:53:41.36,EN,,0,0,0,,Come off and say, well we'll make a thing called make-number
Dialogue: 0,0:53:44.34,0:53:48.11,EN,,0,0,0,,Make-number takes a number and attaches a type,
Dialogue: 0,0:53:48.14,0:53:49.29,EN,,0,0,0,,which is the symbol number.
Dialogue: 0,0:53:50.26,0:53:52.11,EN,,0,0,0,,We build a procedure called plus-number,
Dialogue: 0,0:53:52.92,0:53:58.75,EN,,0,0,0,,which is simply, add the two things using the ordinary addition,
Dialogue: 0,0:53:58.92,0:54:00.78,EN,,0,0,0,,because in this case we're talking about ordinary numbers,
Dialogue: 0,0:54:01.31,0:54:03.10,EN,,0,0,0,,and attach a type to it and make that a number.
Dialogue: 0,0:54:04.51,0:54:08.09,EN,,0,0,0,,And then we put into the table under the symbol number
Dialogue: 0,0:54:08.59,0:54:11.00,EN,,0,0,0,,and the operation add, this procedure plus-number,
Dialogue: 0,0:54:12.30,0:54:16.16,EN,,0,0,0,,and then the same thing for subtracting, and multiplying, and dividing.
Dialogue: 0,0:54:22.67,0:54:26.06,EN,,0,0,0,,Let's look at an example, just to make it clear.
Dialogue: 0,0:54:26.06,0:54:28.75,EN,,0,0,0,,Suppose, for instance,
Dialogue: 0,0:54:32.28,0:54:34.15,EN,,0,0,0,,I'm going to perform the operation.
Dialogue: 0,0:54:34.15,0:54:38.22,EN,,0,0,0,,So I sit up here and I'm going to perform the operation,
Dialogue: 0,0:54:38.22,0:54:40.46,EN,,0,0,0,,which looks like multiplying two complex numbers.
Dialogue: 0,0:54:40.93,0:54:48.64,EN,,0,0,0,,So I would multiply, say, 3 plus 4i and 2 plus 6i.
Dialogue: 0,0:54:50.17,0:54:52.60,EN,,0,0,0,,And that's something that I might want to take hand that to mul.
Dialogue: 0,0:54:52.84,0:54:55.76,EN,,0,0,0,,I'll write mul as my generic operator here.
Dialogue: 0,0:54:57.17,0:54:57.98,EN,,0,0,0,,How's that going to work?
Dialogue: 0,0:54:58.28,0:55:04.60,EN,,0,0,0,,Well 3 plus 4i, say, sits in the system at this level
Dialogue: 0,0:55:04.83,0:55:06.11,EN,,0,0,0,,as something that looks like this.
Dialogue: 0,0:55:06.25,0:55:07.52,EN,,0,0,0,,Let's say it was one of George's.
Dialogue: 0,0:55:08.28,0:55:14.97,EN,,0,0,0,,So it would have a 3 and a 4.
Dialogue: 0,0:55:18.49,0:55:20.97,EN,,0,0,0,,And attached to that would be George's type,
Dialogue: 0,0:55:24.33,0:55:28.32,EN,,0,0,0,,which says rectangular, it came from George.
Dialogue: 0,0:55:29.51,0:55:30.57,EN,,0,0,0,,And attached to that--
Dialogue: 0,0:55:31.23,0:55:35.79,EN,,0,0,0,,and this itself would be the data view from the next level up
Dialogue: 0,0:55:36.19,0:55:36.78,EN,,0,0,0,,which it is--
Dialogue: 0,0:55:37.93,0:55:39.96,EN,,0,0,0,,so that itself would be a type-data object
Dialogue: 0,0:55:40.60,0:55:41.80,EN,,0,0,0,,which would say complex.
Dialogue: 0,0:55:44.82,0:55:47.31,EN,,0,0,0,,So that's what this object would look like
Dialogue: 0,0:55:48.64,0:55:50.24,EN,,0,0,0,,up here at the very highest level,
Dialogue: 0,0:55:50.68,0:55:53.56,EN,,0,0,0,,where the really super-generic operations are looking at it.
Dialogue: 0,0:55:55.56,0:55:58.72,EN,,0,0,0,,Now what happens, mul eventually's going to come along
Dialogue: 0,0:55:58.84,0:56:00.40,EN,,0,0,0,,and say, oh,what's it's type?
Dialogue: 0,0:56:00.48,0:56:01.48,EN,,0,0,0,,It's type is complex.
Dialogue: 0,0:56:04.27,0:56:06.46,EN,,0,0,0,,Go through to operate-2 and say,
Dialogue: 0,0:56:06.46,0:56:09.72,EN,,0,0,0,,oh, what I want to do is apply what's in the table,
Dialogue: 0,0:56:09.72,0:56:13.04,EN,,0,0,0,,which is going to be the procedure star complex,
Dialogue: 0,0:56:15.08,0:56:17.76,EN,,0,0,0,,on this thing with the type stripped off.
Dialogue: 0,0:56:17.95,0:56:19.28,EN,,0,0,0,,So it's going to strip off the type,
Dialogue: 0,0:56:19.93,0:56:24.24,EN,,0,0,0,,take that much, and send that down into the complex world.
Dialogue: 0,0:56:26.70,0:56:28.73,EN,,0,0,0,,The complex world looks at its operations and says,
Dialogue: 0,0:56:28.76,0:56:30.56,EN,,0,0,0,,oh, I have to apply star c.
Dialogue: 0,0:56:31.28,0:56:32.14,EN,,0,0,0,,Star c might say,
Dialogue: 0,0:56:32.22,0:56:37.20,EN,,0,0,0,,at some point I want to look at the magnitude of this object that it's in, that it's got.
Dialogue: 0,0:56:39.42,0:56:40.16,EN,,0,0,0,,And they'll say, oh, it's
Dialogue: 0,0:56:40.16,0:56:41.71,EN,,0,0,0,,rectangular, it's one of George's.
Dialogue: 0,0:56:41.87,0:56:44.41,EN,,0,0,0,,So it'll then strip off the next version of type,
Dialogue: 0,0:56:46.91,0:56:49.80,EN,,0,0,0,,and hand that down to George to take the magnitude of.
Dialogue: 0,0:56:52.16,0:56:53.13,EN,,0,0,0,,So you see what's going on
Dialogue: 0,0:56:53.44,0:56:56.99,EN,,0,0,0,,is that there are these chains of types.
Dialogue: 0,0:56:59.32,0:57:01.50,EN,,0,0,0,,And the length of the chain is sort of the number of levels
Dialogue: 0,0:57:01.53,0:57:03.13,EN,,0,0,0,,that you're going to be going up in this table.
Dialogue: 0,0:57:05.09,0:57:05.96,EN,,0,0,0,,And what a type tells you,
Dialogue: 0,0:57:05.96,0:57:10.84,EN,,0,0,0,,every time you have a vertical barrier in this table,
Dialogue: 0,0:57:11.05,0:57:14.06,EN,,0,0,0,,where there's some ambiguity about where you should go down to the next level,
Dialogue: 0,0:57:14.41,0:57:15.85,EN,,0,0,0,,the type is telling you where to go.
Dialogue: 0,0:57:17.44,0:57:18.83,EN,,0,0,0,,And then everybody at the bottom,
Dialogue: 0,0:57:18.97,0:57:20.67,EN,,0,0,0,,as they construct data and filter it up,
Dialogue: 0,0:57:21.12,0:57:22.81,EN,,0,0,0,,they stick their type back on.
Dialogue: 0,0:57:25.35,0:57:30.75,EN,,0,0,0,,So that's the general structure of the system.
Dialogue: 0,0:57:33.41,0:57:33.77,EN,,0,0,0,,OK.
Dialogue: 0,0:57:34.82,0:57:35.68,EN,,0,0,0,,Now that we've got this,
Dialogue: 0,0:57:37.56,0:57:39.44,EN,,0,0,0,,let's go and make this thing even more complex.
Dialogue: 0,0:57:41.89,0:57:46.54,EN,,0,0,0,,Let's talk about adding to the system not only these kinds of numbers
Dialogue: 0,0:57:46.60,0:57:51.15,EN,,0,0,0,,numbers, but it's also meaningful to start talking about adding polynomials.
Dialogue: 0,0:57:51.51,0:57:52.97,EN,,0,0,0,,Might do arithmetic on polynomials.
Dialogue: 0,0:57:53.36,0:58:03.71,EN,,0,0,0,,Like we could have x to the fifteenth plus 2x to the seventh plus 5.
Dialogue: 0,0:58:04.48,0:58:05.84,EN,,0,0,0,,That might be some polynomial.
Dialogue: 0,0:58:06.38,0:58:07.93,EN,,0,0,0,,And if we have two such gadgets
Dialogue: 0,0:58:07.93,0:58:09.48,EN,,0,0,0,,we can add them or multiply them.
Dialogue: 0,0:58:10.53,0:58:11.79,EN,,0,0,0,,Let's not worry about dividing them.
Dialogue: 0,0:58:12.14,0:58:14.67,EN,,0,0,0,,Just add them, multiply them, then we'll subtract them.
Dialogue: 0,0:58:15.55,0:58:17.16,EN,,0,0,0,,Auhhh...What do we have to do? Well
Dialogue: 0,0:58:18.52,0:58:20.76,EN,,0,0,0,,let's think about how we might represent a polynomial.
Dialogue: 0,0:58:21.83,0:58:23.55,EN,,0,0,0,,It's going to be some typed data object.
Dialogue: 0,0:58:24.73,0:58:27.55,EN,,0,0,0,,So let's say a polynomial to this system
Dialogue: 0,0:58:28.54,0:58:31.68,EN,,0,0,0,,might look like a thing that starts with the type polynomial.
Dialogue: 0,0:58:32.00,0:58:34.55,EN,,0,0,0,,And then maybe it says the next thing is what variable its in.
Dialogue: 0,0:58:34.55,0:58:37.69,EN,,0,0,0,,So I might say I'm a polynomial in the variable x.
Dialogue: 0,0:58:38.96,0:58:41.39,EN,,0,0,0,,And then it'll have some information about what the terms are.
Dialogue: 0,0:58:42.25,0:58:44.16,EN,,0,0,0,,And there're just tons of ways to do this,
Dialogue: 0,0:58:44.25,0:58:47.63,EN,,0,0,0,,but one way is to say we're going to have a thing called a term-list.
Dialogue: 0,0:58:51.52,0:58:52.24,EN,,0,0,0,,And a term-list--
Dialogue: 0,0:58:53.70,0:58:55.61,EN,,0,0,0,,well, in our case we'll use something that looks like this.
Dialogue: 0,0:58:56.36,0:58:59.68,EN,,0,0,0,,We'll make it a bunch of pairs which have an order in a coefficient
Dialogue: 0,0:58:59.69,0:59:05.80,EN,,0,0,0,,So this polynomial would be represented by this term-list.
Dialogue: 0,0:59:09.42,0:59:10.68,EN,,0,0,0,,And what that means is that
Dialogue: 0,0:59:11.48,0:59:19.71,EN,,0,0,0,,this polynomial starts off with a term of order 15 and coefficient 1.
Dialogue: 0,0:59:23.82,0:59:27.50,EN,,0,0,0,,And the next thing in it is a term of order 7 and coefficient 2,
Dialogue: 0,0:59:27.53,0:59:30.49,EN,,0,0,0,,a term of order 0, which is constant in coefficient 5
Dialogue: 0,0:59:31.45,0:59:34.16,EN,,0,0,0,,And there are lots and lots of ways,
Dialogue: 0,0:59:34.25,0:59:35.96,EN,,0,0,0,,and lots and lots of trade-offs
Dialogue: 0,0:59:36.01,0:59:39.10,EN,,0,0,0,,when you really think about making algebraic manipulation packages
Dialogue: 0,0:59:39.44,0:59:41.73,EN,,0,0,0,,that exactly how you should represent these things.
Dialogue: 0,0:59:42.01,0:59:43.68,EN,,0,0,0,,But this is a fairly standard one.
Dialogue: 0,0:59:44.18,0:59:45.55,EN,,0,0,0,,It's useful in a lot of contexts.
Dialogue: 0,0:59:47.77,0:59:50.99,EN,,0,0,0,,OK, well how do we implement our polynomial arithmetic?
Dialogue: 0,0:59:53.47,0:59:54.96,EN,,0,0,0,,Let's start out.
Dialogue: 0,0:59:57.95,1:00:00.28,EN,,0,0,0,,What we'll do to make a polynomial--
Dialogue: 0,1:00:00.76,1:00:04.12,EN,,0,0,0,,we'll first have a way to make polynomials.
Dialogue: 0,1:00:05.69,1:00:10.28,EN,,0,0,0,,We're going to make a polynomial out of variable like x and term-list.
Dialogue: 0,1:00:11.24,1:00:14.09,EN,,0,0,0,,And all that does is we'll package them together someway.
Dialogue: 0,1:00:14.30,1:00:19.40,EN,,0,0,0,,We'll put the variable together with the term list using cons
Dialogue: 0,1:00:19.82,1:00:21.74,EN,,0,0,0,,and then attached to that the type polynomial.
Dialogue: 0,1:00:26.27,1:00:27.77,EN,,0,0,0,,OK, how do we add two polynomials?
Dialogue: 0,1:00:29.28,1:00:31.85,EN,,0,0,0,,To add a polynomial, p1 and p2,
Dialogue: 0,1:00:32.68,1:00:35.18,EN,,0,0,0,,and then just for simplicity let's say we
Dialogue: 0,1:00:35.37,1:00:37.15,EN,,0,0,0,,we will only add things in the same variable.
Dialogue: 0,1:00:37.38,1:00:39.28,EN,,0,0,0,,So if they have the same variable,
Dialogue: 0,1:00:39.69,1:00:42.57,EN,,0,0,0,,and same variable here is going to be some selector we write,
Dialogue: 0,1:00:42.96,1:00:44.38,EN,,0,0,0,,whose details we don't care about.
Dialogue: 0,1:00:45.15,1:00:47.04,EN,,0,0,0,,If the two polynomials have the same variable,
Dialogue: 0,1:00:48.03,1:00:48.81,EN,,0,0,0,,then we'll do something.
Dialogue: 0,1:00:48.81,1:00:51.26,EN,,0,0,0,,If they don't have the same variable, we'll give an error,
Dialogue: 0,1:00:52.35,1:00:54.01,EN,,0,0,0,,polynomials not in the same variable.
Dialogue: 0,1:00:55.48,1:00:57.37,EN,,0,0,0,,And if they do have the same variable,
Dialogue: 0,1:00:57.60,1:00:59.18,EN,,0,0,0,,what we'll do is we'll make a polynomial
Dialogue: 0,1:00:59.80,1:01:01.85,EN,,0,0,0,,whose variable is whatever that variable is,
Dialogue: 0,1:01:03.15,1:01:06.56,EN,,0,0,0,,and whose term-list is something we'll call sum-terms.
Dialogue: 0,1:01:07.48,1:01:09.80,EN,,0,0,0,,Plus terms will add the two term lists.
Dialogue: 0,1:01:10.17,1:01:12.01,EN,,0,0,0,,So we'll add the two term lists to the polynomial.
Dialogue: 0,1:01:13.50,1:01:14.51,EN,,0,0,0,,That'll give us a term-list.
Dialogue: 0,1:01:15.00,1:01:20.01,EN,,0,0,0,,We'll add on, we'll say it's a polynomial in the variable with that term-list.
Dialogue: 0,1:01:20.68,1:01:21.79,EN,,0,0,0,,That's plus poly.
Dialogue: 0,1:01:22.55,1:01:27.00,EN,,0,0,0,,And then we're going to put in our table under the type polynomial
Dialogue: 0,1:01:28.24,1:01:30.14,EN,,0,0,0,,add them using plus poly.
Dialogue: 0,1:01:30.52,1:01:31.75,EN,,0,0,0,,And of course we really haven't done much.
Dialogue: 0,1:01:31.75,1:01:35.31,EN,,0,0,0,,What we've really done is pushed all the work onto this thing, +terms
Dialogue: 0,1:01:35.79,1:01:37.02,EN,,0,0,0,,which is supposed to add term-lists.
Dialogue: 0,1:01:37.74,1:01:39.16,EN,,0,0,0,,Let's look at that.
Dialogue: 0,1:01:39.18,1:01:48.03,EN,,0,0,0,,Here's an overview of how we might add two term-lists.
Dialogue: 0,1:01:48.90,1:01:51.74,EN,,0,0,0,,So L1 and L2 were going to be two term-lists.
Dialogue: 0,1:01:52.00,1:01:54.81,EN,,0,0,0,,And a term-list is a bunch of pairs, coefficient in order.
Dialogue: 0,1:01:55.70,1:01:56.95,EN,,0,0,0,,And it's a big case analysis.
Dialogue: 0,1:01:59.86,1:02:04.14,EN,,0,0,0,,And the first thing we'll check for and see if there are any terms
Dialogue: 0,1:02:05.39,1:02:07.55,EN,,0,0,0,,We're going to recursively work down these term-lists
Dialogue: 0,1:02:08.16,1:02:11.74,EN,,0,0,0,,so eventually we'll get to a place where either L1 or L2 might be empty.
Dialogue: 0,1:02:12.27,1:02:14.35,EN,,0,0,0,,And if either one is empty,
Dialogue: 0,1:02:14.52,1:02:15.85,EN,,0,0,0,,our answer will be the other one.
Dialogue: 0,1:02:15.85,1:02:19.55,EN,,0,0,0,,So if L1 is empty we'll return L2,
Dialogue: 0,1:02:19.63,1:02:21.71,EN,,0,0,0,,and if L2 is empty we'll return L1.
Dialogue: 0,1:02:23.26,1:02:25.76,EN,,0,0,0,,Otherwise there are sort of three interesting cases.
Dialogue: 0,1:02:27.22,1:02:27.98,EN,,0,0,0,,What we're going to do is
Dialogue: 0,1:02:29.08,1:02:31.05,EN,,0,0,0,,grab the first term in each of those lists,
Dialogue: 0,1:02:33.50,1:02:36.04,EN,,0,0,0,,Right? Called t1 and t2.
Dialogue: 0,1:02:37.66,1:02:39.05,EN,,0,0,0,,And we're going to look at three cases,
Dialogue: 0,1:02:39.60,1:02:45.68,EN,,0,0,0,,depending on whether the order of t1 is greater than the order of t2,
Dialogue: 0,1:02:47.23,1:02:50.59,EN,,0,0,0,,or less than t2, or the same.
Dialogue: 0,1:02:53.28,1:02:54.91,EN,,0,0,0,,Those are the three cases we're going to look at.
Dialogue: 0,1:02:54.91,1:02:55.84,EN,,0,0,0,,Let's look at this case.
Dialogue: 0,1:02:58.64,1:03:01.31,EN,,0,0,0,,If the order of t1 is greater than the order of t2,
Dialogue: 0,1:03:03.40,1:03:04.70,EN,,0,0,0,,then what that means is that
Dialogue: 0,1:03:06.06,1:03:09.96,EN,,0,0,0,,then what that means is that our answer is going to start with this term of the order of t1.
Dialogue: 0,1:03:11.56,1:03:13.80,EN,,0,0,0,,Because it won't combine with any lower order terms.
Dialogue: 0,1:03:14.17,1:03:16.19,EN,,0,0,0,,So what we do is add the lower order terms.
Dialogue: 0,1:03:16.76,1:03:18.25,EN,,0,0,0,,We recursively add
Dialogue: 0,1:03:19.71,1:03:25.07,EN,,0,0,0,,together all the terms in the rest of the term-list in L1 and L2.
Dialogue: 0,1:03:27.13,1:03:29.32,EN,,0,0,0,,That's going to be the lower order terms of the answer.
Dialogue: 0,1:03:30.12,1:03:32.48,EN,,0,0,0,,And then we're going to adjoin to that the highest order term.
Dialogue: 0,1:03:33.18,1:03:35.45,EN,,0,0,0,,And I'm using here a whole bunch of procedures I haven't defined
Dialogue: 0,1:03:35.47,1:03:37.55,EN,,0,0,0,,like a adjoin-term, and rest-terms,
Dialogue: 0,1:03:38.48,1:03:40.17,EN,,0,0,0,,and selectors that get order.
Dialogue: 0,1:03:41.15,1:03:42.78,EN,,0,0,0,,But you can imagine what those are.
Dialogue: 0,1:03:44.44,1:03:48.76,EN,,0,0,0,,Right? So if the first term-list has a higher order than the second
Dialogue: 0,1:03:48.78,1:03:51.08,EN,,0,0,0,,we recursively add all the lower terms
Dialogue: 0,1:03:51.28,1:03:53.42,EN,,0,0,0,,and then stick on that last term.
Dialogue: 0,1:03:55.54,1:03:56.75,EN,,0,0,0,,The other case, the same way.
Dialogue: 0,1:03:56.89,1:04:00.28,EN,,0,0,0,,If the first term has a smaller order,
Dialogue: 0,1:04:00.54,1:04:08.36,EN,,0,0,0,,well then we add we add the first term-list and the rest of the terms in the second one
Dialogue: 0,1:04:08.62,1:04:12.65,EN,,0,0,0,,and adjoin on this highest order term.
Dialogue: 0,1:04:14.57,1:04:15.96,EN,,0,0,0,,So so far nothing's much happened,
Dialogue: 0,1:04:15.96,1:04:19.40,EN,,0,0,0,,we've just sort of pushed this thing off into adding lower order terms.
Dialogue: 0,1:04:19.47,1:04:21.96,EN,,0,0,0,,The last case where you actually get to a coefficients
Dialogue: 0,1:04:22.57,1:04:25.18,EN,,0,0,0,,that you have to add, this will be the case where the orders are equal.
Dialogue: 0,1:04:27.24,1:04:30.99,EN,,0,0,0,,What we do is, well again recursively add the lower order terms.
Dialogue: 0,1:04:31.00,1:04:32.83,EN,,0,0,0,,But now we have to really combine something.
Dialogue: 0,1:04:33.46,1:04:36.35,EN,,0,0,0,,What we do is we make a term
Dialogue: 0,1:04:37.31,1:04:39.93,EN,,0,0,0,,whose order is the order of the term we're looking at.
Dialogue: 0,1:04:40.82,1:04:42.72,EN,,0,0,0,,By now t1 and t2 have the same order.
Dialogue: 0,1:04:44.32,1:04:44.99,EN,,0,0,0,,That's its order.
Dialogue: 0,1:04:45.09,1:04:52.33,EN,,0,0,0,,And its coefficient is gotten by adding the coefficient of t1 and the coefficient of t2.
Dialogue: 0,1:04:55.79,1:04:59.64,EN,,0,0,0,,There's... This is a big recursive working down of terms,
Dialogue: 0,1:04:59.68,1:05:03.61,EN,,0,0,0,,but really there's only one interesting symbol in this procedure,
Dialogue: 0,1:05:04.25,1:05:05.69,EN,,0,0,0,,only one interesting idea.
Dialogue: 0,1:05:05.90,1:05:08.50,EN,,0,0,0,,The interesting idea is this add.
Dialogue: 0,1:05:12.39,1:05:14.80,EN,,0,0,0,,And the reason that's interesting is because
Dialogue: 0,1:05:15.42,1:05:17.37,EN,,0,0,0,,something completely wonderful just happened.
Dialogue: 0,1:05:18.22,1:05:21.37,EN,,0,0,0,,We reduced adding polynomials,
Dialogue: 0,1:05:22.56,1:05:26.46,EN,,0,0,0,,not to sort of plus, but to the generic add.
Dialogue: 0,1:05:28.82,1:05:32.28,EN,,0,0,0,,In other words, by implementing it that way,
Dialogue: 0,1:05:32.89,1:05:34.68,EN,,0,0,0,,not only do we have our system
Dialogue: 0,1:05:35.92,1:05:41.66,EN,,0,0,0,,where we can have rational numbers, or complex numbers, or ordinary numbers,
Dialogue: 0,1:05:41.85,1:05:43.82,EN,,0,0,0,,we've just added on polynomials.
Dialogue: 0,1:05:48.52,1:05:51.13,EN,,0,0,0,,But the coefficients of the polynomials
Dialogue: 0,1:05:51.24,1:05:52.86,EN,,0,0,0,,can be anything that the system can add.
Dialogue: 0,1:05:53.59,1:05:56.73,EN,,0,0,0,,So these could be polynomials whose coefficient
Dialogue: 0,1:05:57.20,1:06:01.20,EN,,0,0,0,,are rational numbers or complex numbers,
Dialogue: 0,1:06:02.76,1:06:06.99,EN,,0,0,0,,which in turn could be either rectangular, or polar,
Dialogue: 0,1:06:09.12,1:06:11.39,EN,,0,0,0,,or ordinary numbers.
Dialogue: 0,1:06:18.97,1:06:21.21,EN,,0,0,0,,Rignt? So what I mean precisely is
Dialogue: 0,1:06:22.06,1:06:24.35,EN,,0,0,0,,our system right now automatically
Dialogue: 0,1:06:26.60,1:06:31.50,EN,,0,0,0,,can handle things like adding together polynomials that have this form
Dialogue: 0,1:06:31.53,1:06:39.69,EN,,0,0,0,,2/3 of x squared plus 5/17 x plus 11/4.
Dialogue: 0,1:06:40.94,1:06:43.48,EN,,0,0,0,,Or automatically handle polynomials that look like
Dialogue: 0,1:06:43.82,1:06:52.57,EN,,0,0,0,,3 plus 2i times x to the fifth plus 4 plus 7i, or something.
Dialogue: 0,1:06:53.88,1:06:56.21,EN,,0,0,0,,Right? You can automatically handle those things.
Dialogue: 0,1:06:56.21,1:06:57.07,EN,,0,0,0,,Why is that?
Dialogue: 0,1:06:57.82,1:07:01.50,EN,,0,0,0,,That's merely because, or profoundly because
Dialogue: 0,1:07:02.17,1:07:05.93,EN,,0,0,0,,we reduced adding polynomials to adding their coefficients.
Dialogue: 0,1:07:06.79,1:07:10.22,EN,,0,0,0,,And adding coefficients was done by the generic add operator
Dialogue: 0,1:07:11.08,1:07:12.94,EN,,0,0,0,,which said, I don't care what your types are
Dialogue: 0,1:07:12.96,1:07:14.08,EN,,0,0,0,,as long as I know how to add you.
Dialogue: 0,1:07:15.23,1:07:18.86,EN,,0,0,0,,So automatically for free we get the ability to handle that.
Dialogue: 0,1:07:20.65,1:07:22.04,EN,,0,0,0,,What's even better than that,
Dialogue: 0,1:07:24.51,1:07:26.52,EN,,0,0,0,,one of the things we did
Dialogue: 0,1:07:27.20,1:07:30.52,EN,,0,0,0,,we put into the table that the way you add polynomials
Dialogue: 0,1:07:31.28,1:07:32.52,EN,,0,0,0,,is using plus poly.
Dialogue: 0,1:07:34.66,1:07:38.65,EN,,0,0,0,,That means that polynomials themselves are things that can be added.
Dialogue: 0,1:07:39.42,1:07:42.11,EN,,0,0,0,,So for instance let me write one here.
Dialogue: 0,1:07:43.18,1:07:46.19,EN,,0,0,0,,Here is... Here's a polynomial.
Dialogue: 0,1:07:50.56,1:07:52.41,EN,,0,0,0,,So this gadget here I'm writing up,
Dialogue: 0,1:07:54.12,1:07:58.46,EN,,0,0,0,,this is a polynomial in y
Dialogue: 0,1:08:01.07,1:08:04.69,EN,,0,0,0,,whose coefficients are polynomials in x.
Dialogue: 0,1:08:08.61,1:08:11.12,EN,,0,0,0,,So you see, simply by saying,
Dialogue: 0,1:08:11.76,1:08:14.06,EN,,0,0,0,,polynomials are themselves things that can be added,
Dialogue: 0,1:08:14.41,1:08:17.90,EN,,0,0,0,,we can go off and say, well not only can we deal with rationals,
Dialogue: 0,1:08:18.27,1:08:20.33,EN,,0,0,0,,or complex, or ordinary numbers,
Dialogue: 0,1:08:20.35,1:08:21.77,EN,,0,0,0,,but we can deal with polynomials
Dialogue: 0,1:08:22.09,1:08:25.39,EN,,0,0,0,,whose coefficients are rationals, or complex, or ordinary numbers,
Dialogue: 0,1:08:25.50,1:08:27.52,EN,,0,0,0,,or polynomials
Dialogue: 0,1:08:29.15,1:08:30.96,EN,,0,0,0,,whose coefficients are rationals,
Dialogue: 0,1:08:31.69,1:08:36.76,EN,,0,0,0,,or complex, rectangular, polar, or ordinary numbers,
Dialogue: 0,1:08:36.94,1:08:41.13,EN,,0,0,0,,or ordinary numbers, or polynomials whose coefficients are rationals,
Dialogue: 0,1:08:41.80,1:08:43.32,EN,,0,0,0,,complex, or ordinary numbers.
Dialogue: 0,1:08:43.67,1:08:45.21,EN,,0,0,0,,And so on, and so on, and so on.
Dialogue: 0,1:08:45.95,1:08:47.55,EN,,0,0,0,,So this is sort of an infinite
Dialogue: 0,1:08:48.49,1:08:52.88,EN,,0,0,0,,or maybe a recursive tower of types that we've built up.
Dialogue: 0,1:08:53.88,1:08:57.12,EN,,0,0,0,,And it's all exactly from that one little symbol, A-D-D.
Dialogue: 0,1:08:57.61,1:09:00.49,EN,,0,0,0,,Writing "add" instead of "plus" in the polynomial thing.
Dialogue: 0,1:09:02.27,1:09:03.77,EN,,0,0,0,,Slightly different way to think about it
Dialogue: 0,1:09:03.95,1:09:07.74,EN,,0,0,0,,is that polynomials are a constructor for types.
Dialogue: 0,1:09:08.74,1:09:11.20,EN,,0,0,0,,Namely you give it a type, like integer,
Dialogue: 0,1:09:11.48,1:09:15.74,EN,,0,0,0,,and it returns for you polynomials in x whose coefficients are integers.
Dialogue: 0,1:09:16.27,1:09:17.72,EN,,0,0,0,,And the important thing about
Dialogue: 0,1:09:18.65,1:09:20.73,EN,,0,0,0,,is that is that the operations on polynomials
Dialogue: 0,1:09:21.28,1:09:23.37,EN,,0,0,0,,reduce to the operations on the coefficients.
Dialogue: 0,1:09:23.39,1:09:24.96,EN,,0,0,0,,And there are a lot of things like that.
Dialogue: 0,1:09:25.84,1:09:27.92,EN,,0,0,0,,So for example, let's go back and rational numbers.
Dialogue: 0,1:09:28.87,1:09:32.65,EN,,0,0,0,,We thought about rational numbers as an integer over an integer
Dialogue: 0,1:09:32.67,1:09:35.66,EN,,0,0,0,,but there's the general notion of a rational object.
Dialogue: 0,1:09:36.24,1:09:42.03,EN,,0,0,0,,Like we might think about 3x plus 7 over x squared plus 1.
Dialogue: 0,1:09:43.07,1:09:48.86,EN,,0,0,0,,That's general rational object whose numerator and denominator are polynomials.
Dialogue: 0,1:09:50.31,1:09:52.41,EN,,0,0,0,,And to add two of them we use the same formula,
Dialogue: 0,1:09:52.44,1:09:55.40,EN,,0,0,0,,numerator times denominator plus denominator times numerator
Dialogue: 0,1:09:55.72,1:09:56.99,EN,,0,0,0,,over product of denominators.
Dialogue: 0,1:09:57.29,1:09:59.37,EN,,0,0,0,,How could we install that in our system?
Dialogue: 0,1:09:59.39,1:10:02.97,EN,,0,0,0,,Well here's our original rational number arithmetic package.
Dialogue: 0,1:10:04.25,1:10:08.24,EN,,0,0,0,,And all we have to do in order to make the entire system
Dialogue: 0,1:10:08.28,1:10:11.58,EN,,0,0,0,,continue working with general rational objects,
Dialogue: 0,1:10:11.85,1:10:16.44,EN,,0,0,0,,is replace these particular pluses and stars by the generic operator.
Dialogue: 0,1:10:16.48,1:10:19.18,EN,,0,0,0,,So if we simply change that procedure to this one,
Dialogue: 0,1:10:19.71,1:10:22.04,EN,,0,0,0,,here we've changed plus and star to add a mul,
Dialogue: 0,1:10:22.88,1:10:24.48,EN,,0,0,0,,those are absolutely the only change,
Dialogue: 0,1:10:24.84,1:10:26.03,EN,,0,0,0,,then suddenly
Dialogue: 0,1:10:27.52,1:10:31.40,EN,,0,0,0,,our entire system can start talking about objects that look like this.
Dialogue: 0,1:10:33.72,1:10:38.27,EN,,0,0,0,,So for example, here is a rational object
Dialogue: 0,1:10:39.18,1:10:44.86,EN,,0,0,0,,whose numerator is a polynomial in x whose coefficients are rational numbers.
Dialogue: 0,1:10:47.02,1:10:49.56,EN,,0,0,0,,Or here is a rational object
Dialogue: 0,1:10:51.10,1:10:54.43,EN,,0,0,0,,whose numerator is polynomials in x
Dialogue: 0,1:10:55.15,1:10:58.19,EN,,0,0,0,,whose coefficients are rational objects
Dialogue: 0,1:10:59.77,1:11:01.53,EN,,0,0,0,,constructed out of complex numbers.
Dialogue: 0,1:11:03.39,1:11:04.85,EN,,0,0,0,,And then there are a lot of other things like that.
Dialogue: 0,1:11:04.85,1:11:08.68,EN,,0,0,0,,See, whenever you have a thing where the operations reduce to operations on the pieces,
Dialogue: 0,1:11:08.89,1:11:10.00,EN,,0,0,0,,another example would be
Dialogue: 0,1:11:10.28,1:11:11.42,EN,,0,0,0,,two by two matrices.
Dialogue: 0,1:11:12.31,1:11:15.44,EN,,0,0,0,,I have the idea, there might be a matrix here
Dialogue: 0,1:11:16.43,1:11:18.33,EN,,0,0,0,,of general things that I don't care about.
Dialogue: 0,1:11:18.72,1:11:20.14,EN,,0,0,0,,But if I add two of them,
Dialogue: 0,1:11:22.33,1:11:25.18,EN,,0,0,0,,the answer over here is gotten by
Dialogue: 0,1:11:25.18,1:11:28.14,EN,,0,0,0,,adding this one and that one,however they like to add.
Dialogue: 0,1:11:29.03,1:11:31.11,EN,,0,0,0,,So I can implement that the same way.
Dialogue: 0,1:11:31.11,1:11:31.71,EN,,0,0,0,,And if I do that,
Dialogue: 0,1:11:31.96,1:11:34.60,EN,,0,0,0,,then again suddenly my system can start handling things like this.
Dialogue: 0,1:11:35.29,1:11:39.18,EN,,0,0,0,,So here's a matrix whose elements happen to be--
Dialogue: 0,1:11:39.46,1:11:42.16,EN,,0,0,0,,we'll say this element here is a rational object
Dialogue: 0,1:11:43.10,1:11:45.15,EN,,0,0,0,,whose numerator and denominators are polynomials.
Dialogue: 0,1:11:47.02,1:11:49.56,EN,,0,0,0,,Right? And all that comes for free.
Dialogue: 0,1:11:51.28,1:11:53.82,EN,,0,0,0,,Right? What's really going on here?
Dialogue: 0,1:11:53.92,1:11:56.17,EN,,0,0,0,,What's really going on is
Dialogue: 0,1:11:57.68,1:12:02.44,EN,,0,0,0,,getting rid of who's sitting there poking his nose into who everybody's business is.
Dialogue: 0,1:12:03.12,1:12:06.19,EN,,0,0,0,,We built a system that has decentralized control.
Dialogue: 0,1:12:14.78,1:12:18.34,EN,,0,0,0,,So when you come into and no one's poking around saying,
Dialogue: 0,1:12:18.35,1:12:22.30,EN,,0,0,0,,gee, are you in the official list of people who can be added?
Dialogue: 0,1:12:22.44,1:12:26.22,EN,,0,0,0,,Rather you say, well go off and add yourself how your parts like to be added.
Dialogue: 0,1:12:27.81,1:12:31.03,EN,,0,0,0,,And the result of that is you can get this very, very, very
Dialogue: 0,1:12:31.03,1:12:33.87,EN,,0,0,0,,complex hierarchy where a lot of things just get done and
Dialogue: 0,1:12:33.87,1:12:35.55,EN,,0,0,0,,rooted to the right place automatically.
Dialogue: 0,1:12:37.00,1:12:37.79,EN,,0,0,0,,Let's stop for questions.
Dialogue: 0,1:12:40.38,1:12:42.32,EN,,0,0,0,,AUDIENCE: You say you get this for free.
Dialogue: 0,1:12:42.35,1:12:45.82,EN,,0,0,0,,Um..... One thing that strikes me is that now you've lost
Dialogue: 0,1:12:46.48,1:12:50.91,EN,,0,0,0,,kind of the cleanness of the break between what's on top and what's underneath.
Dialogue: 0,1:12:50.91,1:12:52.77,EN,,0,0,0,,In other words, now you're defining some of the
Dialogue: 0,1:12:52.77,1:12:56.08,EN,,0,0,0,,lower-level procedures in terms of things above their own line.
Dialogue: 0,1:12:56.61,1:12:59.45,EN,,0,0,0,,Isn't that dangerous?
Dialogue: 0,1:13:00.35,1:13:04.49,EN,,0,0,0,,Or, if nothing more, a little less structured?
Dialogue: 0,1:13:05.44,1:13:05.95,EN,,0,0,0,,PROFESSOR: No, I--
Dialogue: 0,1:13:06.41,1:13:07.77,EN,,0,0,0,,the question is whether that's less structured.
Dialogue: 0,1:13:07.77,1:13:08.69,EN,,0,0,0,,Depends on what you mean by structure.
Dialogue: 0,1:13:08.69,1:13:10.17,EN,,0,0,0,,All this is doing is recursion.
Dialogue: 0,1:13:11.05,1:13:18.80,EN,,0,0,0,,See, it's saying that the way you add these guys is to use that.
Dialogue: 0,1:13:19.15,1:13:21.37,EN,,0,0,0,,And that's not less structured, it's just a recursive structure.
Dialogue: 0,1:13:22.70,1:13:24.99,EN,,0,0,0,,So I don't think it's particularly any less clean.
Dialogue: 0,1:13:24.99,1:13:28.16,EN,,0,0,0,,AUDIENCE: Now when you want to change the multiplier or the add operator
Dialogue: 0,1:13:29.34,1:13:31.38,EN,,0,0,0,,suddenly you've got tremendous consequences
Dialogue: 0,1:13:31.38,1:13:34.27,EN,,0,0,0,,underneath that you're not even sure the extent of.
Dialogue: 0,1:13:34.48,1:13:36.44,EN,,0,0,0,,PROFESSOR: That's right, but it depends what you mean.
Dialogue: 0,1:13:37.08,1:13:38.47,EN,,0,0,0,,See, this goes both ways.
Dialogue: 0,1:13:39.10,1:13:43.24,EN,,0,0,0,,Um....What would be a good example?
Dialogue: 0,1:13:44.69,1:13:47.50,EN,,0,0,0,,I ignored greatest common divisor, for instance.
Dialogue: 0,1:13:47.77,1:13:50.08,EN,,0,0,0,,I ignored that problem just to keep the example simple.
Dialogue: 0,1:13:50.28,1:13:56.92,EN,,0,0,0,,But if I suddenly decided that plus rat here
Dialogue: 0,1:13:57.82,1:14:01.69,EN,,0,0,0,,should do a GCD computation and install that,
Dialogue: 0,1:14:03.34,1:14:07.87,EN,,0,0,0,,then that immediately becomes available to all of these, to that guy, and that guy,
Dialogue: 0,1:14:08.03,1:14:10.08,EN,,0,0,0,,and that guy, and all the way down.
Dialogue: 0,1:14:11.56,1:14:13.89,EN,,0,0,0,,So it depends what you mean by the coherence of your system.
Dialogue: 0,1:14:13.89,1:14:17.03,EN,,0,0,0,,It's certainly true that you might want to have a special
Dialogue: 0,1:14:17.03,1:14:19.56,EN,,0,0,0,,different one that didn't filter down through the coefficients
Dialogue: 0,1:14:19.61,1:14:22.97,EN,,0,0,0,,but the nice thing about this particular example is that mostly you do.
Dialogue: 0,1:14:25.44,1:14:27.63,EN,,0,0,0,,AUDIENCE: Isn't that the problem, I think, that you're
Dialogue: 0,1:14:27.63,1:14:32.95,EN,,0,0,0,,getting to tied in with the fact that the structuring, the
Dialogue: 0,1:14:32.95,1:14:36.33,EN,,0,0,0,,recursiveness of that structuring there is actually
Dialogue: 0,1:14:36.33,1:14:40.34,EN,,0,0,0,,in execution as opposed to just definition of the actual
Dialogue: 0,1:14:40.34,1:14:41.16,EN,,0,0,0,,types themselves?
Dialogue: 0,1:14:44.68,1:14:46.12,EN,,0,0,0,,PROFESSOR: I think I understand the question.
Dialogue: 0,1:14:46.12,1:14:47.80,EN,,0,0,0,,The point is that these types evolve
Dialogue: 0,1:14:47.82,1:14:50.40,EN,,0,0,0,,and get more and more complex as the thing's actually running.
Dialogue: 0,1:14:50.40,1:14:50.73,EN,,0,0,0,,Is that what--
Dialogue: 0,1:14:50.73,1:14:50.99,EN,,0,0,0,,AUDIENCE: Yap.
Dialogue: 0,1:14:50.99,1:14:51.79,EN,,0,0,0,,As it's running.
Dialogue: 0,1:14:52.09,1:14:54.18,EN,,0,0,0,,AUDIENCE: As opposed to the basic definitions.
Dialogue: 0,1:14:54.18,1:14:54.83,EN,,0,0,0,,PROFESSOR: Right. There's...
Dialogue: 0,1:14:54.83,1:14:56.70,EN,,0,0,0,,The type structure is sort of recursive.
Dialogue: 0,1:14:57.21,1:15:00.22,EN,,0,0,0,,It's not that you can make this finite list of the
Dialogue: 0,1:15:01.58,1:15:04.85,EN,,0,0,0,,actual things they might look like before the system runs.
Dialogue: 0,1:15:04.85,1:15:05.79,EN,,0,0,0,,It's something that evolves.
Dialogue: 0,1:15:06.78,1:15:08.64,EN,,0,0,0,,So if you want to specify that system,
Dialogue: 0,1:15:08.67,1:15:10.96,EN,,0,0,0,,you have to do in some other way than by this finite list.
Dialogue: 0,1:15:11.00,1:15:13.18,EN,,0,0,0,,You have to do it by a recursive structure.
Dialogue: 0,1:15:13.67,1:15:17.90,EN,,0,0,0,,AUDIENCE: Because the basic structure of the types is pretty clean and simple.
Dialogue: 0,1:15:17.90,1:15:18.19,EN,,0,0,0,,PROFESSOR: Right.
Dialogue: 0,1:15:20.40,1:15:20.75,EN,,0,0,0,,Yes?
Dialogue: 0,1:15:21.46,1:15:22.87,EN,,0,0,0,,AUDIENCE: I have a question.
Dialogue: 0,1:15:22.87,1:15:25.68,EN,,0,0,0,,I understand once you have your data structure set up,
Dialogue: 0,1:15:25.71,1:15:28.73,EN,,0,0,0,,how it pulls off complex and passes that down,
Dialogue: 0,1:15:28.73,1:15:30.64,EN,,0,0,0,,and then pulls off rect, passes that down.
Dialogue: 0,1:15:30.64,1:15:33.95,EN,,0,0,0,,But if you're just a user and you don't know anything about rect or polar or whatever,
Dialogue: 0,1:15:34.25,1:15:36.04,EN,,0,0,0,,how do you initially set up that data structure
Dialogue: 0,1:15:36.09,1:15:38.08,EN,,0,0,0,,so that everything goes to the right spot?
Dialogue: 0,1:15:38.09,1:15:41.00,EN,,0,0,0,,If I just have the equation over there on the left
Dialogue: 0,1:15:41.02,1:15:42.50,EN,,0,0,0,,And I just want to add, multiply complex numbers--
Dialogue: 0,1:15:42.50,1:15:43.64,EN,,0,0,0,,PROFESSOR: Well that's the wonderful thing.
Dialogue: 0,1:15:43.64,1:15:45.26,EN,,0,0,0,,If you're just a user you say "mul."
Dialogue: 0,1:15:47.73,1:15:49.95,EN,,0,0,0,,AUDIENCE: And it figures out that I mean complex numbers?
Dialogue: 0,1:15:49.96,1:15:51.23,EN,,0,0,0,,Or how do I tell it that I want--
Dialogue: 0,1:15:51.26,1:15:53.05,EN,,0,0,0,,PROFESSOR: Well you're going to have in your hands complex numbers.
Dialogue: 0,1:15:53.05,1:15:56.30,EN,,0,0,0,,See what you would have at some level, as a real user,
Dialogue: 0,1:15:56.32,1:15:58.14,EN,,0,0,0,,is a constructor for complex numbers.
Dialogue: 0,1:15:58.37,1:15:59.55,EN,,0,0,0,,AUDIENCE: So then I have to make complex numbers?
Dialogue: 0,1:15:59.56,1:16:00.35,EN,,0,0,0,,PROFESSOR: So you have to make them.
Dialogue: 0,1:16:00.35,1:16:04.01,EN,,0,0,0,,What you would probably have as a user is some little thing in the reader loop,
Dialogue: 0,1:16:04.65,1:16:07.56,EN,,0,0,0,,which would give you some plausible way
Dialogue: 0,1:16:07.56,1:16:08.86,EN,,0,0,0,,to type in a complex number,
Dialogue: 0,1:16:09.31,1:16:11.00,EN,,0,0,0,,in however whatever format you like.
Dialogue: 0,1:16:11.59,1:16:14.36,EN,,0,0,0,,Or it might be that you're never typing them in.
Dialogue: 0,1:16:14.36,1:16:16.17,EN,,0,0,0,,Someone's just handing you a complex number.
Dialogue: 0,1:16:16.78,1:16:19.82,EN,,0,0,0,,AUDIENCE: OK, so if I had a complex number that had a polynomial in it,
Dialogue: 0,1:16:19.82,1:16:21.96,EN,,0,0,0,,I'd have to make my polynomial and then make my complex number.
Dialogue: 0,1:16:21.96,1:16:23.96,EN,,0,0,0,,PROFESSOR: Right if you wanted it constructed from scratch.
Dialogue: 0,1:16:24.28,1:16:25.71,EN,,0,0,0,,At some point you construct them from scratch.
Dialogue: 0,1:16:25.71,1:16:27.05,EN,,0,0,0,,But what you don't have to know of that
Dialogue: 0,1:16:27.28,1:16:30.32,EN,,0,0,0,,is when you have the object you can just say "mul." And it'll multiply.
Dialogue: 0,1:16:32.78,1:16:32.99,EN,,0,0,0,,Yeah?
Dialogue: 0,1:16:33.27,1:16:35.76,EN,,0,0,0,,AUDIENCE: I think the question that was being posed here is,
Dialogue: 0,1:16:36.45,1:16:40.01,EN,,0,0,0,,say if I want to change my presentation of complexes,
Dialogue: 0,1:16:40.03,1:16:41.44,EN,,0,0,0,,or some operation of complex,
Dialogue: 0,1:16:41.52,1:16:47.10,EN,,0,0,0,,how much real code I will have to gets around with,
Dialogue: 0,1:16:47.15,1:16:51.26,EN,,0,0,0,,or change to change it in one specific operation?
Dialogue: 0,1:16:52.27,1:16:53.49,EN,,0,0,0,,PROFESSOR: [UNINTELLIGIBLE] what you have to change.
Dialogue: 0,1:16:53.49,1:16:54.99,EN,,0,0,0,,And the point is that you only have to change
Dialogue: 0,1:16:55.39,1:16:56.07,EN,,0,0,0,,what you're changing.
Dialogue: 0,1:16:56.07,1:17:00.04,EN,,0,0,0,,See if Martha decides that she would rather--
Dialogue: 0,1:17:00.32,1:17:01.23,EN,,0,0,0,,let's see something silly--
Dialogue: 0,1:17:01.44,1:17:02.91,EN,,0,0,0,,like change the order in the pair.
Dialogue: 0,1:17:04.04,1:17:08.72,EN,,0,0,0,,Like angle and magnitude in the other order,
Dialogue: 0,1:17:09.39,1:17:10.80,EN,,0,0,0,,she just makes that change locally.
Dialogue: 0,1:17:10.97,1:17:13.29,EN,,0,0,0,,And the whole thing will propagate through the system in the right way.
Dialogue: 0,1:17:14.79,1:17:18.76,EN,,0,0,0,,Or if suddenly you said, gee, I have another representation for rationals.
Dialogue: 0,1:17:19.70,1:17:23.90,EN,,0,0,0,,And I'm going to stick it here, by filing those operations in the table.
Dialogue: 0,1:17:24.82,1:17:27.22,EN,,0,0,0,,Then suddenly all of these polynomials whose coefficients
Dialogue: 0,1:17:27.22,1:17:29.10,EN,,0,0,0,,are coefficients of coefficients, or whatever,
Dialogue: 0,1:17:29.24,1:17:32.40,EN,,0,0,0,,also can automatically have available that representation.
Dialogue: 0,1:17:32.70,1:17:34.67,EN,,0,0,0,,That's the power of this particular one.
Dialogue: 0,1:17:36.11,1:17:38.70,EN,,0,0,0,,AUDIENCE: I'm not sure if I can even pose an intelligent sounding question.
Dialogue: 0,1:17:38.70,1:17:42.38,EN,,0,0,0,,But somehow this whole thing went really nicely
Dialogue: 0,1:17:42.54,1:17:45.88,EN,,0,0,0,,to this beautiful finish where all the things seemed to fall into place.
Dialogue: 0,1:17:46.72,1:17:48.67,EN,,0,0,0,,And sort of seemed a little contrived.
Dialogue: 0,1:17:50.93,1:17:52.52,EN,,0,0,0,,That's all for the sake, I'm sure, of teaching.
Dialogue: 0,1:17:52.56,1:17:54.65,EN,,0,0,0,,I doubt that the guys who first did this--
Dialogue: 0,1:17:55.10,1:17:55.85,EN,,0,0,0,,and I could be wrong--
Dialogue: 0,1:17:56.60,1:17:59.72,EN,,0,0,0,,figured it all out so that when they just all put it all together,
Dialogue: 0,1:17:59.77,1:18:03.93,EN,,0,0,0,,you could all of the sudden, blam, do any kind of arithmetic on any kind of object.
Dialogue: 0,1:18:04.86,1:18:07.20,EN,,0,0,0,,It seems like maybe they had to play with it for a while
Dialogue: 0,1:18:07.93,1:18:10.62,EN,,0,0,0,,and had to bash it and rework it.
Dialogue: 0,1:18:11.80,1:18:14.12,EN,,0,0,0,,And it seems like that's the kind of problem we're really
Dialogue: 0,1:18:14.12,1:18:16.94,EN,,0,0,0,,faced with we start trying to design a really complex system
Dialogue: 0,1:18:17.31,1:18:20.35,EN,,0,0,0,,is having lots of different kinds of parts and not even knowing
Dialogue: 0,1:18:21.08,1:18:24.62,EN,,0,0,0,,what kinds of operations we're going to want to do on those parts.
Dialogue: 0,1:18:24.62,1:18:26.54,EN,,0,0,0,,How to organize the operations in this nice way
Dialogue: 0,1:18:26.56,1:18:29.63,EN,,0,0,0,,so that no matter what you do, when you start putting them together
Dialogue: 0,1:18:29.63,1:18:31.39,EN,,0,0,0,,everything starts falling out for free.
Dialogue: 0,1:18:31.70,1:18:34.34,EN,,0,0,0,,PROFESSOR: OK, well that's certainly a very intelligent question... Um
Dialogue: 0,1:18:35.10,1:18:39.52,EN,,0,0,0,,Um....One part is this is a very good methodology
Dialogue: 0,1:18:39.87,1:18:43.88,EN,,0,0,0,,that people have discovered a lot coming from symbolic algebra.
Dialogue: 0,1:18:44.59,1:18:45.90,EN,,0,0,0,,Because there are a lot of complications.
Dialogue: 0,1:18:47.59,1:18:50.71,EN,,0,0,0,,To allow you to implement these things before you decide
Dialogue: 0,1:18:50.71,1:18:52.89,EN,,0,0,0,,what you want all the operations to be, and all of that.
Dialogue: 0,1:18:53.31,1:18:57.72,EN,,0,0,0,,So in some sense it's an answer that people have discovered by wading through this stuff.
Dialogue: 0,1:18:58.56,1:19:00.75,EN,,0,0,0,,In another sense, it is a very contrived example.
Dialogue: 0,1:19:02.16,1:19:06.24,EN,,0,0,0,,AUDIENCE: It seems like to be able to do this you do have to
Dialogue: 0,1:19:06.24,1:19:09.01,EN,,0,0,0,,wade through it for a certain amount of time before you can become good at it.
Dialogue: 0,1:19:09.01,1:19:11.88,EN,,0,0,0,,PROFESSOR: Let me show you how terribly contrived this is.
Dialogue: 0,1:19:12.22,1:19:14.13,EN,,0,0,0,,So you can write all these wonderful things.
Dialogue: 0,1:19:14.13,1:19:16.25,EN,,0,0,0,,But the system that I wrote here,
Dialogue: 0,1:19:17.02,1:19:18.96,EN,,0,0,0,,and if we had another half an hour to give this lecture
Dialogue: 0,1:19:19.31,1:19:20.46,EN,,0,0,0,,I would have given this part of it,
Dialogue: 0,1:19:20.81,1:19:23.02,EN,,0,0,0,,which says, notice that it breaks down
Dialogue: 0,1:19:23.20,1:19:29.31,EN,,0,0,0,,if I tell it to do something as foolish as add 3 plus 7/2.
Dialogue: 0,1:19:30.88,1:19:33.42,EN,,0,0,0,,Because what will happen is you'll get to operate-2,
Dialogue: 0,1:19:33.80,1:19:35.95,EN,,0,0,0,,and operate-2 will say, oh this is type number,
Dialogue: 0,1:19:36.18,1:19:37.37,EN,,0,0,0,,and that's type rational.
Dialogue: 0,1:19:37.56,1:19:38.81,EN,,0,0,0,,I don't know how to add them.
Dialogue: 0,1:19:41.53,1:19:44.30,EN,,0,0,0,,So you'd like the system at least to be able to say something like,
Dialogue: 0,1:19:45.88,1:19:47.34,EN,,0,0,0,,gee,before you do that
Dialogue: 0,1:19:48.59,1:19:50.24,EN,,0,0,0,,change that to 3/1.
Dialogue: 0,1:19:50.48,1:19:53.21,EN,,0,0,0,,Turn it into a rational number, hand that to the rational package.
Dialogue: 0,1:19:54.86,1:19:58.70,EN,,0,0,0,,That's the thing I didn't talk about in this lecture.
Dialogue: 0,1:19:58.73,1:20:00.88,EN,,0,0,0,,It's a little bit in the book,which talks about the problem
Dialogue: 0,1:20:00.88,1:20:01.95,EN,,0,0,0,,of what's called coercion.
Dialogue: 0,1:20:03.39,1:20:05.15,EN,,0,0,0,,Where you wanted--
Dialogue: 0,1:20:05.31,1:20:08.89,EN,,0,0,0,,see, having so carefully set up all of these types as distinct objects
Dialogue: 0,1:20:08.91,1:20:12.17,EN,,0,0,0,,a lot of times you want to also put in knowledge
Dialogue: 0,1:20:12.40,1:20:17.98,EN,,0,0,0,,about how to view an ordinary number as a kind of rational.
Dialogue: 0,1:20:19.11,1:20:21.29,EN,,0,0,0,,Or view an ordinary number as a kind of complex.
Dialogue: 0,1:20:21.62,1:20:25.16,EN,,0,0,0,,That's where the complexity in the system really starts happening
Dialogue: 0,1:20:25.76,1:20:28.12,EN,,0,0,0,,where you talk about, see where do I put that knowledge?
Dialogue: 0,1:20:28.42,1:20:32.19,EN,,0,0,0,,Is it rational to know that ordinary numbers might be pieces of cons of them?
Dialogue: 0,1:20:33.13,1:20:36.38,EN,,0,0,0,,Or they're terrible, terrible examples, like
Dialogue: 0,1:20:38.14,1:20:47.48,EN,,0,0,0,,if I might want to add a complex number to a rational number.
Dialogue: 0,1:20:49.87,1:20:50.76,EN,,0,0,0,,Bad example.
Dialogue: 0,1:20:50.76,1:20:51.58,EN,,0,0,0,,5/7.
Dialogue: 0,1:20:53.86,1:20:55.72,EN,,0,0,0,,Then somebody's got to know that
Dialogue: 0,1:20:56.06,1:20:58.16,EN,,0,0,0,,I have to convert these to another type,
Dialogue: 0,1:20:58.20,1:21:00.65,EN,,0,0,0,,which is complex numbers whose parts might be rationals.
Dialogue: 0,1:21:01.54,1:21:02.68,EN,,0,0,0,,And who worries about that?
Dialogue: 0,1:21:02.68,1:21:03.95,EN,,0,0,0,,Does complex worry about that?
Dialogue: 0,1:21:03.95,1:21:05.03,EN,,0,0,0,,Does rational worry about that?
Dialogue: 0,1:21:05.24,1:21:06.22,EN,,0,0,0,,Does plus worry about that?
Dialogue: 0,1:21:06.90,1:21:08.52,EN,,0,0,0,,That's where the real complexity comes in.
Dialogue: 0,1:21:08.52,1:21:11.38,EN,,0,0,0,,And that's where it's pretty well sorted out.
Dialogue: 0,1:21:11.38,1:21:14.12,EN,,0,0,0,,And a lot of, in fact, all of this message passing stuff
Dialogue: 0,1:21:14.64,1:21:16.54,EN,,0,0,0,,was motivated by problems like this.
Dialogue: 0,1:21:18.46,1:21:20.89,EN,,0,0,0,,And when you really push it, people are--
Dialogue: 0,1:21:20.91,1:21:24.76,EN,,0,0,0,,somehow the algebraic manipulation problem seems to be so complex
Dialogue: 0,1:21:25.18,1:21:27.41,EN,,0,0,0,,that the people who are always at the edge of it are exactly in
Dialogue: 0,1:21:27.41,1:21:28.05,EN,,0,0,0,,the state you said.
Dialogue: 0,1:21:28.05,1:21:29.71,EN,,0,0,0,,They're wading through this thing, mucking around,
Dialogue: 0,1:21:29.72,1:21:31.37,EN,,0,0,0,,seeing what they use, trying to distill stuff.
Dialogue: 0,1:21:34.20,1:21:37.76,EN,,0,0,0,,AUDIENCE: I just want to come back to this issue of complexity once more.
Dialogue: 0,1:21:38.41,1:21:44.55,EN,,0,0,0,,Um... It certainly seems to be true that you have a great deal of
Dialogue: 0,1:21:44.55,1:21:48.32,EN,,0,0,0,,flexibility in altering the lower level kinds of things.
Dialogue: 0,1:21:49.71,1:21:53.40,EN,,0,0,0,,But it is true that you are, in a sense,
Dialogue: 0,1:21:53.44,1:21:55.26,EN,,0,0,0,,freezing higher level operations.
Dialogue: 0,1:21:55.45,1:21:58.51,EN,,0,0,0,,Or at least if you change them you don't know where all of
Dialogue: 0,1:21:58.51,1:22:02.06,EN,,0,0,0,,the changes are going to show up, or how they are.
Dialogue: 0,1:22:02.20,1:22:04.22,EN,,0,0,0,,PROFESSOR: OK, that's an extremely good question.
Dialogue: 0,1:22:04.68,1:22:05.87,EN,,0,0,0,,What I have to do is,
Dialogue: 0,1:22:08.68,1:22:10.84,EN,,0,0,0,,if I decide there's a new general operation
Dialogue: 0,1:22:11.45,1:22:13.07,EN,,0,0,0,,called equality test,
Dialogue: 0,1:22:14.96,1:22:17.15,EN,,0,0,0,,then all of these people have to decide
Dialogue: 0,1:22:18.22,1:22:22.54,EN,,0,0,0,,whether or not they would like to have an equality test by looking in the table.
Dialogue: 0,1:22:24.65,1:22:26.84,EN,,0,0,0,,There're ways to decentralize it even more.
Dialogue: 0,1:22:27.87,1:22:30.70,EN,,0,0,0,,That's what I sort of hinted at last time, where I said
Dialogue: 0,1:22:31.08,1:22:33.26,EN,,0,0,0,,you could not only have this type as a symbol,
Dialogue: 0,1:22:33.40,1:22:38.70,EN,,0,0,0,,but you actually might store in each object the operations that it knows of that.
Dialogue: 0,1:22:40.45,1:22:43.90,EN,,0,0,0,,So you might have things like greatest common divisor,
Dialogue: 0,1:22:44.43,1:22:46.81,EN,,0,0,0,,which is a thing here which is defined only for integers,
Dialogue: 0,1:22:47.40,1:22:49.21,EN,,0,0,0,,and not in general for rational numbers.
Dialogue: 0,1:22:51.03,1:22:53.11,EN,,0,0,0,,So it might be a very, very fragmented system.
Dialogue: 0,1:22:53.11,1:22:55.66,EN,,0,0,0,,And then depending on where you want your flexibility,
Dialogue: 0,1:22:56.22,1:22:59.02,EN,,0,0,0,,You...there's a whole spectrum of places that you can build that in.
Dialogue: 0,1:22:59.96,1:23:02.56,EN,,0,0,0,,But you're pointing at the place where this starts being weak,
Dialogue: 0,1:23:02.60,1:23:06.37,EN,,0,0,0,,that there has to be some agreement on top here about these general operations.
Dialogue: 0,1:23:06.37,1:23:07.82,EN,,0,0,0,,Or at least people have to think about them.
Dialogue: 0,1:23:08.39,1:23:10.72,EN,,0,0,0,,Or you might decide, you might have a table that's very sparse
Dialogue: 0,1:23:10.75,1:23:11.96,EN,,0,0,0,,that only has a few things in it.
Dialogue: 0,1:23:14.01,1:23:15.49,EN,,0,0,0,,But there are lot of ways to play that game.
Dialogue: 0,1:23:19.78,1:23:20.43,EN,,0,0,0,,OK, thank you.
Dialogue: 0,1:23:23.53,1:23:36.56,Declare,,0,0,0,,{\fad(500,500)}MIT OpenCourseWare\Nhttp://ocw.mit.edu
Dialogue: 0,1:23:23.53,1:23:36.56,Declare,,0,0,0,,{\an2\fad(500,500)}https://github.com/DeathKing/Learning-SICP
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Ruby
1
https://gitee.com/jacklisp/Learning-SICP.git
git@gitee.com:jacklisp/Learning-SICP.git
jacklisp
Learning-SICP
Learning-SICP
master

搜索帮助