1 00:00:00,000 --> 00:00:03,880 2 00:00:03,880 --> 00:00:14,550 [MUSIC PLAYING] 3 00:00:14,550 --> 00:00:15,790 PROFESSOR: I'd like to welcome you to this 4 00:00:15,790 --> 00:00:17,270 course on computer science. 5 00:00:17,270 --> 00:00:28,370 6 00:00:28,370 --> 00:00:29,990 Actually, that's a terrible way to start. 7 00:00:29,990 --> 00:00:32,740 Computer science is a terrible name for this business. 8 00:00:32,740 --> 00:00:35,572 First of all, it's not a science. 9 00:00:35,572 --> 00:00:40,300 It might be engineering or it might be art, but we'll 10 00:00:40,300 --> 00:00:43,470 actually see that computer so-called science actually has 11 00:00:43,470 --> 00:00:45,350 a lot in common with magic, and we'll see 12 00:00:45,350 --> 00:00:47,210 that in this course. 13 00:00:47,210 --> 00:00:48,040 So it's not a science. 14 00:00:48,040 --> 00:00:53,340 It's also not really very much about computers. 15 00:00:53,340 --> 00:00:57,140 And it's not about computers in the same sense that physics 16 00:00:57,140 --> 00:01:02,920 is not really about particle accelerators, and biology is 17 00:01:02,920 --> 00:01:06,350 not really about microscopes and petri dishes. 18 00:01:06,350 --> 00:01:10,400 And it's not about computers in the same sense that 19 00:01:10,400 --> 00:01:16,480 geometry is not really about using surveying instruments. 20 00:01:16,480 --> 00:01:20,320 In fact, there's a lot of commonality between computer 21 00:01:20,320 --> 00:01:21,240 science and geometry. 22 00:01:21,240 --> 00:01:23,830 Geometry, first of all, is another subject 23 00:01:23,830 --> 00:01:25,680 with a lousy name. 24 00:01:25,680 --> 00:01:28,130 The name comes from Gaia, meaning the Earth, and metron, 25 00:01:28,130 --> 00:01:29,770 meaning to measure. 26 00:01:29,770 --> 00:01:31,350 Geometry originally meant measuring 27 00:01:31,350 --> 00:01:34,260 the Earth or surveying. 28 00:01:34,260 --> 00:01:37,260 And the reason for that was that, thousands of years ago, 29 00:01:37,260 --> 00:01:40,930 the Egyptian priesthood developed the rudiments of 30 00:01:40,930 --> 00:01:45,320 geometry in order to figure out how to restore the 31 00:01:45,320 --> 00:01:47,430 boundaries of fields that were destroyed in the annual 32 00:01:47,430 --> 00:01:49,390 flooding of the Nile. 33 00:01:49,390 --> 00:01:52,360 And to the Egyptians who did that, geometry really was the 34 00:01:52,360 --> 00:01:55,600 use of surveying instruments. 35 00:01:55,600 --> 00:01:57,850 Now, the reason that we think computer science is about 36 00:01:57,850 --> 00:02:01,770 computers is pretty much the same reason that the Egyptians 37 00:02:01,770 --> 00:02:04,520 thought geometry was about surveying instruments. 38 00:02:04,520 --> 00:02:07,340 And that is, when some field is just getting started and 39 00:02:07,340 --> 00:02:11,790 you don't really understand it very well, it's very easy to 40 00:02:11,790 --> 00:02:15,280 confuse the essence of what you're doing with the tools 41 00:02:15,280 --> 00:02:17,590 that you use. 42 00:02:17,590 --> 00:02:20,960 And indeed, on some absolute scale of things, we probably 43 00:02:20,960 --> 00:02:25,100 know less about the essence of computer science than the 44 00:02:25,100 --> 00:02:26,955 ancient Egyptians really knew about geometry. 45 00:02:26,955 --> 00:02:29,970 46 00:02:29,970 --> 00:02:32,570 Well, what do I mean by the essence of computer science? 47 00:02:32,570 --> 00:02:34,300 What do I mean by the essence of geometry? 48 00:02:34,300 --> 00:02:36,380 See, it's certainly true that these Egyptians went off and 49 00:02:36,380 --> 00:02:40,190 used surveying instruments, but when we look back on them 50 00:02:40,190 --> 00:02:42,240 after a couple of thousand years, we say, gee, what they 51 00:02:42,240 --> 00:02:45,910 were doing, the important stuff they were doing, was to 52 00:02:45,910 --> 00:02:52,510 begin to formalize notions about space and time, to start 53 00:02:52,510 --> 00:02:57,490 a way of talking about mathematical truths formally. 54 00:02:57,490 --> 00:02:59,420 That led to the axiomatic method. 55 00:02:59,420 --> 00:03:04,420 That led to sort of all of modern mathematics, figuring 56 00:03:04,420 --> 00:03:08,350 out a way to talk precisely about so-called declarative 57 00:03:08,350 --> 00:03:10,000 knowledge, what is true. 58 00:03:10,000 --> 00:03:12,550 59 00:03:12,550 --> 00:03:15,680 Well, similarly, I think in the future people will look 60 00:03:15,680 --> 00:03:18,520 back and say, yes, those primitives in the 20th century 61 00:03:18,520 --> 00:03:20,190 were fiddling around with these gadgets called 62 00:03:20,190 --> 00:03:25,790 computers, but really what they were doing is starting to 63 00:03:25,790 --> 00:03:32,730 learn how to formalize intuitions about process, how 64 00:03:32,730 --> 00:03:47,100 to do things, starting to develop a way to talk 65 00:03:47,100 --> 00:03:52,190 precisely about how-to knowledge, as opposed to 66 00:03:52,190 --> 00:03:56,470 geometry that talks about what is true. 67 00:03:56,470 --> 00:03:57,810 Let me give you an example of that. 68 00:03:57,810 --> 00:04:01,650 69 00:04:01,650 --> 00:04:02,550 Let's take a look. 70 00:04:02,550 --> 00:04:08,250 Here is a piece of mathematics that says what 71 00:04:08,250 --> 00:04:10,250 a square root is. 72 00:04:10,250 --> 00:04:17,019 The square root of X is the number Y, such that Y squared 73 00:04:17,019 --> 00:04:20,290 is equal to X and Y is greater than 0. 74 00:04:20,290 --> 00:04:23,510 Now, that's a fine piece of mathematics, but just telling 75 00:04:23,510 --> 00:04:26,900 you what a square root is doesn't really say anything 76 00:04:26,900 --> 00:04:31,420 about how you might go out and find one. 77 00:04:31,420 --> 00:04:37,410 So let's contrast that with a piece of imperative knowledge, 78 00:04:37,410 --> 00:04:39,840 how you might go out and find a square root. 79 00:04:39,840 --> 00:04:44,660 This, in fact, also comes from Egypt, not 80 00:04:44,660 --> 00:04:45,640 ancient, ancient Egypt. 81 00:04:45,640 --> 00:04:50,050 This is an algorithm due to Heron of Alexandria, called 82 00:04:50,050 --> 00:04:52,910 how to find a square root by successive averaging. 83 00:04:52,910 --> 00:05:03,370 And what it says is that, in order to find a square root, 84 00:05:03,370 --> 00:05:07,560 you make a guess, you improve that guess-- 85 00:05:07,560 --> 00:05:10,070 86 00:05:10,070 --> 00:05:12,670 and the way you improve the guess is to average the guess 87 00:05:12,670 --> 00:05:15,170 and X over the guess, and we'll talk a little bit later 88 00:05:15,170 --> 00:05:17,080 about why that's a reasonable thing-- 89 00:05:17,080 --> 00:05:19,740 and you keep improving the guess until it's good enough. 90 00:05:19,740 --> 00:05:20,800 That's a method. 91 00:05:20,800 --> 00:05:25,070 That's how to do something as opposed to declarative 92 00:05:25,070 --> 00:05:28,270 knowledge that says what you're looking for. 93 00:05:28,270 --> 00:05:29,520 That's a process. 94 00:05:29,520 --> 00:05:34,130 95 00:05:34,130 --> 00:05:38,850 Well, what's a process in general? 96 00:05:38,850 --> 00:05:40,000 It's kind of hard to say. 97 00:05:40,000 --> 00:05:45,350 You can think of it as like a magical spirit that sort of 98 00:05:45,350 --> 00:05:47,870 lives in the computer and does something. 99 00:05:47,870 --> 00:05:56,250 And the thing that directs a process is a pattern of rules 100 00:05:56,250 --> 00:05:57,500 called a procedure. 101 00:05:57,500 --> 00:06:01,690 102 00:06:01,690 --> 00:06:05,940 So procedures are the spells, if you like, that control 103 00:06:05,940 --> 00:06:10,700 these magical spirits that are the processes. 104 00:06:10,700 --> 00:06:12,650 I guess you know everyone needs a magical language, and 105 00:06:12,650 --> 00:06:17,310 sorcerers, real sorcerers, use ancient Arcadian or Sumerian 106 00:06:17,310 --> 00:06:18,670 or Babylonian or whatever. 107 00:06:18,670 --> 00:06:21,540 We're going to conjure our spirits in a magical language 108 00:06:21,540 --> 00:06:26,750 called Lisp, which is a language designed for talking 109 00:06:26,750 --> 00:06:31,120 about, for casting the spells that are procedures to direct 110 00:06:31,120 --> 00:06:32,040 the processes. 111 00:06:32,040 --> 00:06:33,780 Now, it's very easy to learn Lisp. 112 00:06:33,780 --> 00:06:35,810 In fact, in a few minutes, I'm going to teach you, 113 00:06:35,810 --> 00:06:36,960 essentially, all of Lisp. 114 00:06:36,960 --> 00:06:40,660 I'm going to teach you, essentially, all of the rules. 115 00:06:40,660 --> 00:06:43,440 And you shouldn't find that particularly surprising. 116 00:06:43,440 --> 00:06:46,150 That's sort of like saying it's very easy to learn the 117 00:06:46,150 --> 00:06:46,940 rules of chess. 118 00:06:46,940 --> 00:06:48,860 And indeed, in a few minutes, you can tell somebody the 119 00:06:48,860 --> 00:06:50,710 rules of chess. 120 00:06:50,710 --> 00:06:53,490 But of course, that's very different from saying you 121 00:06:53,490 --> 00:06:55,740 understand the implications of those rules and how to use 122 00:06:55,740 --> 00:06:58,420 those rules to become a masterful chess player. 123 00:06:58,420 --> 00:07:00,380 Well, Lisp is the same way. 124 00:07:00,380 --> 00:07:02,610 We're going to state the rules in a few minutes, and it'll be 125 00:07:02,610 --> 00:07:03,360 very easy to see. 126 00:07:03,360 --> 00:07:06,210 But what's really hard is going to be the implications 127 00:07:06,210 --> 00:07:09,310 of those rules, how you exploit those rules to be a 128 00:07:09,310 --> 00:07:12,080 master programmer. 129 00:07:12,080 --> 00:07:15,260 And the implications of those rules are going to take us 130 00:07:15,260 --> 00:07:17,770 the, well, the whole rest of the subject and, of course, 131 00:07:17,770 --> 00:07:19,020 way beyond. 132 00:07:19,020 --> 00:07:21,420 133 00:07:21,420 --> 00:07:26,070 OK, so in computer science, we're in the business of 134 00:07:26,070 --> 00:07:30,910 formalizing this sort of how-to imperative knowledge, 135 00:07:30,910 --> 00:07:33,330 how to do stuff. 136 00:07:33,330 --> 00:07:35,120 And the real issues of computer science are, of 137 00:07:35,120 --> 00:07:38,620 course, not telling people how to do square roots. 138 00:07:38,620 --> 00:07:40,050 Because if that was all it was, there 139 00:07:40,050 --> 00:07:41,760 wouldn't be no big deal. 140 00:07:41,760 --> 00:07:45,550 The real problems come when we try to build very, very large 141 00:07:45,550 --> 00:07:49,270 systems, computer programs that are thousands of pages 142 00:07:49,270 --> 00:07:52,640 long, so long that nobody can really hold them in their 143 00:07:52,640 --> 00:07:54,640 heads all at once. 144 00:07:54,640 --> 00:07:58,770 And the only reason that that's possible is because 145 00:07:58,770 --> 00:08:17,830 there are techniques for controlling the complexity of 146 00:08:17,830 --> 00:08:21,590 these large systems. And these techniques that are 147 00:08:21,590 --> 00:08:22,950 controlling complexity are what this 148 00:08:22,950 --> 00:08:24,700 course is really about. 149 00:08:24,700 --> 00:08:26,030 And in some sense, that's really what 150 00:08:26,030 --> 00:08:29,650 computer science is about. 151 00:08:29,650 --> 00:08:31,740 Now, that may seem like a very strange thing to say. 152 00:08:31,740 --> 00:08:34,960 Because after all, a lot of people besides computer 153 00:08:34,960 --> 00:08:37,970 scientists deal with controlling complexity. 154 00:08:37,970 --> 00:08:41,860 A large airliner is an extremely complex system, and 155 00:08:41,860 --> 00:08:44,760 the aeronautical engineers who design that are dealing with 156 00:08:44,760 --> 00:08:47,030 immense complexity. 157 00:08:47,030 --> 00:08:49,380 But there's a difference between that kind of 158 00:08:49,380 --> 00:08:52,205 complexity and what we deal with in computer science. 159 00:08:52,205 --> 00:08:55,090 160 00:08:55,090 --> 00:08:57,750 And that is that computer science, in some 161 00:08:57,750 --> 00:08:59,700 sense, isn't real. 162 00:08:59,700 --> 00:09:02,670 163 00:09:02,670 --> 00:09:07,070 You see, when an engineer is designing a physical system, 164 00:09:07,070 --> 00:09:09,520 that's made out of real parts. 165 00:09:09,520 --> 00:09:12,820 The engineers who worry about that have to address problems 166 00:09:12,820 --> 00:09:16,540 of tolerance and approximation and noise in the system. 167 00:09:16,540 --> 00:09:19,280 So for example, as an electrical engineer, I can go 168 00:09:19,280 --> 00:09:21,885 off and easily build a one-stage amplifier or a 169 00:09:21,885 --> 00:09:25,090 two-stage amplifier, and I can imagine cascading a lot of 170 00:09:25,090 --> 00:09:26,760 them to build a million-stage amplifier. 171 00:09:26,760 --> 00:09:30,900 But it's ridiculous to build such a thing, because long 172 00:09:30,900 --> 00:09:33,160 before the millionth stage, the thermal noise in those 173 00:09:33,160 --> 00:09:34,740 components way at the beginning is going to get 174 00:09:34,740 --> 00:09:36,200 amplified and make the whole thing meaningless. 175 00:09:36,200 --> 00:09:38,880 176 00:09:38,880 --> 00:09:44,070 Computer science deals with idealized components. 177 00:09:44,070 --> 00:09:47,430 We know as much as we want about these little program and 178 00:09:47,430 --> 00:09:51,820 data pieces that we're fitting things together. 179 00:09:51,820 --> 00:09:53,090 We don't have to worry about tolerance. 180 00:09:53,090 --> 00:09:57,960 And that means that, in building a large program, 181 00:09:57,960 --> 00:10:01,720 there's not all that much difference between what I can 182 00:10:01,720 --> 00:10:06,520 build and what I can imagine, because the parts are these 183 00:10:06,520 --> 00:10:10,250 abstract entities that I know as much as I want. 184 00:10:10,250 --> 00:10:13,430 I know about them as precisely as I'd like. 185 00:10:13,430 --> 00:10:15,920 So as opposed to other kinds of engineering, where the 186 00:10:15,920 --> 00:10:17,830 constraints on what you can build are the constraints of 187 00:10:17,830 --> 00:10:19,810 physical systems, the constraints of physics and 188 00:10:19,810 --> 00:10:24,160 noise and approximation, the constraints imposed in 189 00:10:24,160 --> 00:10:26,640 building large software systems are the limitations of 190 00:10:26,640 --> 00:10:28,930 our own minds. 191 00:10:28,930 --> 00:10:32,460 So in that sense, computer science is like an abstract 192 00:10:32,460 --> 00:10:33,530 form of engineering. 193 00:10:33,530 --> 00:10:35,680 It's the kind of engineering where you ignore the 194 00:10:35,680 --> 00:10:37,645 constraints that are imposed by reality. 195 00:10:37,645 --> 00:10:42,050 196 00:10:42,050 --> 00:10:46,400 Well, what are some of these techniques? 197 00:10:46,400 --> 00:10:47,830 They're not special to computer science. 198 00:10:47,830 --> 00:10:50,360 199 00:10:50,360 --> 00:10:54,140 First technique, which is used in all of engineering, is a 200 00:10:54,140 --> 00:10:57,785 kind of abstraction called black-box abstraction. 201 00:10:57,785 --> 00:11:07,670 202 00:11:07,670 --> 00:11:14,340 Take something and build a box about it. 203 00:11:14,340 --> 00:11:19,220 Let's see, for example, if we looked at that square root 204 00:11:19,220 --> 00:11:29,678 method, I might want to take that and build a box. 205 00:11:29,678 --> 00:11:38,980 That sort of says, to find the square root of X. And that 206 00:11:38,980 --> 00:11:42,560 might be a whole complicated set of rules. 207 00:11:42,560 --> 00:11:46,280 And that might end up being a kind of thing where I can put 208 00:11:46,280 --> 00:11:50,270 in, say, 36 and say, what's the square root of 36? 209 00:11:50,270 --> 00:11:51,520 And out comes 6. 210 00:11:51,520 --> 00:11:53,880 211 00:11:53,880 --> 00:11:59,630 And the important thing is that I'd like to design that 212 00:11:59,630 --> 00:12:05,080 so that if George comes along and would like to compute, 213 00:12:05,080 --> 00:12:11,580 say, the square root of A plus the square root of B, he can 214 00:12:11,580 --> 00:12:14,930 take this thing and use it as a module without having to 215 00:12:14,930 --> 00:12:16,760 look inside and build something that looks like 216 00:12:16,760 --> 00:12:24,960 this, like an A and a B and a square root box and another 217 00:12:24,960 --> 00:12:32,660 square root box and then something that adds that would 218 00:12:32,660 --> 00:12:33,870 put out the answer. 219 00:12:33,870 --> 00:12:38,830 And you can see, just from the fact that I want to do that, 220 00:12:38,830 --> 00:12:41,560 is from George's point of view, the internals of what's 221 00:12:41,560 --> 00:12:44,170 in here should not be important. 222 00:12:44,170 --> 00:12:46,940 So for instance, it shouldn't matter that, when I wrote 223 00:12:46,940 --> 00:12:50,750 this, I said I want to find the square root of X. I could 224 00:12:50,750 --> 00:12:54,840 have said the square root of Y, or the square root of A, or 225 00:12:54,840 --> 00:12:56,890 anything at all. 226 00:12:56,890 --> 00:13:03,480 That's the fundamental notion of putting something in a box 227 00:13:03,480 --> 00:13:07,520 using black-box abstraction to suppress detail. 228 00:13:07,520 --> 00:13:10,070 And the reason for that is you want to go off and build 229 00:13:10,070 --> 00:13:11,990 bigger boxes. 230 00:13:11,990 --> 00:13:13,880 Now, there's another reason for doing black-box 231 00:13:13,880 --> 00:13:17,340 abstraction other than you want to suppress detail for 232 00:13:17,340 --> 00:13:18,310 building bigger boxes. 233 00:13:18,310 --> 00:13:24,880 Sometimes you want to say that your way of doing something, 234 00:13:24,880 --> 00:13:30,210 your how-to method, is an instance of a more general 235 00:13:30,210 --> 00:13:33,430 thing, and you'd like your language to be able to express 236 00:13:33,430 --> 00:13:35,560 that generality. 237 00:13:35,560 --> 00:13:37,800 Let me show you another example 238 00:13:37,800 --> 00:13:38,740 sticking with square roots. 239 00:13:38,740 --> 00:13:42,260 Let's go back and take another look at that slide with the 240 00:13:42,260 --> 00:13:44,380 square root algorithm on it. 241 00:13:44,380 --> 00:13:45,460 Remember what that says. 242 00:13:45,460 --> 00:13:50,700 That says, in order to do something, I make a guess, and 243 00:13:50,700 --> 00:13:53,800 I improve that guess, and I sort of keep 244 00:13:53,800 --> 00:13:56,970 improving that guess. 245 00:13:56,970 --> 00:13:59,560 So there's the general strategy of, I'm looking for 246 00:13:59,560 --> 00:14:02,440 something, and the way I find it is that I 247 00:14:02,440 --> 00:14:04,280 keep improving it. 248 00:14:04,280 --> 00:14:10,930 Now, that's a particular case of another kind of strategy 249 00:14:10,930 --> 00:14:14,176 for finding a fixed point of something. 250 00:14:14,176 --> 00:14:17,660 So you have a fixed point of a function. 251 00:14:17,660 --> 00:14:26,090 A fixed point of a function is something, is a value. 252 00:14:26,090 --> 00:14:30,710 A fixed point of a function F is a value Y, such that F of Y 253 00:14:30,710 --> 00:14:41,592 equals Y. And the way I might do that is start with a guess. 254 00:14:41,592 --> 00:14:44,630 And then if I want something that doesn't change when I 255 00:14:44,630 --> 00:14:47,800 keep applying F, is I'll keep applying F over and over until 256 00:14:47,800 --> 00:14:50,150 that result doesn't change very much. 257 00:14:50,150 --> 00:14:52,290 So there's a general strategy. 258 00:14:52,290 --> 00:14:56,250 And then, for example, to compute the square root of X, 259 00:14:56,250 --> 00:15:00,780 I can try and find a fixed point of the function which 260 00:15:00,780 --> 00:15:05,020 takes Y to the average of X/Y. And the idea that is that if I 261 00:15:05,020 --> 00:15:09,300 really had Y equal to the square root of X, then Y and 262 00:15:09,300 --> 00:15:12,080 X/Y would be the same value. 263 00:15:12,080 --> 00:15:16,370 They'd both be the square root of X, because X over the 264 00:15:16,370 --> 00:15:19,080 square root of X is the square root of X. 265 00:15:19,080 --> 00:15:23,860 And so the average if Y were equal to the square of X, then 266 00:15:23,860 --> 00:15:26,230 the average wouldn't change. 267 00:15:26,230 --> 00:15:27,530 So the square root of X is a fixed point of 268 00:15:27,530 --> 00:15:30,250 that particular function. 269 00:15:30,250 --> 00:15:34,010 Now, what I'd like to have, I'd like to express the 270 00:15:34,010 --> 00:15:36,430 general strategy for finding fixed points. 271 00:15:36,430 --> 00:15:37,210 So what I might imagine doing, is to find, is to be able to 272 00:15:37,210 --> 00:15:37,309 use my language to define a box that says "fixed point," 273 00:15:37,309 --> 00:15:37,417 just like I could make a box that says "square root." And 274 00:15:37,417 --> 00:15:38,667 I'd like to be able to express this in my language. 275 00:15:38,667 --> 00:15:56,350 276 00:15:56,350 --> 00:16:00,870 So I'd like to express not only the imperative how-to 277 00:16:00,870 --> 00:16:03,620 knowledge of a particular thing like square root, but 278 00:16:03,620 --> 00:16:05,600 I'd like to be able to express the imperative knowledge of 279 00:16:05,600 --> 00:16:09,930 how to do a general thing like how to find fixed point. 280 00:16:09,930 --> 00:16:12,090 And in fact, let's go back and look at that slide again. 281 00:16:12,090 --> 00:16:15,010 282 00:16:15,010 --> 00:16:23,380 See, not only is this a piece of imperative knowledge, how 283 00:16:23,380 --> 00:16:27,190 to find a fixed point, but over here on the bottom, 284 00:16:27,190 --> 00:16:29,890 there's another piece of imperative knowledge which 285 00:16:29,890 --> 00:16:34,350 says, one way to compute square root is to apply this 286 00:16:34,350 --> 00:16:36,140 general fixed point method. 287 00:16:36,140 --> 00:16:37,710 So I'd like to also be able to express 288 00:16:37,710 --> 00:16:39,700 that imperative knowledge. 289 00:16:39,700 --> 00:16:40,650 What would that look like? 290 00:16:40,650 --> 00:16:46,010 That would say, this fixed point box is such that if I 291 00:16:46,010 --> 00:16:56,980 input to it the function that takes Y to the average of Y 292 00:16:56,980 --> 00:17:04,300 and X/Y, then what should come out of that fixed point box is 293 00:17:04,300 --> 00:17:06,200 a method for finding square roots. 294 00:17:06,200 --> 00:17:08,800 295 00:17:08,800 --> 00:17:10,829 So in these boxes we're building, we're not only 296 00:17:10,829 --> 00:17:16,369 building boxes that you input numbers and output numbers, 297 00:17:16,369 --> 00:17:19,410 we're going to be building in boxes that, in effect, compute 298 00:17:19,410 --> 00:17:22,250 methods like finding square root. 299 00:17:22,250 --> 00:17:27,480 And my take is their inputs functions, like Y goes to the 300 00:17:27,480 --> 00:17:32,360 average of Y and X/Y. The reason we want to do that, the 301 00:17:32,360 --> 00:17:35,425 reason this is a procedure, will end up being a procedure, 302 00:17:35,425 --> 00:17:39,640 as we'll see, whose value is another procedure, the reason 303 00:17:39,640 --> 00:17:42,630 we want to do that is because procedures are going to be our 304 00:17:42,630 --> 00:17:47,960 ways of talking about imperative knowledge. 305 00:17:47,960 --> 00:17:50,560 And the way to make that very powerful is to be able to talk 306 00:17:50,560 --> 00:17:53,260 about other kinds of knowledge. 307 00:17:53,260 --> 00:17:55,930 So here is a procedure that, in effect, talks about another 308 00:17:55,930 --> 00:17:59,450 procedure, a general strategy that itself talks about 309 00:17:59,450 --> 00:18:00,700 general strategies. 310 00:18:00,700 --> 00:18:04,290 311 00:18:04,290 --> 00:18:08,370 Well, our first topic in this course-- there'll be three 312 00:18:08,370 --> 00:18:11,070 major topics-- will be black-box abstraction. 313 00:18:11,070 --> 00:18:15,150 Let's look at that in a little bit more detail. 314 00:18:15,150 --> 00:18:23,910 What we're going to do is we will start out talking about 315 00:18:23,910 --> 00:18:27,480 how Lisp is built up out of primitive objects. 316 00:18:27,480 --> 00:18:29,580 What does the language supply with us? 317 00:18:29,580 --> 00:18:32,690 And we'll see that there are primitive procedures and 318 00:18:32,690 --> 00:18:35,620 primitive data. 319 00:18:35,620 --> 00:18:38,510 Then we're going to see, how do you take those primitives 320 00:18:38,510 --> 00:18:41,940 and combine them to make more complicated things, means of 321 00:18:41,940 --> 00:18:42,860 combination? 322 00:18:42,860 --> 00:18:44,824 And what we'll see is that there are ways of putting 323 00:18:44,824 --> 00:18:47,850 things together, putting primitive procedures together 324 00:18:47,850 --> 00:18:50,960 to make more complicated procedures. 325 00:18:50,960 --> 00:18:53,250 And we'll see how to put primitive data together to 326 00:18:53,250 --> 00:18:55,830 make compound data. 327 00:18:55,830 --> 00:18:59,700 Then we'll say, well, having made those compounds things, 328 00:18:59,700 --> 00:19:02,830 how do you abstract them? 329 00:19:02,830 --> 00:19:05,290 How do you put those black boxes around them so you can 330 00:19:05,290 --> 00:19:08,090 use them as components in more complex things? 331 00:19:08,090 --> 00:19:11,640 And we'll see that's done by defining procedures and a 332 00:19:11,640 --> 00:19:13,740 technique for dealing with compound data called data 333 00:19:13,740 --> 00:19:15,540 abstraction. 334 00:19:15,540 --> 00:19:19,150 And then, what's maybe the most important thing, is going 335 00:19:19,150 --> 00:19:21,650 from just the rules to how does an expert work? 336 00:19:21,650 --> 00:19:25,800 How do you express common patterns of doing things, like 337 00:19:25,800 --> 00:19:28,580 saying, well, there's a general method of fixed point 338 00:19:28,580 --> 00:19:32,822 and square root is a particular case of that? 339 00:19:32,822 --> 00:19:34,290 And we're going to use-- 340 00:19:34,290 --> 00:19:36,640 I've already hinted at it-- something called higher-order 341 00:19:36,640 --> 00:19:40,770 procedures, namely procedures whose inputs and outputs are 342 00:19:40,770 --> 00:19:43,230 themselves procedures. 343 00:19:43,230 --> 00:19:44,900 And then we'll also see something very interesting. 344 00:19:44,900 --> 00:19:47,730 We'll see, as we go further and further on and become more 345 00:19:47,730 --> 00:19:50,310 abstract, there'll be very-- 346 00:19:50,310 --> 00:19:53,700 well, the line between what we consider to be data and what 347 00:19:53,700 --> 00:19:56,920 we consider to be procedures is going to blur at an 348 00:19:56,920 --> 00:19:58,170 incredible rate. 349 00:19:58,170 --> 00:20:03,270 350 00:20:03,270 --> 00:20:06,300 Well, that's our first subject, black-box 351 00:20:06,300 --> 00:20:07,020 abstraction. 352 00:20:07,020 --> 00:20:08,270 Let's look at the second topic. 353 00:20:08,270 --> 00:20:10,640 354 00:20:10,640 --> 00:20:13,510 I can introduce it like this. 355 00:20:13,510 --> 00:20:19,590 See, suppose I want to express the idea-- 356 00:20:19,590 --> 00:20:22,790 remember, we're talking about ideas-- 357 00:20:22,790 --> 00:20:30,950 suppose I want to express the idea that I can take something 358 00:20:30,950 --> 00:20:36,070 and multiply it by the sum of two other things. 359 00:20:36,070 --> 00:20:40,180 So for example, I might say, if I had 1 and 3 and multiply 360 00:20:40,180 --> 00:20:41,920 that by 2, I get 8. 361 00:20:41,920 --> 00:20:43,930 But I'm talking about the general idea of what's called 362 00:20:43,930 --> 00:20:46,470 linear combination, that you can add two things and 363 00:20:46,470 --> 00:20:49,170 multiply them by something else. 364 00:20:49,170 --> 00:20:51,040 It's very easy when I think about it for numbers, but 365 00:20:51,040 --> 00:20:56,060 suppose I also want to use that same idea to think about, 366 00:20:56,060 --> 00:21:00,920 I could add two vectors, a1 and a2, and then scale them by 367 00:21:00,920 --> 00:21:03,060 some factor x and get another vector. 368 00:21:03,060 --> 00:21:08,570 Or I might say, I want to think about a1 and a2 as being 369 00:21:08,570 --> 00:21:13,720 polynomials, and I might want to add those two polynomials 370 00:21:13,720 --> 00:21:16,680 and then multiply them by 2 to get a more complicated one. 371 00:21:16,680 --> 00:21:20,020 372 00:21:20,020 --> 00:21:24,650 Or a1 and a2 might be electrical signals, and I 373 00:21:24,650 --> 00:21:26,870 might want to think about summing those two electrical 374 00:21:26,870 --> 00:21:29,350 signals and then putting the whole thing through an 375 00:21:29,350 --> 00:21:33,890 amplifier, multiplying it by some factor of 2 or something. 376 00:21:33,890 --> 00:21:34,850 The idea is I want to think about the 377 00:21:34,850 --> 00:21:38,530 general notion of that. 378 00:21:38,530 --> 00:21:42,880 Now, if our language is going to be good language for 379 00:21:42,880 --> 00:21:47,960 expressing those kind of general ideas, if I really, 380 00:21:47,960 --> 00:21:55,190 really can do that, I'd like to be able to say I'm going to 381 00:21:55,190 --> 00:22:03,660 multiply by x the sum of a1 and a2, and I'd like that to 382 00:22:03,660 --> 00:22:07,470 express the general idea of all different kinds of things 383 00:22:07,470 --> 00:22:09,980 that a1 and a2 could be. 384 00:22:09,980 --> 00:22:11,690 Now, if you think about that, there's a problem, because 385 00:22:11,690 --> 00:22:16,370 after all, the actual primitive operations that go 386 00:22:16,370 --> 00:22:17,870 on in the machine are obviously going to be 387 00:22:17,870 --> 00:22:22,070 different if I'm adding two numbers than if I'm adding two 388 00:22:22,070 --> 00:22:25,790 polynomials, or if I'm adding the representation of two 389 00:22:25,790 --> 00:22:27,940 electrical signals or wave forms. 390 00:22:27,940 --> 00:22:30,950 Somewhere, there has to be the knowledge of the kinds of 391 00:22:30,950 --> 00:22:33,140 various things that you can add and the 392 00:22:33,140 --> 00:22:34,390 ways of adding them. 393 00:22:34,390 --> 00:22:37,110 394 00:22:37,110 --> 00:22:39,430 Now, to construct such a system, the question is, where 395 00:22:39,430 --> 00:22:41,090 do I put that knowledge? 396 00:22:41,090 --> 00:22:43,280 How do I think about the different kinds 397 00:22:43,280 --> 00:22:44,480 of choices I have? 398 00:22:44,480 --> 00:22:48,310 And if tomorrow George comes up with a new kind of object 399 00:22:48,310 --> 00:22:51,770 that might be added and multiplied, how do I add 400 00:22:51,770 --> 00:22:54,280 George's new object to the system without screwing up 401 00:22:54,280 --> 00:22:57,690 everything that was already there? 402 00:22:57,690 --> 00:23:00,790 Well, that's going to be the second big topic, the way of 403 00:23:00,790 --> 00:23:03,720 controlling that kind of complexity. 404 00:23:03,720 --> 00:23:07,480 And the way you do that is by establishing conventional 405 00:23:07,480 --> 00:23:20,230 interfaces, agreed upon ways of plugging things together. 406 00:23:20,230 --> 00:23:23,530 Just like in electrical engineering, people have 407 00:23:23,530 --> 00:23:26,520 standard impedances for connectors, and then you know 408 00:23:26,520 --> 00:23:28,080 if you build something with one of those standard 409 00:23:28,080 --> 00:23:30,160 impedances, you can plug it together with something else. 410 00:23:30,160 --> 00:23:32,720 411 00:23:32,720 --> 00:23:34,300 So that's going to be our second large topic, 412 00:23:34,300 --> 00:23:35,690 conventional interfaces. 413 00:23:35,690 --> 00:23:39,000 What we're going to see is, first, we're going to talk 414 00:23:39,000 --> 00:23:41,400 about the problem of generic operations, which is the one I 415 00:23:41,400 --> 00:23:46,100 alluded to, things like "plus" that have to work with all 416 00:23:46,100 --> 00:23:47,350 different kinds of data. 417 00:23:47,350 --> 00:23:52,149 418 00:23:52,149 --> 00:23:54,660 So we talk about generic operations. 419 00:23:54,660 --> 00:23:58,270 Then we're going to talk about really large-scale structures. 420 00:23:58,270 --> 00:24:01,820 How do you put together very large programs that model the 421 00:24:01,820 --> 00:24:03,880 kinds of complex systems in the real world that 422 00:24:03,880 --> 00:24:05,480 you'd like to model? 423 00:24:05,480 --> 00:24:08,990 And what we're going to see is that there are two very 424 00:24:08,990 --> 00:24:11,770 important metaphors for putting together such systems. 425 00:24:11,770 --> 00:24:14,730 One is called object-oriented programming, where you sort of 426 00:24:14,730 --> 00:24:19,840 think of your system as a kind of society full of little 427 00:24:19,840 --> 00:24:21,150 things that interact by sending 428 00:24:21,150 --> 00:24:23,300 information between them. 429 00:24:23,300 --> 00:24:26,540 And then the second one is operations on aggregates, 430 00:24:26,540 --> 00:24:29,820 called streams, where you think of a large system put 431 00:24:29,820 --> 00:24:33,530 together kind of like a signal processing engineer puts 432 00:24:33,530 --> 00:24:35,020 together a large electrical system. 433 00:24:35,020 --> 00:24:38,610 434 00:24:38,610 --> 00:24:40,240 That's going to be our second topic. 435 00:24:40,240 --> 00:24:43,370 436 00:24:43,370 --> 00:24:47,000 Now, the third thing we're going to come to, the third 437 00:24:47,000 --> 00:24:49,640 basic technique for controlling complexity, is 438 00:24:49,640 --> 00:24:51,680 making new languages. 439 00:24:51,680 --> 00:24:54,370 Because sometimes, when you're sort of overwhelmed by the 440 00:24:54,370 --> 00:24:56,640 complexity of a design, the way that you control that 441 00:24:56,640 --> 00:25:01,330 complexity is to pick a new design language. 442 00:25:01,330 --> 00:25:03,330 And the purpose of the new design language will be to 443 00:25:03,330 --> 00:25:05,730 highlight different aspects of the system. 444 00:25:05,730 --> 00:25:08,360 It will suppress some kinds of details and emphasize other 445 00:25:08,360 --> 00:25:09,610 kinds of details. 446 00:25:09,610 --> 00:25:12,910 447 00:25:12,910 --> 00:25:15,910 This is going to be the most magical part of the course. 448 00:25:15,910 --> 00:25:18,350 We're going to start out by actually looking at the 449 00:25:18,350 --> 00:25:21,730 technology for building new computer languages. 450 00:25:21,730 --> 00:25:25,770 The first thing we're going to do is actually build in Lisp. 451 00:25:25,770 --> 00:25:29,210 452 00:25:29,210 --> 00:25:32,940 We're going to express in Lisp the process of interpreting 453 00:25:32,940 --> 00:25:33,800 Lisp itself. 454 00:25:33,800 --> 00:25:36,840 And that's going to be a very sort of self-circular thing. 455 00:25:36,840 --> 00:25:38,870 There's a little mystical symbol that 456 00:25:38,870 --> 00:25:40,750 has to do with that. 457 00:25:40,750 --> 00:25:45,500 The process of interpreting Lisp is sort of a giant wheel 458 00:25:45,500 --> 00:25:49,150 of two processes, apply and eval, which sort of constantly 459 00:25:49,150 --> 00:25:52,031 reduce expressions to each other. 460 00:25:52,031 --> 00:25:54,150 Then we're going to see all sorts of other magical things. 461 00:25:54,150 --> 00:25:56,690 Here's another magical symbol. 462 00:25:56,690 --> 00:25:59,870 463 00:25:59,870 --> 00:26:02,260 This is sort of the Y operator, which is, in some 464 00:26:02,260 --> 00:26:04,800 sense, the expression of infinity inside 465 00:26:04,800 --> 00:26:06,390 our procedural language. 466 00:26:06,390 --> 00:26:08,610 We'll take a look at that. 467 00:26:08,610 --> 00:26:11,880 In any case, this section of the course is called 468 00:26:11,880 --> 00:26:24,270 Metalinguistic Abstraction, abstracting by talking about 469 00:26:24,270 --> 00:26:25,535 how you construct new languages. 470 00:26:25,535 --> 00:26:30,270 471 00:26:30,270 --> 00:26:34,140 As I said, we're going to start out by looking at the 472 00:26:34,140 --> 00:26:35,530 process of interpretation. 473 00:26:35,530 --> 00:26:38,270 We're going to look at this apply-eval 474 00:26:38,270 --> 00:26:41,980 loop, and build Lisp. 475 00:26:41,980 --> 00:26:44,450 Then, just to show you that this is very general, we're 476 00:26:44,450 --> 00:26:47,100 going to use exactly the same technology to build a very 477 00:26:47,100 --> 00:26:49,780 different kind of language, a so-called logic programming 478 00:26:49,780 --> 00:26:52,880 language, where you don't really talk about procedures 479 00:26:52,880 --> 00:26:54,560 at all that have inputs and outputs. 480 00:26:54,560 --> 00:26:57,290 What you do is talk about relations between things. 481 00:26:57,290 --> 00:27:01,220 And then finally, we're going to talk about how you 482 00:27:01,220 --> 00:27:04,140 implement these things very concretely on the very 483 00:27:04,140 --> 00:27:06,830 simplest kind of machines. 484 00:27:06,830 --> 00:27:09,860 We'll see something like this. 485 00:27:09,860 --> 00:27:14,880 This is a picture of a chip, which is the Lisp interpreter 486 00:27:14,880 --> 00:27:17,330 that we will be talking about then in hardware. 487 00:27:17,330 --> 00:27:21,010 488 00:27:21,010 --> 00:27:24,840 Well, there's an outline of the course, three big topics. 489 00:27:24,840 --> 00:27:28,120 Black-box abstraction, conventional interfaces, 490 00:27:28,120 --> 00:27:31,590 metalinguistic abstraction. 491 00:27:31,590 --> 00:27:33,480 Now, let's take a break now and then we'll get started. 492 00:27:33,480 --> 00:28:04,770 [MUSIC PLAYING] 493 00:28:04,770 --> 00:28:08,020 Let's actually start in learning Lisp now. 494 00:28:08,020 --> 00:28:10,250 Actually, we'll start out by learning something much more 495 00:28:10,250 --> 00:28:12,320 important, maybe the very most important thing in this 496 00:28:12,320 --> 00:28:16,220 course, which is not Lisp, in particular, of course, but 497 00:28:16,220 --> 00:28:20,320 rather a general framework for thinking about languages that 498 00:28:20,320 --> 00:28:21,970 I already alluded to. 499 00:28:21,970 --> 00:28:24,420 When somebody tells you they're going to show you a 500 00:28:24,420 --> 00:28:27,150 language, what you should say is, what I'd like you to tell 501 00:28:27,150 --> 00:28:32,510 me is what are the primitive elements? 502 00:28:32,510 --> 00:28:37,490 503 00:28:37,490 --> 00:28:38,930 What does the language come with? 504 00:28:38,930 --> 00:28:43,650 Then, what are the ways you put those together? 505 00:28:43,650 --> 00:28:46,720 What are the means of combination? 506 00:28:46,720 --> 00:28:50,190 507 00:28:50,190 --> 00:28:53,400 What are the things that allow you to take these primitive 508 00:28:53,400 --> 00:28:57,920 elements and build bigger things out of them? 509 00:28:57,920 --> 00:29:01,280 What are the ways of putting things together? 510 00:29:01,280 --> 00:29:04,890 And then, what are the means of abstraction? 511 00:29:04,890 --> 00:29:08,110 512 00:29:08,110 --> 00:29:15,830 How do we take those complicated things and draw 513 00:29:15,830 --> 00:29:16,750 those boxes around them? 514 00:29:16,750 --> 00:29:20,180 How do we name them so that we can now use them as if they 515 00:29:20,180 --> 00:29:22,810 were primitive elements in making still 516 00:29:22,810 --> 00:29:23,790 more complex things? 517 00:29:23,790 --> 00:29:26,850 And so on, and so on, and so on. 518 00:29:26,850 --> 00:29:28,580 So when someone says to you, gee, I have a great new 519 00:29:28,580 --> 00:29:32,900 computer language, you don't say, how many characters does 520 00:29:32,900 --> 00:29:35,810 it take to invert a matrix? 521 00:29:35,810 --> 00:29:37,460 It's irrelevant. 522 00:29:37,460 --> 00:29:41,220 What you say is, if the language did not come with 523 00:29:41,220 --> 00:29:43,470 matrices built in or with something else built in, how 524 00:29:43,470 --> 00:29:45,910 could I then build that thing? 525 00:29:45,910 --> 00:29:47,590 What are the means of combination which would allow 526 00:29:47,590 --> 00:29:48,610 me to do that? 527 00:29:48,610 --> 00:29:52,450 And then, what are the means of abstraction which allow me 528 00:29:52,450 --> 00:29:55,750 then to use those as elements in making more complicated 529 00:29:55,750 --> 00:29:57,000 things yet? 530 00:29:57,000 --> 00:29:58,960 531 00:29:58,960 --> 00:30:02,330 Well, we're going to see that Lisp has some primitive data 532 00:30:02,330 --> 00:30:05,280 and some primitive procedures. 533 00:30:05,280 --> 00:30:08,410 In fact, let's really start. 534 00:30:08,410 --> 00:30:09,950 And here's a piece of primitive data in 535 00:30:09,950 --> 00:30:16,710 Lisp, number 3. 536 00:30:16,710 --> 00:30:18,800 Actually, if I'm being very pedantic, that's 537 00:30:18,800 --> 00:30:19,790 not the number 3. 538 00:30:19,790 --> 00:30:24,620 That's some symbol that represents Plato's concept of 539 00:30:24,620 --> 00:30:27,060 the number 3. 540 00:30:27,060 --> 00:30:30,500 And here's another. 541 00:30:30,500 --> 00:30:35,370 Here's some more primitive data in Lisp, 17.4. 542 00:30:35,370 --> 00:30:40,940 Or actually, some representation of 17.4. 543 00:30:40,940 --> 00:30:43,795 And here's another one, 5. 544 00:30:43,795 --> 00:30:46,750 545 00:30:46,750 --> 00:30:48,490 Here's another primitive object that's 546 00:30:48,490 --> 00:30:52,130 built in Lisp, addition. 547 00:30:52,130 --> 00:30:56,830 Actually, to use the same kind of pedantic-- this is a name 548 00:30:56,830 --> 00:31:00,140 for the primitive method of adding things. 549 00:31:00,140 --> 00:31:02,920 Just like this is a name for Plato's number 3, this is a 550 00:31:02,920 --> 00:31:10,370 name for Plato's concept of how you add things. 551 00:31:10,370 --> 00:31:12,370 So those are some primitive elements. 552 00:31:12,370 --> 00:31:14,090 I can put them together. 553 00:31:14,090 --> 00:31:18,140 I can say, gee, what's the sum of 3 and 17.4 and 5? 554 00:31:18,140 --> 00:31:25,580 And the way I do that is to say, let's apply the sum 555 00:31:25,580 --> 00:31:27,600 operator to these three numbers. 556 00:31:27,600 --> 00:31:28,310 And I should get, what? 557 00:31:28,310 --> 00:31:29,690 8, 17. 558 00:31:29,690 --> 00:31:34,390 25.4. 559 00:31:34,390 --> 00:31:37,590 So I should be able to ask Lisp what the value of this 560 00:31:37,590 --> 00:31:43,050 is, and it will return 25.4. 561 00:31:43,050 --> 00:31:44,610 Let's introduce some names. 562 00:31:44,610 --> 00:31:50,950 This thing that I typed is called a combination. 563 00:31:50,950 --> 00:31:56,830 564 00:31:56,830 --> 00:31:59,040 And a combination consists, in general, 565 00:31:59,040 --> 00:32:02,790 of applying an operator-- 566 00:32:02,790 --> 00:32:04,220 so this is an operator-- 567 00:32:04,220 --> 00:32:09,500 568 00:32:09,500 --> 00:32:13,190 to some operands. 569 00:32:13,190 --> 00:32:14,440 These are the operands. 570 00:32:14,440 --> 00:32:21,760 571 00:32:21,760 --> 00:32:23,640 And of course, I can make more complex things. 572 00:32:23,640 --> 00:32:25,950 The reason I can get complexity out of this is 573 00:32:25,950 --> 00:32:30,290 because the operands themselves, in general, can be 574 00:32:30,290 --> 00:32:31,200 combinations. 575 00:32:31,200 --> 00:32:37,770 So for instance, I could say, what is the sum of 3 and the 576 00:32:37,770 --> 00:32:45,660 product of 5 and 6 and 8 and 2? 577 00:32:45,660 --> 00:32:47,520 And I should get-- let's see-- 578 00:32:47,520 --> 00:32:52,355 30, 40, 43. 579 00:32:52,355 --> 00:32:56,520 So Lisp should tell me that that's 43. 580 00:32:56,520 --> 00:33:01,610 Forming combinations is the basic needs of combination 581 00:33:01,610 --> 00:33:04,690 that we'll be looking at. 582 00:33:04,690 --> 00:33:10,520 And then, well, you see some syntax here. 583 00:33:10,520 --> 00:33:16,940 Lisp uses what's called prefix notation, which means that the 584 00:33:16,940 --> 00:33:25,400 operator is written to the left of the operands. 585 00:33:25,400 --> 00:33:27,810 It's just a convention. 586 00:33:27,810 --> 00:33:29,960 And notice, it's fully parenthesized. 587 00:33:29,960 --> 00:33:32,170 And the parentheses make it completely unambiguous. 588 00:33:32,170 --> 00:33:36,840 So by looking at this, I can see that there's the operator, 589 00:33:36,840 --> 00:33:42,760 and there are 1, 2, 3, 4 operands. 590 00:33:42,760 --> 00:33:46,980 And I can see that the second operand here is itself some 591 00:33:46,980 --> 00:33:52,500 combination that has one operator and two operands. 592 00:33:52,500 --> 00:33:55,740 Parentheses in Lisp are a little bit, or are very unlike 593 00:33:55,740 --> 00:33:57,630 parentheses in conventional mathematics. 594 00:33:57,630 --> 00:34:01,400 In mathematics, we sort of use them to mean grouping, and it 595 00:34:01,400 --> 00:34:03,140 sort of doesn't hurt if sometimes you leave out 596 00:34:03,140 --> 00:34:04,610 parentheses if people understand 597 00:34:04,610 --> 00:34:05,790 that that's a group. 598 00:34:05,790 --> 00:34:07,660 And in general, it doesn't hurt if you put in extra 599 00:34:07,660 --> 00:34:09,760 parentheses, because that maybe makes the 600 00:34:09,760 --> 00:34:10,570 grouping more distinct. 601 00:34:10,570 --> 00:34:13,010 Lisp is not like that. 602 00:34:13,010 --> 00:34:17,020 In Lisp, you cannot leave out parentheses, and you cannot 603 00:34:17,020 --> 00:34:20,530 put in extra parentheses, because putting in parentheses 604 00:34:20,530 --> 00:34:23,980 always means, exactly and precisely, this is a 605 00:34:23,980 --> 00:34:27,260 combination which has meaning, applying 606 00:34:27,260 --> 00:34:29,050 operators to operands. 607 00:34:29,050 --> 00:34:32,290 And if I left this out, if I left those parentheses out, it 608 00:34:32,290 --> 00:34:35,469 would mean something else. 609 00:34:35,469 --> 00:34:38,100 In fact, the way to think about this, is really what I'm 610 00:34:38,100 --> 00:34:42,280 doing when I write something like this is writing a tree. 611 00:34:42,280 --> 00:34:48,909 So this combination is a tree that has a plus and then a 3 612 00:34:48,909 --> 00:34:54,500 and then a something else and an 8 and a 2. 613 00:34:54,500 --> 00:34:57,670 And then this something else here is itself a little 614 00:34:57,670 --> 00:35:03,770 subtree that has a star and a 5 and a 6. 615 00:35:03,770 --> 00:35:07,400 And the way to think of that is, really, what's going on 616 00:35:07,400 --> 00:35:13,260 are we're writing these trees, and parentheses are just a way 617 00:35:13,260 --> 00:35:16,390 to write this two-dimensional structure as a linear 618 00:35:16,390 --> 00:35:19,130 character string. 619 00:35:19,130 --> 00:35:22,110 Because at least when Lisp first started and people had 620 00:35:22,110 --> 00:35:24,630 teletypes or punch cards or whatever, this was more 621 00:35:24,630 --> 00:35:25,890 convenient. 622 00:35:25,890 --> 00:35:29,590 Maybe if Lisp started today, the syntax of Lisp 623 00:35:29,590 --> 00:35:31,900 would look like that. 624 00:35:31,900 --> 00:35:33,720 Well, let's look at what that actually 625 00:35:33,720 --> 00:35:36,450 looks like on the computer. 626 00:35:36,450 --> 00:35:39,320 Here I have a Lisp interaction set up. 627 00:35:39,320 --> 00:35:41,060 There's a editor. 628 00:35:41,060 --> 00:35:43,980 And on the top, I'm going to type some values and ask Lisp 629 00:35:43,980 --> 00:35:45,050 what they are. 630 00:35:45,050 --> 00:35:46,750 So for instance, I can say to Lisp, what's the 631 00:35:46,750 --> 00:35:49,370 value of that symbol? 632 00:35:49,370 --> 00:35:50,050 That's 3. 633 00:35:50,050 --> 00:35:51,850 And I ask Lisp to evaluate it. 634 00:35:51,850 --> 00:35:55,530 And there you see Lisp has returned on the bottom, and 635 00:35:55,530 --> 00:35:57,690 said, oh yeah, that's 3. 636 00:35:57,690 --> 00:36:06,490 Or I can say, what's the sum of 3 and 4 and 8? 637 00:36:06,490 --> 00:36:08,950 What's that combination? 638 00:36:08,950 --> 00:36:10,660 And ask Lisp to evaluate it. 639 00:36:10,660 --> 00:36:14,660 640 00:36:14,660 --> 00:36:16,246 That's 15. 641 00:36:16,246 --> 00:36:19,210 Or I can type in something more complicated. 642 00:36:19,210 --> 00:36:29,510 I can say, what's the sum of the product of 3 and the sum 643 00:36:29,510 --> 00:36:35,210 of 7 and 19.5? 644 00:36:35,210 --> 00:36:37,820 And you'll notice here that Lisp has something built in 645 00:36:37,820 --> 00:36:39,660 that helps me keep track of all these parentheses. 646 00:36:39,660 --> 00:36:42,260 Watch as I type the next closed parentheses, which is 647 00:36:42,260 --> 00:36:45,620 going to close the combination starting with the star. 648 00:36:45,620 --> 00:36:48,220 The opening one will flash. 649 00:36:48,220 --> 00:36:50,200 Here, I'll rub those out and do it again. 650 00:36:50,200 --> 00:36:53,590 Type close, and you see that closes the plus. 651 00:36:53,590 --> 00:36:57,910 Close again, that closes the star. 652 00:36:57,910 --> 00:36:59,570 Now I'm back to the sum, and maybe I'm going to 653 00:36:59,570 --> 00:37:01,480 add that all to 4. 654 00:37:01,480 --> 00:37:02,630 That closes the plus. 655 00:37:02,630 --> 00:37:05,750 Now I have a complete combination, and I can ask 656 00:37:05,750 --> 00:37:07,170 Lisp for the value of that. 657 00:37:07,170 --> 00:37:11,310 That kind of paren balancing is something that's built into 658 00:37:11,310 --> 00:37:13,630 a lot of Lisp systems to help you keep track, because it is 659 00:37:13,630 --> 00:37:16,760 kind of hard just by hand doing all these parentheses. 660 00:37:16,760 --> 00:37:20,520 There's another kind of convention for keeping track 661 00:37:20,520 --> 00:37:21,100 of parentheses. 662 00:37:21,100 --> 00:37:24,800 Let me write another complicated combination. 663 00:37:24,800 --> 00:37:33,170 Let's take the sum of the product of 3 and 5 and add 664 00:37:33,170 --> 00:37:34,090 that to something. 665 00:37:34,090 --> 00:37:37,510 And now what I'm going to do is I'm going to indent so that 666 00:37:37,510 --> 00:37:39,830 the operands are written vertically. 667 00:37:39,830 --> 00:37:47,250 Which the sum of that and the product of 47 and-- 668 00:37:47,250 --> 00:37:50,340 let's say the product of 47 with a 669 00:37:50,340 --> 00:37:54,520 difference of 20 and 6.8. 670 00:37:54,520 --> 00:37:58,236 That means subtract 6.8 from 20. 671 00:37:58,236 --> 00:38:00,050 And then you see the parentheses close. 672 00:38:00,050 --> 00:38:01,890 Close the minus. 673 00:38:01,890 --> 00:38:03,572 Close the star. 674 00:38:03,572 --> 00:38:05,150 And now let's get another operator. 675 00:38:05,150 --> 00:38:08,230 You see the Lisp editor here is indenting to the right 676 00:38:08,230 --> 00:38:12,660 position automatically to help me keep track. 677 00:38:12,660 --> 00:38:13,920 I'll do that again. 678 00:38:13,920 --> 00:38:16,220 I'll close that last parentheses again. 679 00:38:16,220 --> 00:38:17,470 You see it balances the plus. 680 00:38:17,470 --> 00:38:20,340 681 00:38:20,340 --> 00:38:24,100 Now I can say, what's the value of that? 682 00:38:24,100 --> 00:38:29,620 So those two things, indenting to the right level, which is 683 00:38:29,620 --> 00:38:34,230 called pretty printing, and flashing parentheses, are two 684 00:38:34,230 --> 00:38:37,120 things that a lot of Lisp systems have built in to help 685 00:38:37,120 --> 00:38:37,660 you keep track. 686 00:38:37,660 --> 00:38:38,910 And you should learn how to use them. 687 00:38:38,910 --> 00:38:42,020 688 00:38:42,020 --> 00:38:44,640 Well, those are the primitives. 689 00:38:44,640 --> 00:38:46,190 There's a means of combination. 690 00:38:46,190 --> 00:38:49,360 Now let's go up to the means of abstraction. 691 00:38:49,360 --> 00:38:52,400 I'd like to be able to take the idea that I do some 692 00:38:52,400 --> 00:38:54,820 combination like this, and abstract it and give it a 693 00:38:54,820 --> 00:38:57,300 simple name, so I can use that as an element. 694 00:38:57,300 --> 00:39:01,770 And I do that in Lisp with "define." So I can say, for 695 00:39:01,770 --> 00:39:14,515 example, define A to be the product of 5 and 5. 696 00:39:14,515 --> 00:39:17,936 697 00:39:17,936 --> 00:39:23,240 And now I could say, for example, to Lisp, what is the 698 00:39:23,240 --> 00:39:26,742 product of A and A? 699 00:39:26,742 --> 00:39:31,980 And this should be 25, and this should be 625. 700 00:39:31,980 --> 00:39:36,200 And then, crucial thing, I can now use A-- 701 00:39:36,200 --> 00:39:38,360 here I've used it in a combination-- 702 00:39:38,360 --> 00:39:41,770 but I could use that in other more complicated things that I 703 00:39:41,770 --> 00:39:43,440 name in turn. 704 00:39:43,440 --> 00:39:53,970 So I could say, define B to be the sum of, we'll say, A and 705 00:39:53,970 --> 00:40:00,260 the product of 5 and A. And then close the plus. 706 00:40:00,260 --> 00:40:03,470 707 00:40:03,470 --> 00:40:04,920 Let's take a look at that on the computer and 708 00:40:04,920 --> 00:40:07,850 see how that looks. 709 00:40:07,850 --> 00:40:10,515 So I'll just type what I wrote on the board. 710 00:40:10,515 --> 00:40:21,165 I could say, define A to be the product of 5 and 5. 711 00:40:21,165 --> 00:40:23,675 712 00:40:23,675 --> 00:40:25,640 And I'll tell that to Lisp. 713 00:40:25,640 --> 00:40:27,320 And notice what Lisp responded there with 714 00:40:27,320 --> 00:40:29,120 was an A in the bottom. 715 00:40:29,120 --> 00:40:31,680 In general, when you type in a definition in Lisp, it 716 00:40:31,680 --> 00:40:35,180 responds with the symbol being defined. 717 00:40:35,180 --> 00:40:39,200 Now I could say to Lisp, what is the product of A and A? 718 00:40:39,200 --> 00:40:42,266 719 00:40:42,266 --> 00:40:46,140 And it says that's 625. 720 00:40:46,140 --> 00:40:59,790 I can define B to be the sum of A and the product of 5 and 721 00:40:59,790 --> 00:41:03,110 A. Close a paren closes the star. 722 00:41:03,110 --> 00:41:04,600 Close the plus. 723 00:41:04,600 --> 00:41:11,030 Close the "define." Lisp says, OK, B, there on the bottom. 724 00:41:11,030 --> 00:41:13,110 And now I can say to Lisp, what's the value of B? 725 00:41:13,110 --> 00:41:17,100 726 00:41:17,100 --> 00:41:19,310 And I can say something more complicated, like what's the 727 00:41:19,310 --> 00:41:26,600 sum of A and the quotient of B and 5? 728 00:41:26,600 --> 00:41:30,430 That slash is divide, another primitive operator. 729 00:41:30,430 --> 00:41:33,830 I've divided B by 5, added it to A. Lisp 730 00:41:33,830 --> 00:41:36,830 says, OK, that's 55. 731 00:41:36,830 --> 00:41:39,810 So there's what it looks like. 732 00:41:39,810 --> 00:41:43,670 There's the basic means of defining something. 733 00:41:43,670 --> 00:41:47,870 It's the simplest kind of naming, but it's not really 734 00:41:47,870 --> 00:41:49,970 very powerful. 735 00:41:49,970 --> 00:41:51,760 See, what I'd really like to name-- 736 00:41:51,760 --> 00:41:53,510 remember, we're talking about general methods-- 737 00:41:53,510 --> 00:41:56,810 I'd like to name, oh, the general idea that, for 738 00:41:56,810 --> 00:42:11,440 example, I could multiply 5 by 5, or 6 by 6, or 1,001 by 739 00:42:11,440 --> 00:42:18,240 1,001, 1,001.7 by 1,001.7. 740 00:42:18,240 --> 00:42:22,350 I'd like to be able to name the general idea of 741 00:42:22,350 --> 00:42:23,970 multiplying something by itself. 742 00:42:23,970 --> 00:42:28,400 743 00:42:28,400 --> 00:42:28,960 Well, you know what that is. 744 00:42:28,960 --> 00:42:31,146 That's called squaring. 745 00:42:31,146 --> 00:42:43,640 And the way I can do that in Lisp is I can say, define to 746 00:42:43,640 --> 00:42:57,850 square something x, multiply x by itself. 747 00:42:57,850 --> 00:43:01,260 And then having done that, I could say to Lisp, for 748 00:43:01,260 --> 00:43:06,240 example, what's the square of 10? 749 00:43:06,240 --> 00:43:10,240 And Lisp will say 100. 750 00:43:10,240 --> 00:43:14,796 So now let's actually look at that a little more closely. 751 00:43:14,796 --> 00:43:17,040 Right, there's the definition of square. 752 00:43:17,040 --> 00:43:23,730 To square something, multiply it by itself. 753 00:43:23,730 --> 00:43:26,210 You see this x here. 754 00:43:26,210 --> 00:43:28,550 That x is kind of a pronoun, which is the something that 755 00:43:28,550 --> 00:43:31,380 I'm going to square. 756 00:43:31,380 --> 00:43:35,220 And what I do with it is I multiply x, I 757 00:43:35,220 --> 00:43:36,930 multiply it by itself. 758 00:43:36,930 --> 00:43:44,670 759 00:43:44,670 --> 00:43:44,775 OK. 760 00:43:44,775 --> 00:43:48,280 So there's the notation for defining a procedure. 761 00:43:48,280 --> 00:43:52,500 Actually, this is a little bit confusing, because this is 762 00:43:52,500 --> 00:43:53,830 sort of how I might use square. 763 00:43:53,830 --> 00:43:57,790 And I say square root of x or square root of 10, but it's 764 00:43:57,790 --> 00:44:00,300 not making it very clear that I'm actually naming something. 765 00:44:00,300 --> 00:44:02,970 766 00:44:02,970 --> 00:44:05,790 So let me write this definition in another way that 767 00:44:05,790 --> 00:44:06,770 makes it a little bit more clear 768 00:44:06,770 --> 00:44:08,420 that I'm naming something. 769 00:44:08,420 --> 00:44:28,250 I'll say, "define" square to be lambda of x times xx. 770 00:44:28,250 --> 00:44:36,550 771 00:44:36,550 --> 00:44:40,480 Here, I'm naming something square, just like over here, 772 00:44:40,480 --> 00:44:44,390 I'm naming something A. The thing that I'm naming square-- 773 00:44:44,390 --> 00:44:49,290 here, the thing I named A was the value of this combination. 774 00:44:49,290 --> 00:44:52,270 Here, the thing that I'm naming square is this thing 775 00:44:52,270 --> 00:44:55,610 that begins with lambda, and lambda is Lisp's way of saying 776 00:44:55,610 --> 00:44:56,860 make a procedure. 777 00:44:56,860 --> 00:45:00,150 778 00:45:00,150 --> 00:45:04,170 Let's look at that more closely on the slide. 779 00:45:04,170 --> 00:45:07,410 The way I read that definition is to say, I define square to 780 00:45:07,410 --> 00:45:09,910 be make a procedure-- 781 00:45:09,910 --> 00:45:12,730 782 00:45:12,730 --> 00:45:14,010 that's what the lambda is-- 783 00:45:14,010 --> 00:45:19,220 make a procedure with an argument named x. 784 00:45:19,220 --> 00:45:22,030 And what it does is return the results of 785 00:45:22,030 --> 00:45:24,920 multiplying x by itself. 786 00:45:24,920 --> 00:45:32,380 Now, in general, we're going to be using this top form of 787 00:45:32,380 --> 00:45:35,050 defining, just because it's a little bit more convenient. 788 00:45:35,050 --> 00:45:38,750 But don't lose sight of the fact that it's really this. 789 00:45:38,750 --> 00:45:41,530 In fact, as far as the Lisp interpreter's concerned, 790 00:45:41,530 --> 00:45:44,830 there's no difference between typing this to it and typing 791 00:45:44,830 --> 00:45:46,460 this to it. 792 00:45:46,460 --> 00:45:54,380 And there's a word for that, sort of syntactic sugar. 793 00:45:54,380 --> 00:45:58,400 What syntactic sugar means, it's having somewhat more 794 00:45:58,400 --> 00:46:01,060 convenient surface forms for typing something. 795 00:46:01,060 --> 00:46:04,470 So this is just really syntactic sugar for this 796 00:46:04,470 --> 00:46:07,310 underlying Greek thing with the lambda. 797 00:46:07,310 --> 00:46:09,710 And the reason you should remember that is don't forget 798 00:46:09,710 --> 00:46:12,430 that, when I write something like this, I'm 799 00:46:12,430 --> 00:46:14,380 really naming something. 800 00:46:14,380 --> 00:46:17,040 I'm naming something square, and the something that I'm 801 00:46:17,040 --> 00:46:21,620 naming square is a procedure that's getting constructed. 802 00:46:21,620 --> 00:46:24,820 Well, let's look at that on the computer, too. 803 00:46:24,820 --> 00:46:30,660 So I'll come and I'll say, define square of 804 00:46:30,660 --> 00:46:34,670 x to be times xx. 805 00:46:34,670 --> 00:46:49,570 806 00:46:49,570 --> 00:46:53,042 Now I'll tell Lisp that. 807 00:46:53,042 --> 00:46:56,580 It says "square." See, I've named something "square." Now, 808 00:46:56,580 --> 00:47:00,760 having done that, I can ask Lisp for, what's 809 00:47:00,760 --> 00:47:05,230 the square of 1,001? 810 00:47:05,230 --> 00:47:14,920 Or in general, I could say, what's the square of the sum 811 00:47:14,920 --> 00:47:17,340 of 5 and 7? 812 00:47:17,340 --> 00:47:22,532 813 00:47:22,532 --> 00:47:25,190 The square of 12's 144. 814 00:47:25,190 --> 00:47:28,080 Or I can use square itself as an element in some 815 00:47:28,080 --> 00:47:28,680 combination. 816 00:47:28,680 --> 00:47:36,240 I can say, what's the sum of the square of 3 and 817 00:47:36,240 --> 00:47:37,490 the square of 4? 818 00:47:37,490 --> 00:47:42,480 819 00:47:42,480 --> 00:47:44,950 9 and 16 is 25. 820 00:47:44,950 --> 00:47:49,580 Or I can use square as an element in some much more 821 00:47:49,580 --> 00:47:50,390 complicated thing. 822 00:47:50,390 --> 00:47:53,032 I can say, what's the square of, the sqare of, 823 00:47:53,032 --> 00:48:07,016 the square of 1,001? 824 00:48:07,016 --> 00:48:11,160 And there's the square of the square of the square of 1,001. 825 00:48:11,160 --> 00:48:15,620 Or I can say to Lisp, what is square itself? 826 00:48:15,620 --> 00:48:17,040 What's the value of that? 827 00:48:17,040 --> 00:48:21,040 And Lisp returns some conventional way of telling me 828 00:48:21,040 --> 00:48:22,200 that that's a procedure. 829 00:48:22,200 --> 00:48:24,990 It says, "compound procedure square." Remember, the value 830 00:48:24,990 --> 00:48:30,050 of square is this procedure, and the thing with the stars 831 00:48:30,050 --> 00:48:33,810 and the brackets are just Lisp's conventional way of 832 00:48:33,810 --> 00:48:37,010 describing that. 833 00:48:37,010 --> 00:48:40,830 Let's look at two more examples of defining. 834 00:48:40,830 --> 00:48:45,020 835 00:48:45,020 --> 00:48:47,210 Here are two more procedures. 836 00:48:47,210 --> 00:48:51,860 I can define the average of x and y to be the sum of x and y 837 00:48:51,860 --> 00:48:54,460 divided by 2. 838 00:48:54,460 --> 00:49:00,830 Or having had average and mean square, having had average and 839 00:49:00,830 --> 00:49:03,970 square, I can use that to talk about the mean square of 840 00:49:03,970 --> 00:49:08,325 something, which is the average of the square of x and 841 00:49:08,325 --> 00:49:10,790 the square of y. 842 00:49:10,790 --> 00:49:13,870 So for example, having done that, I could say, what's the 843 00:49:13,870 --> 00:49:24,915 mean square of 2 and 3? 844 00:49:24,915 --> 00:49:29,530 And I should get the average of 4 and 9, which is 6.5. 845 00:49:29,530 --> 00:49:32,970 846 00:49:32,970 --> 00:49:37,000 The key thing here is that, having defined square, I can 847 00:49:37,000 --> 00:49:38,560 use it as if it were primitive. 848 00:49:38,560 --> 00:49:41,410 849 00:49:41,410 --> 00:49:45,200 So if we look here on the slide, if I look at mean 850 00:49:45,200 --> 00:49:50,910 square, the person defining mean square doesn't have to 851 00:49:50,910 --> 00:49:54,660 know, at this point, whether square was something built 852 00:49:54,660 --> 00:49:57,540 into the language or whether it was a 853 00:49:57,540 --> 00:49:59,600 procedure that was defined. 854 00:49:59,600 --> 00:50:04,040 And that's a key thing in Lisp, that you do not make 855 00:50:04,040 --> 00:50:08,230 arbitrary distinctions between things that happen to be 856 00:50:08,230 --> 00:50:10,400 primitive in the language and things that 857 00:50:10,400 --> 00:50:12,740 happen to be built in. 858 00:50:12,740 --> 00:50:14,750 A person using that shouldn't even have to know. 859 00:50:14,750 --> 00:50:17,800 So the things you construct get used with all the power 860 00:50:17,800 --> 00:50:19,700 and flexibility as if they were primitives. 861 00:50:19,700 --> 00:50:21,470 In fact, you can drive that home by looking on the 862 00:50:21,470 --> 00:50:24,750 computer one more time. 863 00:50:24,750 --> 00:50:26,680 We talked about plus. 864 00:50:26,680 --> 00:50:29,920 And in fact, if I come here on the computer screen and say, 865 00:50:29,920 --> 00:50:31,745 what is the value of plus? 866 00:50:31,745 --> 00:50:34,380 867 00:50:34,380 --> 00:50:36,120 Notice what Lisp types out. 868 00:50:36,120 --> 00:50:38,230 On the bottom there, it typed out, "compound procedure 869 00:50:38,230 --> 00:50:43,070 plus." Because, in this system, it turns out that the 870 00:50:43,070 --> 00:50:45,770 addition operator is itself a compound procedure. 871 00:50:45,770 --> 00:50:48,140 And if I didn't just type that in, you'd never know that, and 872 00:50:48,140 --> 00:50:49,710 it wouldn't make any difference anyway. 873 00:50:49,710 --> 00:50:50,240 We don't care. 874 00:50:50,240 --> 00:50:52,500 It's below the level of the abstraction that 875 00:50:52,500 --> 00:50:54,120 we're dealing with. 876 00:50:54,120 --> 00:50:57,230 So the key thing is you cannot tell, should not be able to 877 00:50:57,230 --> 00:51:00,910 tell, in general, the difference between things that 878 00:51:00,910 --> 00:51:03,590 are built in and things that are compound. 879 00:51:03,590 --> 00:51:04,160 Why is that? 880 00:51:04,160 --> 00:51:06,630 Because the things that are compound have an abstraction 881 00:51:06,630 --> 00:51:09,420 wrapper wrapped around them. 882 00:51:09,420 --> 00:51:12,510 We've seen almost all the elements of Lisp now. 883 00:51:12,510 --> 00:51:15,090 There's only one more we have to look at, and that is how to 884 00:51:15,090 --> 00:51:16,510 make a case analysis. 885 00:51:16,510 --> 00:51:18,760 Let me show you what I mean. 886 00:51:18,760 --> 00:51:22,550 We might want to think about the mathematical definition of 887 00:51:22,550 --> 00:51:23,740 the absolute value functions. 888 00:51:23,740 --> 00:51:30,520 I might say the absolute value of x is the function which has 889 00:51:30,520 --> 00:51:35,670 the property that it's negative of x. 890 00:51:35,670 --> 00:51:42,580 For x less than 0, it's 0 for x equal to 0. 891 00:51:42,580 --> 00:51:46,360 And it's x for x greater than 0. 892 00:51:46,360 --> 00:51:49,190 893 00:51:49,190 --> 00:51:51,490 And Lisp has a way of making case analyses. 894 00:51:51,490 --> 00:51:55,210 Let me define for you absolute value. 895 00:51:55,210 --> 00:52:03,080 Say define the absolute value of x is conditional. 896 00:52:03,080 --> 00:52:05,075 This means case analysis, COND. 897 00:52:05,075 --> 00:52:08,773 898 00:52:08,773 --> 00:52:18,760 If x is less than 0, the answer is negate x. 899 00:52:18,760 --> 00:52:22,990 900 00:52:22,990 --> 00:52:24,290 What I've written here is a clause. 901 00:52:24,290 --> 00:52:29,490 902 00:52:29,490 --> 00:52:33,818 This whole thing is a conditional clause, 903 00:52:33,818 --> 00:52:36,380 and it has two parts. 904 00:52:36,380 --> 00:52:44,760 This part here is a predicate or a condition. 905 00:52:44,760 --> 00:52:45,640 That's a condition. 906 00:52:45,640 --> 00:52:47,680 And the condition is expressed by something called a 907 00:52:47,680 --> 00:52:51,170 predicate, and a predicate in Lisp is some sort of thing 908 00:52:51,170 --> 00:52:53,440 that returns either true or false. 909 00:52:53,440 --> 00:52:55,490 And you see Lisp has a primitive procedure, 910 00:52:55,490 --> 00:53:00,510 less-than, that tests whether something is true or false. 911 00:53:00,510 --> 00:53:06,940 And the other part of a clause is an action or a thing to do, 912 00:53:06,940 --> 00:53:07,930 in the case where that's true. 913 00:53:07,930 --> 00:53:12,130 And here, what I'm doing is negating x. 914 00:53:12,130 --> 00:53:13,300 The negation operator, the minus sign in Lisp is 915 00:53:13,300 --> 00:53:14,550 a little bit funny. 916 00:53:14,550 --> 00:53:17,880 917 00:53:17,880 --> 00:53:19,186 If there's two or more arguments, if there's two 918 00:53:19,186 --> 00:53:21,740 arguments it subtracts the second one from the first, and 919 00:53:21,740 --> 00:53:22,380 we saw that. 920 00:53:22,380 --> 00:53:25,280 And if there's one argument, it negates it. 921 00:53:25,280 --> 00:53:27,700 So this corresponds to that. 922 00:53:27,700 --> 00:53:28,960 And then there's another COND clause. 923 00:53:28,960 --> 00:53:34,630 It says, in the case where x is equal to 0, 924 00:53:34,630 --> 00:53:37,482 the answer is 0. 925 00:53:37,482 --> 00:53:43,480 And in the case where x is greater than 0, 926 00:53:43,480 --> 00:53:45,430 the answer is x. 927 00:53:45,430 --> 00:53:46,790 Close that clause. 928 00:53:46,790 --> 00:53:48,250 Close the COND. 929 00:53:48,250 --> 00:53:48,920 Close the definition. 930 00:53:48,920 --> 00:53:51,110 And there's the definition of absolute value. 931 00:53:51,110 --> 00:53:53,560 And you see it's the case analysis that looks very much 932 00:53:53,560 --> 00:53:55,265 like the case analysis you use in mathematics. 933 00:53:55,265 --> 00:53:58,500 934 00:53:58,500 --> 00:54:02,300 There's a somewhat different way of writing a restricted 935 00:54:02,300 --> 00:54:03,090 case analysis. 936 00:54:03,090 --> 00:54:05,520 Often, you have a case analysis where you only have 937 00:54:05,520 --> 00:54:08,810 one case, where you test something, and then depending 938 00:54:08,810 --> 00:54:11,000 on whether it's true or false, you do something. 939 00:54:11,000 --> 00:54:16,150 And here's another definition of absolute value which looks 940 00:54:16,150 --> 00:54:21,010 almost the same, which says, if x is less than 0, the 941 00:54:21,010 --> 00:54:24,380 result is negate x. 942 00:54:24,380 --> 00:54:25,960 Otherwise, the answer is x. 943 00:54:25,960 --> 00:54:27,120 And we'll be using "if" a lot. 944 00:54:27,120 --> 00:54:30,650 But again, the thing to remember is that this form of 945 00:54:30,650 --> 00:54:35,130 absolute value that you're looking at here, and then this 946 00:54:35,130 --> 00:54:37,650 one over here that I wrote on the board, are 947 00:54:37,650 --> 00:54:39,040 essentially the same. 948 00:54:39,040 --> 00:54:40,700 And "if" and COND are-- 949 00:54:40,700 --> 00:54:42,020 well, whichever way you like it. 950 00:54:42,020 --> 00:54:45,100 You can think of COND as syntactic sugar for "if," or 951 00:54:45,100 --> 00:54:47,375 you can think of "if" as syntactic sugar for COND, and 952 00:54:47,375 --> 00:54:48,810 it doesn't make any difference. 953 00:54:48,810 --> 00:54:51,400 The person implementing a Lisp system will pick one and 954 00:54:51,400 --> 00:54:52,840 implement the other in terms of that. 955 00:54:52,840 --> 00:54:54,570 And it doesn't matter which one you pick. 956 00:54:54,570 --> 00:55:02,660 957 00:55:02,660 --> 00:55:05,640 Why don't we break now, and then take some questions. 958 00:55:05,640 --> 00:55:11,760 How come sometimes when I write define, I put an open 959 00:55:11,760 --> 00:55:16,790 paren here and say, define open paren something or other, 960 00:55:16,790 --> 00:55:19,480 and sometimes when I write this, I 961 00:55:19,480 --> 00:55:22,330 don't put an open paren? 962 00:55:22,330 --> 00:55:27,550 The answer is, this particular form of "define," where you 963 00:55:27,550 --> 00:55:30,850 say define some expression, is this very special thing for 964 00:55:30,850 --> 00:55:33,630 defining procedures. 965 00:55:33,630 --> 00:55:37,900 But again, what it really means is I'm defining this 966 00:55:37,900 --> 00:55:41,350 symbol, square, to be that. 967 00:55:41,350 --> 00:55:44,810 So the way you should think about it is what "define" does 968 00:55:44,810 --> 00:55:48,330 is you write "define," and the second thing you write is the 969 00:55:48,330 --> 00:55:49,830 symbol here-- no open paren-- 970 00:55:49,830 --> 00:55:54,610 the symbol you're defining and what you're defining it to be. 971 00:55:54,610 --> 00:55:57,300 That's like here and like here. 972 00:55:57,300 --> 00:56:01,480 That's sort of the basic way you use "define." And then, 973 00:56:01,480 --> 00:56:05,040 there's this special syntactic trick which allows you to 974 00:56:05,040 --> 00:56:08,140 define procedures that look like this. 975 00:56:08,140 --> 00:56:10,690 So the difference is, it's whether or not you're defining 976 00:56:10,690 --> 00:56:11,755 a procedure. 977 00:56:11,755 --> 00:56:38,110 [MUSIC PLAYING] 978 00:56:38,110 --> 00:56:42,600 Well, believe it or not, you actually now know enough Lisp 979 00:56:42,600 --> 00:56:46,610 to write essentially any numerical procedure that you'd 980 00:56:46,610 --> 00:56:49,470 write in a language like FORTRAN or Basic or whatever, 981 00:56:49,470 --> 00:56:51,656 or, essentially, any other language. 982 00:56:51,656 --> 00:56:55,190 And you're probably saying, that's not believable, because 983 00:56:55,190 --> 00:56:56,890 you know that these languages have things like "for 984 00:56:56,890 --> 00:57:00,910 statements," and "do until while" or something. 985 00:57:00,910 --> 00:57:04,745 But we don't really need any of that. 986 00:57:04,745 --> 00:57:06,220 In fact, we're not going to use any of 987 00:57:06,220 --> 00:57:08,180 that in this course. 988 00:57:08,180 --> 00:57:10,410 Let me show you. 989 00:57:10,410 --> 00:57:14,400 Again, looking back at square root, let's go back to this 990 00:57:14,400 --> 00:57:18,505 square root algorithm of Heron of Alexandria. 991 00:57:18,505 --> 00:57:20,000 Remember what that said. 992 00:57:20,000 --> 00:57:23,060 It said, to find an approximation to the square 993 00:57:23,060 --> 00:57:28,730 root of X, you make a guess, you improve that guess by 994 00:57:28,730 --> 00:57:32,900 averaging the guess and X over the guess. 995 00:57:32,900 --> 00:57:36,382 You keep improving that until the guess is good enough. 996 00:57:36,382 --> 00:57:38,460 I already alluded to the idea. 997 00:57:38,460 --> 00:57:44,650 The idea is that, if the initial guess that you took 998 00:57:44,650 --> 00:57:48,430 was actually equal to the square root of X, then G here 999 00:57:48,430 --> 00:57:52,760 would be equal to X/G. 1000 00:57:52,760 --> 00:57:54,400 So if you hit the square root, averaging them 1001 00:57:54,400 --> 00:57:55,630 wouldn't change it. 1002 00:57:55,630 --> 00:57:59,160 If the G that you picked was larger than the square root of 1003 00:57:59,160 --> 00:58:03,280 X, then X/G will be smaller than the square root of X, so 1004 00:58:03,280 --> 00:58:05,890 that when you average G and X/G, you get 1005 00:58:05,890 --> 00:58:09,130 something in between. 1006 00:58:09,130 --> 00:58:11,790 So if you pick a G that's too small, your 1007 00:58:11,790 --> 00:58:13,040 answer will be too large. 1008 00:58:13,040 --> 00:58:17,190 If you pick a G that's too large, if your G is larger 1009 00:58:17,190 --> 00:58:19,420 than the square root of X and X/G will be smaller than the 1010 00:58:19,420 --> 00:58:21,110 square root of X. 1011 00:58:21,110 --> 00:58:24,460 So averaging always gives you something in between. 1012 00:58:24,460 --> 00:58:27,450 And then, it's not quite trivial, but it's possible to 1013 00:58:27,450 --> 00:58:31,050 show that, in fact, if G misses the square root of X by 1014 00:58:31,050 --> 00:58:34,220 a little bit, the average of G and X/G will actually keep 1015 00:58:34,220 --> 00:58:37,800 getting closer to the square root of X. So if you keep 1016 00:58:37,800 --> 00:58:40,140 doing this enough, you'll eventually get as 1017 00:58:40,140 --> 00:58:41,680 close as you want. 1018 00:58:41,680 --> 00:58:44,170 And then there's another fact, that you can always start out 1019 00:58:44,170 --> 00:58:49,210 this process by using 1 as an initial guess. 1020 00:58:49,210 --> 00:58:52,440 And it'll always converge to the square root of X. So 1021 00:58:52,440 --> 00:58:55,610 that's this method of successive averaging due to 1022 00:58:55,610 --> 00:58:56,660 Heron of Alexandria. 1023 00:58:56,660 --> 00:59:00,250 Let's write it in Lisp. 1024 00:59:00,250 --> 00:59:05,770 Well, the central idea is, what does it mean to try a 1025 00:59:05,770 --> 00:59:07,940 guess for the square root of X? 1026 00:59:07,940 --> 00:59:09,780 Let's write that. 1027 00:59:09,780 --> 00:59:24,310 So we'll say, define to try a guess for the square root of 1028 00:59:24,310 --> 00:59:27,750 X, what do we do? 1029 00:59:27,750 --> 00:59:44,130 We'll say, if the guess is good enough to be a guess for 1030 00:59:44,130 --> 00:59:48,330 the square root of X, then, as an answer, 1031 00:59:48,330 --> 00:59:51,550 we'll take the guess. 1032 00:59:51,550 --> 00:59:58,620 Otherwise, we will try the improved guess. 1033 00:59:58,620 --> 01:00:05,400 We'll improve that guess for the square root of X, and 1034 01:00:05,400 --> 01:00:09,690 we'll try that as a guess for the square root of X. Close 1035 01:00:09,690 --> 01:00:13,510 the "try." Close the "if." Close the "define." So that's 1036 01:00:13,510 --> 01:00:15,820 how we try a guess. 1037 01:00:15,820 --> 01:00:18,050 And then, the next part of the process said, in order to 1038 01:00:18,050 --> 01:00:28,370 compute square roots, we'll say, define to compute the 1039 01:00:28,370 --> 01:00:35,290 square root of X, we will try 1 as a guess for the square 1040 01:00:35,290 --> 01:00:40,280 root of X. Well, we have to define a couple more things. 1041 01:00:40,280 --> 01:00:43,770 We have to say, how is a guess good enough? 1042 01:00:43,770 --> 01:00:45,545 And how do we improve a guess? 1043 01:00:45,545 --> 01:00:47,380 So let's look at that. 1044 01:00:47,380 --> 01:00:53,650 The algorithm to improve a guess for the square root of 1045 01:00:53,650 --> 01:00:55,640 X, we average-- 1046 01:00:55,640 --> 01:00:57,000 that was the algorithm-- 1047 01:00:57,000 --> 01:01:00,680 we average the guess with the quotient of 1048 01:01:00,680 --> 01:01:03,030 dividing X by the guess. 1049 01:01:03,030 --> 01:01:05,810 That's how we improve a guess. 1050 01:01:05,810 --> 01:01:07,720 And to tell whether a guess is good enough, well, we have to 1051 01:01:07,720 --> 01:01:09,530 decide something. 1052 01:01:09,530 --> 01:01:11,510 This is supposed to be a guess for the square root of X, so 1053 01:01:11,510 --> 01:01:14,700 one possible thing you can do is say, when you take that 1054 01:01:14,700 --> 01:01:19,110 guess and square it, do you get something very close to X? 1055 01:01:19,110 --> 01:01:22,870 So one way to say that is to say, I square the guess, 1056 01:01:22,870 --> 01:01:26,900 subtract X from that, and see if the absolute value of that 1057 01:01:26,900 --> 01:01:31,200 whole thing is less than some small number, which depends on 1058 01:01:31,200 --> 01:01:32,450 my purposes. 1059 01:01:32,450 --> 01:01:35,080 1060 01:01:35,080 --> 01:01:40,410 So there's a complete procedure for how to compute 1061 01:01:40,410 --> 01:01:42,830 the square root of X. Let's look at the structure of that 1062 01:01:42,830 --> 01:01:44,080 a little bit. 1063 01:01:44,080 --> 01:01:47,970 1064 01:01:47,970 --> 01:01:49,100 I have the whole thing. 1065 01:01:49,100 --> 01:01:55,370 I have the notion of how to compute a square root. 1066 01:01:55,370 --> 01:01:56,960 That's some kind of module. 1067 01:01:56,960 --> 01:01:58,580 That's some kind of black box. 1068 01:01:58,580 --> 01:02:07,340 It's defined in terms of how to try a guess for the square 1069 01:02:07,340 --> 01:02:09,090 root of X. 1070 01:02:09,090 --> 01:02:15,110 "Try" is defined in terms of, well, telling whether 1071 01:02:15,110 --> 01:02:16,640 something is good enough and telling 1072 01:02:16,640 --> 01:02:18,680 how to improve something. 1073 01:02:18,680 --> 01:02:19,800 So good enough. 1074 01:02:19,800 --> 01:02:30,790 "Try" is defined in terms of "good enough" and "improve." 1075 01:02:30,790 --> 01:02:32,170 And let's see what else I fill in. 1076 01:02:32,170 --> 01:02:34,640 Well, I'll go down this tree. 1077 01:02:34,640 --> 01:02:36,040 "Good enough" was defined in terms of 1078 01:02:36,040 --> 01:02:37,930 absolute value, and square. 1079 01:02:37,930 --> 01:02:40,910 1080 01:02:40,910 --> 01:02:43,290 And improve was defined in terms of something called 1081 01:02:43,290 --> 01:02:47,340 averaging and then some other primitive operator. 1082 01:02:47,340 --> 01:02:49,530 Square root's defined in terms of "try." "Try" is defined in 1083 01:02:49,530 --> 01:02:53,860 terms of "good enough" and "improve," 1084 01:02:53,860 --> 01:02:55,410 but also "try" itself. 1085 01:02:55,410 --> 01:03:02,750 So "try" is also defined in terms of how to try itself. 1086 01:03:02,750 --> 01:03:06,240 Well, that may give you some problems. Your high school 1087 01:03:06,240 --> 01:03:10,680 geometry teacher probably told you that it's naughty to try 1088 01:03:10,680 --> 01:03:13,360 and define things in terms of themselves, because it doesn't 1089 01:03:13,360 --> 01:03:13,810 make sense. 1090 01:03:13,810 --> 01:03:16,440 But that's false. 1091 01:03:16,440 --> 01:03:18,730 Sometimes it makes perfect sense to define things in 1092 01:03:18,730 --> 01:03:20,210 terms of themselves. 1093 01:03:20,210 --> 01:03:22,918 And this is the case. 1094 01:03:22,918 --> 01:03:24,150 And we can look at that. 1095 01:03:24,150 --> 01:03:28,140 We could write down what this means, and say, suppose I 1096 01:03:28,140 --> 01:03:30,100 asked Lisp what the square root of 2 is. 1097 01:03:30,100 --> 01:03:32,690 1098 01:03:32,690 --> 01:03:35,710 What's the square root of 2 mean? 1099 01:03:35,710 --> 01:03:42,700 Well, that means I try 1 as a guess for the 1100 01:03:42,700 --> 01:03:43,950 square root of 2. 1101 01:03:43,950 --> 01:03:47,100 1102 01:03:47,100 --> 01:03:47,760 Now I look. 1103 01:03:47,760 --> 01:03:50,000 I say, gee, is 1 a good enough guess for the 1104 01:03:50,000 --> 01:03:51,140 square root of 2? 1105 01:03:51,140 --> 01:03:54,140 And that depends on the test that "good enough" does. 1106 01:03:54,140 --> 01:03:57,240 And in this case, "good enough" will say, no, 1 is not 1107 01:03:57,240 --> 01:03:59,740 a good enough guess for the square root of 2. 1108 01:03:59,740 --> 01:04:10,350 So that will reduce to saying, I have to try an improved-- 1109 01:04:10,350 --> 01:04:15,910 improve 1 as a guess for the square root of 2, and try that 1110 01:04:15,910 --> 01:04:19,110 as a guess for the square root of 2. 1111 01:04:19,110 --> 01:04:22,350 Improving 1 as a guess for the square root of 2 means I 1112 01:04:22,350 --> 01:04:27,270 average 1 and 2 divided by 1. 1113 01:04:27,270 --> 01:04:29,550 So this is going to be average. 1114 01:04:29,550 --> 01:04:37,830 This piece here will be the average of 1 and the 1115 01:04:37,830 --> 01:04:40,930 quotient of 2 by 1. 1116 01:04:40,930 --> 01:04:44,910 That's this piece here. 1117 01:04:44,910 --> 01:04:46,160 And this is 1.5. 1118 01:04:46,160 --> 01:04:49,060 1119 01:04:49,060 --> 01:04:53,670 So this square root of 2 reduces to trying 1 for the 1120 01:04:53,670 --> 01:05:03,370 square root of 2, which reduces to trying 1.5 as a 1121 01:05:03,370 --> 01:05:06,220 guess for the square root of 2. 1122 01:05:06,220 --> 01:05:07,880 So that makes sense. 1123 01:05:07,880 --> 01:05:09,650 Let's look at the rest of the process. 1124 01:05:09,650 --> 01:05:14,890 If I try 1.5, that reduces. 1125 01:05:14,890 --> 01:05:18,210 1.5 turns out to be not good enough as a guess for the 1126 01:05:18,210 --> 01:05:20,130 square root of 2. 1127 01:05:20,130 --> 01:05:23,340 So that reduces to trying the average of 1.5 and 2 divided 1128 01:05:23,340 --> 01:05:28,200 by 1.5 as a guess for the square root of 2. 1129 01:05:28,200 --> 01:05:31,110 That average turns out to be 1.333. 1130 01:05:31,110 --> 01:05:34,215 So this whole thing reduces to trying 1.333 as a guess for 1131 01:05:34,215 --> 01:05:35,130 the square root of 2. 1132 01:05:35,130 --> 01:05:37,910 And then so on. 1133 01:05:37,910 --> 01:05:40,750 That reduces to another called a "good enough," 1.4 1134 01:05:40,750 --> 01:05:41,630 something or other. 1135 01:05:41,630 --> 01:05:45,160 And then it keeps going until the process finally stops with 1136 01:05:45,160 --> 01:05:47,780 something that "good enough" thinks is good enough, which, 1137 01:05:47,780 --> 01:05:52,500 in this case, is 1.4142 something or other. 1138 01:05:52,500 --> 01:05:55,890 So the process makes perfect sense. 1139 01:05:55,890 --> 01:05:59,710 1140 01:05:59,710 --> 01:06:02,620 This, by the way, is called a recursive definition. 1141 01:06:02,620 --> 01:06:14,410 1142 01:06:14,410 --> 01:06:19,470 And the ability to make recursive definitions is a 1143 01:06:19,470 --> 01:06:20,710 source of incredible power. 1144 01:06:20,710 --> 01:06:24,040 And as you can already see I've hinted at, it's the thing 1145 01:06:24,040 --> 01:06:27,160 that effectively allows you to do these infinite computations 1146 01:06:27,160 --> 01:06:30,730 that go on until something is true, without having any other 1147 01:06:30,730 --> 01:06:33,235 constricts other than the ability to call a procedure. 1148 01:06:33,235 --> 01:06:35,890 1149 01:06:35,890 --> 01:06:37,970 Well, let's see, there's one more thing. 1150 01:06:37,970 --> 01:06:43,210 Let me show you a variant of this definition of square root 1151 01:06:43,210 --> 01:06:46,300 here on the slide. 1152 01:06:46,300 --> 01:06:48,320 Here's sort of the same thing. 1153 01:06:48,320 --> 01:06:51,430 What I've done here is packaged the definitions of 1154 01:06:51,430 --> 01:06:55,340 "improve" and "good enough" and "try" inside "square 1155 01:06:55,340 --> 01:06:59,760 root." So, in effect, what I've done is I've built a 1156 01:06:59,760 --> 01:07:01,860 square root box. 1157 01:07:01,860 --> 01:07:07,320 So I've built a box that's the square root procedure that 1158 01:07:07,320 --> 01:07:08,150 someone can use. 1159 01:07:08,150 --> 01:07:11,910 They might put in 36 and get out 6. 1160 01:07:11,910 --> 01:07:15,080 And then, packaged inside this box are the definitions of 1161 01:07:15,080 --> 01:07:26,530 "try" and "good enough" and "improve." 1162 01:07:26,530 --> 01:07:28,260 So they're hidden inside this box. 1163 01:07:28,260 --> 01:07:32,010 And the reason for doing that is that, if someone's using 1164 01:07:32,010 --> 01:07:34,920 this square root, if George is using this square root, George 1165 01:07:34,920 --> 01:07:39,180 probably doesn't care very much that, when I implemented 1166 01:07:39,180 --> 01:07:42,600 square root, I had things inside there called "try" and 1167 01:07:42,600 --> 01:07:48,150 "good enough" and "improve." And in fact, Harry might have 1168 01:07:48,150 --> 01:07:50,300 a cube root procedure that has "try" and "good enough" and 1169 01:07:50,300 --> 01:07:53,260 "improve." And in order to not get the whole system confused, 1170 01:07:53,260 --> 01:07:55,430 it'd be good for Harry to package his internal 1171 01:07:55,430 --> 01:07:58,320 procedures inside his cube root procedure. 1172 01:07:58,320 --> 01:08:00,970 Well, this is called block structure, this particular way 1173 01:08:00,970 --> 01:08:09,940 of packaging internals inside of a definition. 1174 01:08:09,940 --> 01:08:13,040 And let's go back and look at the slide again. 1175 01:08:13,040 --> 01:08:17,720 The way to read this kind of procedure is to say, to define 1176 01:08:17,720 --> 01:08:23,010 "square root," well, inside that definition, I'll have the 1177 01:08:23,010 --> 01:08:26,479 definition of an "improve" and the definition of "good 1178 01:08:26,479 --> 01:08:31,149 enough" and the definition of "try." And then, subject to 1179 01:08:31,149 --> 01:08:36,010 those definitions, the way I do square root is to try 1. 1180 01:08:36,010 --> 01:08:38,310 And notice here, I don't have to say 1 as a guess for the 1181 01:08:38,310 --> 01:08:41,290 square root of X, because since it's all inside the 1182 01:08:41,290 --> 01:08:44,270 square root, it sort of has this X known. 1183 01:08:44,270 --> 01:08:54,770 1184 01:08:54,770 --> 01:08:56,510 Let me summarize. 1185 01:08:56,510 --> 01:08:59,890 We started out with the idea that what we're going to be 1186 01:08:59,890 --> 01:09:04,960 doing is expressing imperative knowledge. 1187 01:09:04,960 --> 01:09:08,960 And in fact, here's a slide that summarizes the way we 1188 01:09:08,960 --> 01:09:09,680 looked at Lisp. 1189 01:09:09,680 --> 01:09:13,609 We started out by looking at some primitive elements in 1190 01:09:13,609 --> 01:09:17,609 addition and multiplication, some predicates for testing 1191 01:09:17,609 --> 01:09:19,630 whether something is less-than or something's equal. 1192 01:09:19,630 --> 01:09:22,330 And in fact, we saw really sneakily in the system we're 1193 01:09:22,330 --> 01:09:25,160 actually using, these aren't actually primitives, but it 1194 01:09:25,160 --> 01:09:26,550 doesn't matter. 1195 01:09:26,550 --> 01:09:28,120 What matters is we're going to use them as if they're 1196 01:09:28,120 --> 01:09:28,510 primitives. 1197 01:09:28,510 --> 01:09:30,220 We're not going to look inside. 1198 01:09:30,220 --> 01:09:34,540 We also have some primitive data and some numbers. 1199 01:09:34,540 --> 01:09:36,830 We saw some means of composition, means of 1200 01:09:36,830 --> 01:09:41,300 combination, the basic one being composing functions and 1201 01:09:41,300 --> 01:09:44,840 building combinations with operators and operands. 1202 01:09:44,840 --> 01:09:47,600 And there were some other things, like COND and "if" and 1203 01:09:47,600 --> 01:09:53,790 "define." But the main thing about "define," in particular, 1204 01:09:53,790 --> 01:09:55,710 was that it was the means of abstraction. 1205 01:09:55,710 --> 01:09:57,670 It was the way that we name things. 1206 01:09:57,670 --> 01:09:59,770 You can also see from this slide not only where we've 1207 01:09:59,770 --> 01:10:01,450 been, but holes we have to fill in. 1208 01:10:01,450 --> 01:10:03,930 At some point, we'll have to talk about how you combine 1209 01:10:03,930 --> 01:10:07,720 primitive data to get compound data, and how you abstract 1210 01:10:07,720 --> 01:10:11,950 data so you can use large globs of data as 1211 01:10:11,950 --> 01:10:13,900 if they were primitive. 1212 01:10:13,900 --> 01:10:16,370 So that's where we're going. 1213 01:10:16,370 --> 01:10:20,790 But before we do that, for the next couple of lectures we're 1214 01:10:20,790 --> 01:10:25,720 going to be talking about, first of all, how it is that 1215 01:10:25,720 --> 01:10:28,900 you make a link between these procedures we write and the 1216 01:10:28,900 --> 01:10:32,040 processes that happen in the machine. 1217 01:10:32,040 --> 01:10:36,210 And then, how it is that you start using the power of Lisp 1218 01:10:36,210 --> 01:10:38,710 to talk not only about these individual little 1219 01:10:38,710 --> 01:10:43,080 computations, but about general conventional methods 1220 01:10:43,080 --> 01:10:45,200 of doing things. 1221 01:10:45,200 --> 01:10:46,730 OK, are there any questions? 1222 01:10:46,730 --> 01:10:47,640 AUDIENCE: Yes. 1223 01:10:47,640 --> 01:10:51,880 If we defined A using parentheses instead of as we 1224 01:10:51,880 --> 01:10:53,400 did, what would be the difference? 1225 01:10:53,400 --> 01:10:58,130 PROFESSOR: If I wrote this, if I wrote that, what I would be 1226 01:10:58,130 --> 01:11:03,740 doing is defining a procedure named A. In this case, a 1227 01:11:03,740 --> 01:11:07,950 procedure of no arguments, which, when I ran it, would 1228 01:11:07,950 --> 01:11:10,274 give me back 5 times 5. 1229 01:11:10,274 --> 01:11:10,716 AUDIENCE: Right. 1230 01:11:10,716 --> 01:11:12,610 I mean, you come up with the same thing, except for you 1231 01:11:12,610 --> 01:11:13,940 really got a different-- 1232 01:11:13,940 --> 01:11:14,120 PROFESSOR: Right. 1233 01:11:14,120 --> 01:11:16,330 And the difference would be, in the old one-- 1234 01:11:16,330 --> 01:11:19,180 Let me be a little bit clearer here. 1235 01:11:19,180 --> 01:11:24,070 Let's call this A, like here. 1236 01:11:24,070 --> 01:11:35,060 And pretend here, just for contrast, I wrote, define D to 1237 01:11:35,060 --> 01:11:37,300 be the product of 5 and 5. 1238 01:11:37,300 --> 01:11:40,200 1239 01:11:40,200 --> 01:11:42,450 And the difference between those, let's think about 1240 01:11:42,450 --> 01:11:45,770 interactions with the Lisp interpreter. 1241 01:11:45,770 --> 01:11:52,860 I could type in A and Lisp would return 25. 1242 01:11:52,860 --> 01:12:01,240 I could type in D, if I just typed in D, Lisp would return 1243 01:12:01,240 --> 01:12:08,000 compound procedure D, because that's what it is. 1244 01:12:08,000 --> 01:12:09,670 It's a procedure. 1245 01:12:09,670 --> 01:12:12,500 I could run D. I could say, what's the value of running D? 1246 01:12:12,500 --> 01:12:16,520 Here is a combination with no operands. 1247 01:12:16,520 --> 01:12:17,570 I see there are no operands. 1248 01:12:17,570 --> 01:12:22,940 I didn't put any after D. And it would say, oh, that's 25. 1249 01:12:22,940 --> 01:12:28,070 Or I could say, just for completeness, if I typed in, 1250 01:12:28,070 --> 01:12:29,310 what's the value of running A? 1251 01:12:29,310 --> 01:12:31,690 I get an error. 1252 01:12:31,690 --> 01:12:35,150 The error would be the same one as over there. 1253 01:12:35,150 --> 01:12:40,010 It'd be the error would say, sorry, 25, which is the value 1254 01:12:40,010 --> 01:12:43,720 of A, is not an operator that I can apply to something. 1255 01:12:43,720 --> 01:12:53,076