• [categories_slider autoplay="1"]
  • Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008

    Copy Help
    • Public/Private: Change the visibility of this video on your My Videos tab
    • Save/Unsave: Save/Unsave this video to/from your Saved Videos tab
    • Copy: Copy this video link to your system clipboard
    • Email: Copy this video link to your default email application
    • Remove: Remove this video from your My Videos or Saved Videos tab
    search-icon
    Watch at: 00:00 / 00:00:20The following content is provided under a CreativeCommons license.Your support will help MIT OpenCourseware continue tooffer high-quality educational resources for free.To make a donation, or view additional materials fromhundreds of MIT courses, visit MIT OpenCourseware, atocw.mit.edu .PROFESSOR: Good morning.Try it again.Good morning.Watch at: 00:20 / 00:40STUDENTS: Good morning.PROFESSOR: Thank you.This is 6.00, also known as Introduction to ComputerScience and Programming.My name is Eric Grimson, I have together Professor JohnGuttag over here, we're going to be lecturingthe course this term.I want to give you a heads up; you're getting some seriousWatch at: 00:40 / 01:00firepower this term.John was department head for ten years, felt like acentury, and in course six, I'm the current departmenthead in course six.John's been lecturing for thirty years, roughly.All right, I'm the young guy, I've only been lecturing fortwenty-five years.You can tell, I have less grey hair than he does.Watch at: 01:00 / 01:20What I'm trying to say to you is, we take thiscourse really seriously.We hope you do as well.But we think it's really important for the departmentto help everybody learn about computation, and that's whatthis course is about.What I want to do today is three things: I'm going tostart-- actually, I shouldn't say start, I'm going to do aWatch at: 01:20 / 01:40little bit of administrivia, the kinds of things you needto know about how we're going to run the course.I want to talk about the goal of the course, what it isyou'll be able to do at the end of this course when youget through it, and then I want to begin talking aboutthe concepts and tools of computational thinking, whichis what we're primarily going to focus on here.Watch at: 01:40 / 02:00We're going to try and help you learn how to think like acomputer scientist, and we're going to begin talking aboutthat towards the end of this lecture and of coursethroughout the rest of the lectures that carry on.Right, let's start with the goals.I'm going to give you goals in two levels.The strategic goals are the following: we want to helpprepare freshmen and sophomores who are interestedWatch at: 02:00 / 02:20in majoring in course six to get an easy entry into thedepartment, especially for those students who don't havea lot of prior programming experience.If you're in that category, don't panic, you'regoing to get it.We're going to help you ramp in and you'll certainly beable to start the course six curriculum and do just fineand still finish on target.Watch at: 02:20 / 02:40We don't expect everybody to be a course six major,contrary to popular opinion, so for those are you not inthat category, the second thing we want to do is we wantto help students who don't plan to major in course six tofeel justifiably confident in their ability to write andread small pieces of code.For all students, what we want to do is we want to give youWatch at: 02:40 / 03:00an understanding of the role computation can and cannotplay in tackling technical problems. So that you willcome away with a sense of what you can do, what you can't do,and what kinds of things you should use to tackle complexproblems.And finally, we want to position all students so thatyou can easily, if you like, compete for things like yourWatch at: 03:00 / 03:20office and summer jobs.Because you'll have an appropriate level ofconfidence and competence in your ability to docomputational problem solving.Those are the strategic goals.Now, this course is primarily aimed at students who havelittle or no prior programming experience.As a consequence, we believe that no student here isWatch at: 03:20 / 03:40under-qualified for this course: you're all MITstudents, you're all qualified to be here.But we also hope that there aren't any students here whoare over-qualified for this course.And what do I mean by that?If you've done a lot prior programming, this is probablynot the best course for you, and if you're in thatcategory, I would please encourage you to talk to JohnWatch at: 03:40 / 04:00or I after class about what your goals are, what kind ofexperience you have, and how we might find you a coursethat better meets your goals.Second reason we don't want over-qualified students in theclass, it sounds a little nasty, but the second reasonis, an over-qualified student, somebody who's, I don't know,programmed for Google for the last five years, is going toWatch at: 04:00 / 04:20have an easy time in this course, but we don't want sucha student accidentally intimidating the rest of you.We don't want you to feel inadequate when you're simplyinexperienced.And so, it really is a course aimed at students with littleor no prior programming experience.And again, if you're not in that category, talk to John orWatch at: 04:20 / 04:40I after class, and we'll help you figure out where you mightwant to go.OK.Those are the top-level goals of the course.Let's talk sort of at a more tactical level, about what dowe want you to know in this course.What we want you to be able to do by the timeyou leave this course?So here are the skills that we would like you to acquire.Watch at: 04:40 / 05:00Right, the first skill we want you to acquire, is we want youto be able to use the basic tools of computationalthinking to write small scale programs. I'm going to keepcoming back to that idea, but I'm going to call itcomputational thinking.And that's so you can write small pieces of code.Watch at: 05:00 / 05:20And small is not derogatory here, by the way, it just saysthe size of things you're going to be able to do.Second skill we want you to have at the end of this courseis the ability to use a vocabulary of computationaltools in order to be able to understandprograms written by others.So you're going to be able to write, you're goingto be able to read.This latter skill, by the way, is incredibly valuable.Watch at: 05:20 / 05:40Because you won't want to do everything from scratchyourself, you want to be able to look at what is beingcreated by somebody else and understand what is inside ofthere, whether it works correctly and how you canbuild on it.This is one of the few places whereplagiarism is an OK thing.It's not bad to, if you like, learn from the skills ofWatch at: 05:40 / 06:00others in order to create something you want to write.Although we'll come back to plagiarism as abad thing later on.Third thing we want you to do, is to understand thefundamental both capabilities and limitations ofcomputations, and the costs associated with them.And that latter statement sounds funny, you don't thinkof computations having limits, but they do.There're some things that cannot be computed.Watch at: 06:00 / 06:20We want you to understand where those limits are.So you're going to be able to understandabilities and limits.And then, finally, the last tactical skill that you'regoing to get out of this course is you're going to havethe ability to map scientific problems into aWatch at: 06:20 / 06:40computational frame.So you're going to be able to take a description of aproblem and map it into something computational.Now if you think about it, boy, it soundslike grammar school.Watch at: 06:40 / 07:00We're going to teach you to read, we're going to teach youto write, we're going to teach you to understand what you canand cannot do, and most importantly, we're going totry and give you the start of an ability to take adescription of a problem from some other domain, and figureout how to map it into that domain of computation so youcan do the reading and writing that you want to do.Watch at: 07:00 / 07:20OK, in a few minutes we're going to start talking thenabout what is computation, how are we going to start buildingthose tools, but that's what you should take away, that'swhat you're going to gain out of this course by the timeyou're done.Now, let me take a sidebar for about five minutes to talkabout course administration, the administrivia, things thatwe're going to do in the course, just so you know whatthe rules are.Watch at: 07:20 / 07:40Right, so, class is two hours of lecture a week.You obviously know where and you know when,because you're here.Tuesdays and Thursdays at 11:00.One hour of recitation a week, on Fridays, and we'll comeback in a second to how you're going to get set up for that.And nine hours a week of outside-the-class work.Those nine hours are going to be primarily working onWatch at: 07:40 / 08:00problem sets, and all the problems sets are going toinvolve programming in Python, which is the language we'regoing to be using this term.Now, one of the things you're going to see is the firstproblem sets are pretty easy.Actually, that's probably wrong, John, right?They're very easy.And we're going to ramp up.By the time you get to the end of the term, you're going tobe dealing with some fairly complex things, so one of thethings you're going to see is, we're going to make heavy useWatch at: 08:00 / 08:20of libraries, or code written by others.It'll allow you to tackle interesting problems I'll haveyou to write from scratch, but it does mean that this skillhere is going to be really valuable.You need to be able to read that code and understand it,as well as write your own.OK.Two quizzes.Watch at: 08:20 / 08:40During the term, the dates have already been scheduled.John, I forgot to look them up, I think it's October 2ndand November 4th, it'll be on the course website.My point is, go check the course website, which by theway is right there.If you have, if you know you have a conflict with one ofthose quiz dates now, please see John or I right away.Watch at: 08:40 / 09:00We'll arrange something ahead of time.But if you--The reason I'm saying that is, you know, you know that you'regetting married that day for example, we will excuse youfrom the quiz to get married.We'll expect you come right back to do the quiz by theway, but the--Boy, tough crowd.All right.If you have a conflict, please let us know.Second thing is, if you have an MIT documented special needWatch at: 09:00 / 09:20for taking quizzes, please see John or I well in advance.At least two weeks before the quiz.Again, we'll arrange for this, but you need to give us enoughwarning so that we can deal with that.OK, the quizzes are open book.This course is not about memory.Watch at: 09:20 / 09:40It's not how well you can memorize facts: in fact, Ithink both John and I are a little sensitive to memorytests, given our age, right John?This is not about how you memorize things, it's abouthow you think.So they're open note, open book.It's really going to test your ability to think.The grades for the course will be assigned roughly, and I usethe word roughly because we reserve the right to moveWatch at: 09:40 / 10:00these numbers around a little bit, but basically in thefollowing percentages: 55% of your grade comes from theproblem sets, the other 45% come from the quizzes.And I should've said there's two quizzes and a final exam.I forgot, that final exam during final period.So the quiz percentages are 10%, 15%, and 20%.Which makes up the other 45%.OK.Watch at: 10:00 / 10:20Other administrivia.Let me just look through my list here.First problem set, problem set zero, has already been posted.This is a really easy one.We intend it to be a really easy problem set.It's basically to get you to load up Python on your machineand make sure you understand how to interact with it.The first problem set will be posted shortly, it's alsopretty boring-- somewhat like my lectures but not John's--Watch at: 10:20 / 10:40and that means, you know, we want you just toget going on things.Don't worry, we're going to make them more interesting asyou go along.Nonetheless, I want to stress that none of these problemssets are intended to be lethal.We're not using them to weed you out, we're using them tohelp you learn.So if you run into a problem set that just, youdon't get, all right?Watch at: 10:40 / 11:00Seek help.Could be psychiatric help, could be a TA.I recommend the TA.My point being, please come and talk to somebody.The problems are set up so that, if you start down theright path, it should be pretty straight-forward towork it through.If you start down a plausible but incorrect path, you canWatch at: 11:00 / 11:20sometimes find yourself stuck in the weeds somewhere, and wewant to bring you back in.So part of the goal here is, this should not be a grueling,exhausting kind of task, it's really something that shouldbe helping you learn the material.If you need help, ask John, myself, or the TAs.That's what we're here for.OK.We're going to run primarily a paperless subject, that's whyWatch at: 11:20 / 11:40the website is there.Please check it, that's where everything's going to beposted in terms of things you need to know.In particular, please go to it today, you will find a formthere that you need to fill out to register for, or signup for rather, a recitation.Recitations are on Friday.Right now, we have them scheduled at 9:00, 10:00,11:00, 12:00, 1:00, and 2:00.Watch at: 11:40 / 12:00We may drop one of the recitations, just depending oncourse size, all right?So we reserve the right, unfortunately, to have to moveyou around.My guess is that 9:00 is not going to be a tremendouslypopular time, but maybe you'll surprise me.Nonetheless, please go in and sign up.We will let you sign up for whichever recitation makessense for you.Again, we reserve the right to move people around if we haveWatch at: 12:00 / 12:20to, just to balance load, but we want you to find somethingthat fits your schedule rather than ours.OK.Other things.There is no required text.If you feel exposed without a text book, you really have tohave a textbook, you'll find one recommended-- actually I'mWatch at: 12:20 / 12:40going to reuse that word, John, at least suggest it, onthe course website.I don't think either of us are thrilled with the text, it'sthe best we've probably found for Python, it's OK.If you need it, it's there.But we're going to basically not rely on any specific text.Right.Related to that: attendance here isobviously not mandatory.You ain't in high school anymore.Watch at: 12:40 / 13:00I think both of us would love to see your smiling faces, orat least your faces, even if you're notsmiling at us every day.Point I want to make about this, though, is that we aregoing to cover a lot of material that is not in theassigned readings, and we do have assigned readingsassociated with each one of these lectures.If you choose not to show up today-- or sorry, you didWatch at: 13:00 / 13:20choose to show up today, if you choose not to show up infuture days-- we'll understand, but please alsounderstand that the TAs won't have a lot of patience withyou if you're asking a question about something thatwas either covered in the readings, or covered in thelecture and is pretty straight forward.All right?We expect you to behave responsiblyand we will as well.All right.Watch at: 13:20 / 13:40I think the last thing I want to say is, we will not behanding out class notes.Now this sounds like a draconian measure;let me tell you why.Every study I know of, and I suspect every one John knows,about learning, stresses that students learn best when theytake notes.Ironically, even if they never look at them.Watch at: 13:40 / 14:00OK.The process of writing is exercising both halves of yourbrain, and it's actually helping you learn, and sotaking notes is really valuable thing.Therefore we're not going to distribute notes.What we will distribute for most lectures is a handoutthat's mostly code examples that we're going to do.I don't happen to have one today because we're not goingto do a lot of code.We will in future.Those notes are going to make no sense, I'm guessing,Watch at: 14:00 / 14:20outside of the lecture, all right?So it's not just, you can swing by 11:04 and grab a copyand go off and catch some more sleep.What we recommend is you use those notes to take your ownannotations to help you understand what's going on,but we're not going to provide class notes.We want you to take your own notes to help you, if youWatch at: 14:20 / 14:40like, spur your own learning process.All right.And then finally, I want to stress that John, myself, allof the staff, our job is to help you learn.That's what we're here for.It's what we get excited about.If you're stuck, if you're struggling, if you're notcertain about something, please ask.Watch at: 14:40 / 15:00We're not mind readers, we can't tell when you'restruggling, other than sort of seeing the expression on yourface, we need your help in identifying that.But all of the TAs, many of whom are sitting down in thefront row over here, are here to help, so come and ask.At the same time, remember that they're students too.And if you come and ask a question that you could haveeasily answered by doing the reading, coming to lecture, orWatch at: 15:00 / 15:20using Google, they're going to have less patience.But helping you understand things that really are aconceptual difficulty is what they're here for and whatwe're here for, so please come and talk to us.OK.That takes care of the administrivia preamble.John, things we add?PROFESSOR GUTTAG: Two more quick things.Watch at: 15:20 / 15:40This semester, your class is being videotaped forOpenCourseware.If any of you don't want your image recorded and posted onthe web, you're supposed to sit in the back three rows.PROFESSOR GRIMSON: Ah, thank you.I forgot.PROFESSOR GUTTAG: --Because the camera may pan.Watch at: 15:40 / 16:00I think you're all very good-looking and give MIT agood image, so please, feel free to be filmed.PROFESSOR GRIMSON: I'll turn around, so if you want to, youknow, move to the back, I won't see who moves.Right.Great.Thank you, John.PROFESSOR GUTTAG: So that, the other thing I want to mentionis, recitations are also very important.Watch at: 16:00 / 16:19We will be covering material in recitations that're not inthe lectures, not in the reading, and we do expect youto attend recitations.PROFESSOR GRIMSON: Great.Thanks, John.Any questions about the administrivia?I know it's boring, but we need to do it so you know whatthe ground rules are.Good.OK.Let's talk about computation.As I said, our strategic goal, our tactical goals, are tohelp you think like a computer scientist. Another way ofWatch at: 16:19 / 16:40saying it is, we want to give you the skill so that you canmake the computer do what you want it to do.And we hope that at the end of the class, every time you'reconfronted with some technical problem, one of your firstinstincts is going to be, "How do I write the piece of codethat's going to help me solve that?"So we want to help you think like a computerscientist. All right.Watch at: 16:40 / 17:00And that, is an interesting statement.What does it mean, to think like a computer scientist?Well, let's see.The primary knowledge you're going to take away from thisWatch at: 17:00 / 17:20course is this notion of computational problem solving,this ability to think incomputational modes of thought.And unlike in a lot of introductory courses, as aconsequence, having the ability to memorize is notgoing to help you.It's really learning those notions of the tools that youwant to use.What in the world does it mean to saycomputational mode of thought?Watch at: 17:20 / 17:40It sounds like a hifalutin phrase you use when you'retrying to persuade a VC to fund you.Right.So to answer this, we really have to ask a differentquestion, a related question; so, what's computation?It's like a strange statement, right?What is computation?And part of the reason for putting it up is that I wantto, as much as possible, answer that question byWatch at: 17:40 / 18:00separating out the mechanism, which is the computer, fromcomputational thinking.Right.The artifact should not be what's driving this.It should be the notion of, "What does it mean to docomputation?"Now, to answer that, I'm going to back up one more level.And I'm going to pose what sounds like a philosophyquestion, which is, "What is knowledge?" And you'll see inWatch at: 18:00 / 18:20about two minutes why I'm going to do this.But I'm going to suggest that I can divide knowledge into atleast two categories.OK, and what is knowledge?And the two categories I'm going to divide them into aredeclarative and imperative knowledge.Right.Watch at: 18:20 / 18:40What in the world is declarative knowledge?Think of it as statements of fact.It's assertions of truth.Boy, in this political season, that's a really dangerousphrase to use, right?But it's a statement of fact.I'll stay away from the political comments.Let me give you an example of this.Right.Here's a declarative statement.The square root of x is that y such that y squared equals x,Watch at: 18:40 / 19:00y's positive.You all know that.But what I want you to see here, is that's astatement of fact.It's a definition.It's an axiom.It doesn't help you find square roots.Watch at: 19:00 / 19:20If I say x is 2, I want to know, what's the square rootof 2, well if you're enough of a geek, you'll say 1.41529 orwhatever the heck it is, but in general, this doesn't helpyou find the square root.The closest it does is it would let you test. You know,if you're wandering through Harvard Square and you see anout-of-work Harvard grad, they're handing out examplesof square roots, they'll give you an example and you canWatch at: 19:20 / 19:40test it to see, is the square root of2, 1.41529 or whatever.I don't even get laughs at Harvard jokes, John, I'm goingto stop in a second here, all right?All right, so what am I trying to say here?It doesn't -- yeah, exactly.We're staying away from that, really quickly, especiallywith the cameras rolling.All right.Watch at: 19:40 / 20:00What am I trying to say?It tells you how you might test something but it doesn'ttell you how to.And that's what imperative knowledge is.Imperative knowledge is a description ofhow to deduce something.So let me give you an example of a pieceof imperative knowledge.All right, this is actually a very old piece of imperativeknowledge for computing square roots, it's attributed toWatch at: 20:00 / 20:20Heron of Alexandria, although I believe that the Babyloniansare suspected of knowing it beforehand.But here is a piece of imperative knowledge.All right?I'm going to start with a guess, I'm going to call it g.And then I'm going to say, if g squared is close to x, stop.Watch at: 20:20 / 20:40And return g.It's a good enough answer.Otherwise, I'm going to get a new guess by taking g, x overg, adding them, and dividing by two.Watch at: 20:40 / 21:00Then you take the average of g and x over g.Don't worry about how came about, Heron found this out.But that gives me a new guess, and I'm going to repeat.That's a recipe.That's a description of a set of steps.Watch at: 21:00 / 21:20Notice what it has, it has a bunch of nice things that wewant to use, right?It's a sequence of specific instructionsthat I do in order.Along the way I have some tests, and depending on thevalue of that test, I may change where I am in thatsequence of instructions.And it has an end test, something that tells me whenWatch at: 21:20 / 21:40I'm done and what the answer is.This tells you how to find square roots.it's how-to knowledge.It's imperative knowledge.All right.That's what computation basically is about.We want to have ways of capturing this process.OK, and that leads now to an interesting question, whichwould be, "How do I build a mechanical process to captureWatch at: 21:40 / 22:00that set of computations?" So I'm going to suggest thatthere's an easy way to do it--I realized I did the boards in the wrong order here-- one ofthe ways I could do it is, you could imagine building alittle circuit to do this.If I had a couple of elements of stored values in it, I hadWatch at: 22:00 / 22:20some wires to move things around, I had a little thingto do addition, little thing to do division, and asomething to do the testing, I could build a little circuitthat would actually do this computation.OK.That, strange as it sounds, is actually an example of theearliest computers, because the earliest computers werewhat we call fixed-program computers, meaning that theyWatch at: 22:20 / 22:40had a piece of circuitry designed to do a specificcomputation.And that's what they would do: they would do that specificcomputation.Watch at: 22:40 / 23:00You've seen these a lot, right?A good example of this: calculator.It's basically an example of a fixed-program computer.It does arithmetic.If you want play video games on it, good luck.If you want to do word processing on it, good luck.It's designed to do a specific thing.Watch at: 23:00 / 23:20It's a fixed-program computer.In fact, a lot of the other really interesting early onessimilarly have this flavor, to give an example: I never knowhow to pronounce this, Atanasoff, 1941.One of the earliest computational things was athing designed by a guy named Atanasoff, and it basicallysolved linear equations.Watch at: 23:20 / 23:40Handy thing to do if you're doing 1801, all right, or1806, or whatever you want to do those things in.All it could do, though, was solve those equations.One of my favorite examples of an early computer was done byAlan Turing, one of the great computer scientists of alltime, called the bombe, which was designed to break codes.Watch at: 23:40 / 24:00It was actually used during WWII to breakGerman Enigma codes.And what it was designed to do, was to solvethat specific problem.The point I'm trying to make is, fixed-program computers iswhere we started, but it doesn't really get us to wherewe'd like to be.We want to capture this idea of problem solving.So let's see how we'd get there.Watch at: 24:00 / 24:20So even within this framework of, given a description of acomputation as a set of steps, in the idea that I could builda circuit to do it, let me suggest for you what would bea wonderful circuit to build.Suppose you could build a circuit with the followingproperty: the input to this circuit would be any othercircuit diagram.Watch at: 24:20 / 24:40Give it a circuit diagram for some computation, you give itto the circuit, and that circuit would wonderfullyreconfigure itself to act like the circuits diagram.Which would mean, it could act like a calculator.Or, it could act like Turing's bombe.Or, it could act like a square root machine.So what would that circuit look like?You can imagine these tiny little robots wanderingWatch at: 24:40 / 25:00around, right?Pulling wires and pulling out components andstacking them together.How would you build a circuit that could take a circuitdiagram in and make a machine act like that circuit?Sounds like a neat challenge.Let me change the game slightly.Suppose instead, I want a machine that can take aWatch at: 25:00 / 25:20recipe, the description of a sequence of steps, take thatas its input, and then that machine will now act like whatis described in that recipe.Reconfigure itself, emulate it, however you want to usethe words, it's going to change how it does thecomputation.Watch at: 25:20 / 25:40That would be cool.And that exists.It's called an interpreter.It is the basic heart of every computer.What it is doing, is saying, change the game.This is now an example of a stored-program computer.Watch at: 25:40 / 26:00What that means, in a stored-program computer, isthat I can provide to the computer a sequence ofinstructions describing the process I want it to execute.And inside of the machine, and things we'll talk about, thereis a process that will allow that sequence to be executedWatch at: 26:00 / 26:20as described in that recipe, so it can behave like anything that I can describe in one of those recipes.All right.That actually seems like a really nice thing to have, andso let me show you what that would basically look like.Inside of a stored-program computer, we would have theWatch at: 26:20 / 26:40following: we have a memory, it's connected to two things;control unit, in what's called an ALU, an arithmetic logicunit, and this can take in input, and spit out output,Watch at: 26:40 / 27:00and inside this stored-program computer, excuse me, you havethe following: you have a sequence of instructions.And these all get stored in there.Watch at: 27:00 / 27:20Notice the difference.The recipe, the sequence of instructions, is actuallygetting read in, and it's treated just like data.It's inside the memory of the machine, which means we haveaccess to it, we can change it, we can use it to build newpieces of code, as well as we can interpret it.One other piece that goes into this computer--Watch at: 27:20 / 27:40I never remember where to put the PC, John, control?ALU?Separate?I'll put it separate-- you have a thingcalled a program counter.And here's the basis of the computation.That program counter points to some location in memory,typically to the first instruction in the sequence.Watch at: 27:40 / 28:00And those instructions, by the way, are very simple: they'rethings like, take the value out of two places in memory,and run them through the multiplier in here, a littlepiece of circuitry, and stick them back intosomeplace in memory.Or take this value out of memory, run it through someother simple operation, stick it back in memory.Watch at: 28:00 / 28:20Having executed this instruction, that counter goesup by one and we move to the next one.We execute that instruction, we move to the next one.Oh yeah, it looks a whole lot like that.Some of those instructions will involve tests: they'llsay, is something true?And if the test is true, it will change the value of thisWatch at: 28:20 / 28:40program counter to point to some other place in thememory, some other point in that sequence of instructions,and you'll keep processing.Eventually you'll hopefully stop, and a value gets spitout, and you're done.That's the heart of a computer.Now that's a slight misstatement.The process to control it is intriguing and interesting,but the heart of the computer is simply this notion that weWatch at: 28:40 / 29:00build our descriptions, our recipes, on a sequence ofprimitive instructions.And then we have a flow of control.And that flow of control is what I just described.It's moving through a sequence of instructions, occasionallychanging where we are as we move around.OK.The thing I want you to take away from this, then, is toWatch at: 29:00 / 29:20think of this as, this is, if you like, a recipe.And that's really what a program is.It's a sequence of instructions.Watch at: 29:20 / 29:40Now, one of things I left hanging is, I said, OK, youbuild it out of primitives.So one of the questions is, well, what are the rightprimitives to use?And one of the things that was useful here is, that weactually know that the set of primitives that you want touse is very straight-forward.OK, but before I do that, let me drive home this idea of whythis is a recipe.Watch at: 29:40 / 30:00Assuming I have a set of primitive instructions that Ican describe everything on, I want to know what can I build.Well, I'm going to do the same analogy to a real recipe.So, real recipe.I don't know.Separate six eggs.Do something.Beat until the-- sorry, beat the whitesuntil they're stiff.Do something until an end test is true.Watch at: 30:00 / 30:20Take the yolks and mix them in with the sugar and water--No.Sugar and flour I guess is probably what I want, sugarand water is not going to do anything interesting for mehere-- mix them into something else.Do a sequence of things.A traditional recipe actually is based on a small set ofprimitives, and a good chef with, or good cook, I shouldWatch at: 30:20 / 30:40say, with that set of primitives, can create anunbounded number of great dishes.Same thing holds true in programming.Right.Given a fixed set of primitives, all right, a goodprogrammer can program anything.Watch at: 30:40 / 31:00And by that, I mean anything that can be described in oneof these process, you can capture in that set ofprimitives.All right, the question is, as I started to say, is, "Whatare the right primitives?" So there's a little bit of, alittle piece of history here, if you like.In 1936, that same guy, Alan Turing, showed that with sixWatch at: 31:00 / 31:20simple primitives, anything that could be described in amechanical process, it's actually algorithmically,could be programmed just using those six primitives.Think about that for a second.That's an incredible statement.It says, with six primitives, I can rule the world.Watch at: 31:20 / 31:40With six primitives, I can program anything.A couple of really interesting consequences of that, by theway, one of them is, it says, anything you can do in oneprogramming language, you can do inanother programming language.And there is no programming language that is better-- wellactually, that's not quite true, there are some better atdoing certain kinds of things-- but there's nothingthat you can do in C that you can't do in Fortran.Watch at: 31:40 / 32:00It's called Turing compatibility.Anything you can do with one, you can do with another, it'sbased on that fundamental result.OK.Now, fortunately we're not going to start with Turing'ssix primitives, this would be really painful programming,because they're down at the level of, "take this value andwrite it onto this tape." First of all, we don't haveWatch at: 32:00 / 32:20tapes anymore in computers, and even if we did, you don'twant to be programming at that level.What we're going to see with programming language is thatwe're going to use higher-level abstracts.A broader set of primitives, but nonetheless the samefundamental thing holds.With those six primitives, you can do it.OK.So where are we here?What we're saying is, in order to do computation, we want toWatch at: 32:20 / 32:39describe recipes, we want to describe this sequence ofsteps built on some primitives, and we want todescribe the flow of control that goes through thosesequence of steps as we carry on.So the last thing we need before we can start talkingabout real programming is, we need todescribe those recipes.All right, And to describe the recipes, we'reWatch at: 32:39 / 33:00going to want a language.We need to know not only what are the primitives, but how dowe make things meaningful in that language.Watch at: 33:00 / 33:20Language.There we go.All right.Now, it turns out there are--I don't know, John, hundreds?Thousands?Of programming languages?At least hundreds-- of programming languages around.PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]PROFESSOR ERIC GRIMSON: True.Thank you.You know, they all have, you know,Watch at: 33:20 / 33:39their pluses and minuses.I have to admit, in my career here, I think I've taught inat least three languages, I suspect you've taught more,five or six, John?Both of us have probably programmed in more than thosenumber of languages, at least programmed that many, since wetaught in those languages.One of the things you want to realize is,there is no best language.At least I would argue that, I think John would agree.We might both agree we have our own nominees for worstWatch at: 33:39 / 34:00language, there are some of those.There is no best language.All right?They all are describing different things.Having said that, some of them are better suited for somethings than others.Anybody here heard of MATLAB Maybe programmed in MATLAB?It's great for doing things with vectors and matrices andthings that are easily captured in that framework.Watch at: 34:00 / 34:20But there's some things that are a realpain to do in MATLAB.So MATLAB's great for that kind of thing.C is a great language for programming things thatcontrol data networks, for example.I happen to be, and John teases me about thisregularly, I'm an old-time Lisp programmer, and that'show I was trained.And I happen to like Lisp and Scheme, it's a great languagewhen you're trying to deal with problems where you haveWatch at: 34:20 / 34:40arbitrarily structured data sets.It's particularly good at that.So the point I want to make here is that there's noparticularly best language.What we're going to do is simply use a language thathelps us understand.So in this course, the language we'regoing to use is Python.Which is a pretty new language, it's growing inpopularity, it has a lot of the elements of some otherWatch at: 34:40 / 35:00languages because it's more recent, it inherits thingsfrom it's pregenitors, if you like.But one of the things I want to stress is, this course isnot about Python.Strange statement.You do need to know how to use it, but it's not about thedetails of, where do the semi-colons go in Python.Watch at: 35:00 / 35:20All right?It's about using it to think.And what you should take away from this course is havinglearned how to design recipes, how to structure recipes, howto do things in modes in Python.Those same tools easily transferto any other language.You can pick up another language in a week, couple ofweeks at most, once you know how to do Python.Watch at: 35:20 / 35:40OK.In order to talk about Python and languages, I want to doone last thing to set the stage for what we're going todo here, and that's to talk about the different dimensionsof a language.And there're three I want to deal with.The first one is, whether this is a high-levelor low-level language.Watch at: 35:40 / 36:00That basically says, how close are youthe guts of the machine?A low-level language, we used to call this assemblyprogramming, you're down at the level of, your primitivesare literally moving pieces of data from one location ofmemory to another, through a very simple operation.A high-level language, the designer has created a muchricher set of primitive things.In a high-level language, square root might simply be aWatch at: 36:00 / 36:20primitive that you can use, rather than you having to goover and code it.And there're trade-offs between both.Second dimension is, whether this is a general versus atargeted language.And by that I mean, do the set of primitives support a broadrange of applications, or is it really aimed at a veryWatch at: 36:20 / 36:40specific set of applications?I'd argue that MATLAB is basically a targeted language,it's targeted at matrices and vectors and things like that.And the third one I want to point out is, whether this isan interpreted versus a compiled language.Watch at: 36:40 / 37:00What that basically says is the following: in aninterpreted language, you take what's called the source code,the thing you write, it may go through a simple checker butit basically goes to the interpreter, that thing insidethe machine that's going to control the flow of goingthrough each one of the instructions,and give you an output.So the interpreter is simply operating directly on yourWatch at: 37:00 / 37:20code at run time.In a compiled language, you have an intermediate step, inwhich you take the source code, it runs through what'scalled a checker or a compiler or both, and it creates what'scalled object code.And that does two things: one, it helps catch bugs in yourcode, and secondly it often converts it into a moreefficient sequence of instructions before youWatch at: 37:20 / 37:40actually go off and run it.All right?And there's trade-offs between both.I mean, an interpreted language is often easier todebug, because you can still see your raw code there, butit's not always as fast. A compiled language is usuallymuch faster in terms of its execution.And it's one of the things you may want to trade off.Right.In the case of Python, it's a high-level language.Watch at: 37:40 / 38:00I would argue, I think John would agree with me, it'sbasically a general-purpose language.It happens to be better suited for manipulating strings thannumbers, for example, but it's really ageneral-purpose language.And it's primarily--I shouldn't say primarily, it is an interpreted language.OK?As a consequence, it's not as good as helping debug, but itWatch at: 38:00 / 38:20does let you-- sorry, that's the wrong way of saying-- it'snot as good at catching some things before you run them, itis easier at some times in debugging as you goalong on the fly.OK.So what does Python look like?In order to talk about Python-- actually, I'm goingto do it this way-- we need to talk about how toWatch at: 38:20 / 38:40write things in Python.Again, you have to let me back up slightly and set the stage.Our goal is to build recipes.You're all going to be great chefs by thetime you're done here.All right?Our goal is to take problems and break them down into thesecomputational steps, these sequence of instructionsthat'll allow us to capture that process.Watch at: 38:40 / 39:00To do that, we need to describe: not only, what arethe primitives, but how do we capture things legally in thatlanguage, and interact with the computer?And so for that, we need a language.We're about to start talking about the elements of thelanguage, but to do that, we also need to separate out onelast piece of distinction.Just like with a natural language, we're going toseparate out syntax versus semantics.Watch at: 39:00 / 39:20So what's syntax?Syntax basically says, what are the legal expressions inthis language?Boy, my handwriting is atrocious, isn't it?Watch at: 39:20 / 39:40There's a English sequence of words.It's not since syntactically correct, right?It's not a sentence.There's no verb in there anywhere, it's justa sequence of nouns.Same thing in our languages.We have to describe how do you put together legally formedexpressions.OK?And as we add constructs to the language, we're going toWatch at: 39:40 / 40:00talk about.Second thing we want to talk about very briefly as we goalong is the semantics of the language.And here we're going to break out two pieces; staticsemantics and full semantics.Static semantics basically says which programs areWatch at: 40:00 / 40:20meaningful.Which expressions make sense.Here's an English sentence.It's syntactically correct.Watch at: 40:20 / 40:40Right?Noun phrase, verb, noun phrase.I'm not certain it's meaningful, unless you are inthe habit of giving your furniture personal names.What's the point?Again, you can have things that are syntactically legalbut not semantically meaningful, and staticsemantics is going to be a way of helping us decide whatexpressions, what pieces of code, actually have realWatch at: 40:40 / 41:00meaning to it.All right?The last piece of it is, in addition to having staticsemantics, we have sort of full semantics.Which is, what does the program mean?Or, said a different way, what's going tohappen when I run it?Watch at: 41:00 / 41:20That's the meaning of the expression.That's what you want.All right?You want to know, what's the meaning of this piece of code?When I run it, what's going to happen?That's what I want to build.The reason for pulling this out is, what you're going tosee is, that in most languages, and certainly inWatch at: 41:20 / 41:40Python-- we got lots of help here-- all right, Python comesbuilt-in with something that will check your static, sorry,your syntax for you.And in fact, as a sidebar, if you turn in a problem set thatis not syntactically correct, there's a simple button thatWatch at: 41:40 / 42:00you push that will check your syntax.If you've turned in a program that's not syntacticallycorrect, the TAs give you a zero.Because it said you didn't even take the time to makesure the syntax is correct.The system will help you find it.In Python, it'll find it, I think one bug ata time, right John?It finds one syntax error at a time, so you have to be alittle patient to do it, but you can check thatthe syntax is right.You're going to see that we get some help here on theWatch at: 42:00 / 42:20static semantics, and I'm going to do an example in asecond, meaning that the system, some languages arebetter than others on it, but it will try and help you catchsome things that are not semantically correctWatch at: 42:20 / 42:40statically.In the case of Python, it does that I think all at run time.I'm looking to you again, John, I think there's nopre-time checks.Its-- sorry?PROFESSOR JOHN GUTTAG: [UNINTELLIGIBLE]PROFESSOR ERIC GRIMSON: There is some.OK.Most of them, I think though, are primarily caught at runtime, and that's a little bit of a pain because you don'tsee it until you go and run the code, and there are some,actually we're going to see an example I think in a secondWatch at: 42:40 / 43:00where you find it, but you do get some help there.The problem is, things that you catch here are actuallythe least worrisome bugs.They're easy to spot, you can't run the program withthem there, so you're not going to get weird answers.Not everything is going to get caught instatic semantics checking.Some things are going to slide through, andWatch at: 43:00 / 43:20that's actually a bother.It's a problem.Because it says, your program will still give you a value,but it may not be what you intended, and you can't alwaystell, and that may propagate it's way down through a wholebunch of other computations before it causes somecatastrophic failure.So actually, the problem with static semantics is you'd likeit to catch everything, you don't always get it.Watch at: 43:20 / 43:40Sadly we don't get much help here.Which is where we'd like it.But that's part of your job.OK.What happens if you actually have something that's bothsyntactically correct, and appears to have correct staticsemantics, and you run it?It could run and give you the right answer, it could crash,it could loop forever, it could run and apparently giveWatch at: 43:40 / 44:00you the right answer.And you're not always going to be able to tell.Well, you'll know when it crashes, that doesn't help youvery much, but you can't always tell whethersomething's stuck in an infinite loop or whether it'ssimply taking a long time to compute.You'd love to have a system that spots that for you, butit's not possible.And so to deal with this last one, youWatch at: 44:00 / 44:20need to develop style.All right?Meaning, we're going to try to help you with how to developgood programming style, but you need to write in a way inwhich it is going to be easy for you to spot the placesthat cause those semantic bugs to occur.All right.Watch at: 44:20 / 44:40If that sounds like a really long preamble, it is.Let's start with Python.But again, my goal here is to let you see what computation'sabout, why we need to do it, I'm going to remind you onelast time, our goal is to be able to have a set ofprimitives that we combine into complex expressions,which we can then abstract to treat as primitives, and wewant to use that sequence of instructions in this flow ofWatch at: 44:40 / 45:00control computing, in order to deduce new information.That imperative knowledge that we talked about right there.So I'm going to start today, we have about five or tenminutes left, I think, in order-- sorry, five minutesleft-- in order to do this with some beginnings ofPython, and we're going to pick this up obviously, nexttime, so; simple parts of Python.Watch at: 45:00 / 45:20In order to create any kinds of expressions, we're going toneed values.Primitive data elements.And in Python, we have two to start with; we have numbers,and we have strings.Numbers is what you'd expect.There's a number.Watch at: 45:20 / 45:40There's another number.All right?Strings are captured in Python with an open quote and somesequence of characters followed by a closed quote.Associated with every data type in Python is a type,which identifies the kind of thing it is.Watch at: 45:40 / 46:00Some of these are obvious.Strings are just a type on their own.But for numbers, for example, we can havea variety of types.So this is something that we would call aninteger, or an INT.And this is something we would call afloating point, or a float.Or if you want to think of it as a real number.And there's some others that we can see.Watch at: 46:00 / 46:20We're going to build up this taxonomy if you like, but thereason it's relevant is, associated with each one ofthose types is a set of operators that expect certaintypes of input in order to do their job.And given those types of input, will get back output.All right.In order to deal with this, let me show you an example,and I hope that comes up, great.Watch at: 46:20 / 46:40What I have here is a Python shell, and I'm going to justshow you some simple examples of how we start buildingexpressions.And this'll lead into what you're going to see next timeas well as what you're going to do tomorrow.So.Starting with the shell, I can type in expressions.Actually, let me back up and do this in video.I can type in a number, I get back a number, I can type in aWatch at: 46:40 / 47:00string, I get back the string.Strings, by the way, can have spaces in them, they can haveother characters, it's simply a sequence of things, andnotice, by the way, that the string five-- sorry, thestring's digit five digit two is differentWatch at: 47:00 / 47:20than the number 52.The quotes are around them to make that distinction.We're going to see why in a second.What I'm doing, by the way, here is I'm simply typing inexpressions to that interpreter.It's using its set of rules to deduce the value and printthem back out.Things I might like to do in here is, I might like to docombinations of things with these.So we have associated with simple things, a set ofWatch at: 47:20 / 47:40operations.So for numbers, we have the things you'd expect, thearithmetics.And let me show you some examples of that.And actually, I'm going to do one other distinction here.What I typed in, things like-- well, let me start this way--Watch at: 47:40 / 48:00there's an expression.And in Python the expression is, operand, operator,operand, when we're doing simple expressions like this,and if I give it to the interpreter, it gives me backexactly what you'd expect, which is that value.OK?The distinction I'm going to make is, that's an expression.The interpreter is going to get a value for it.Watch at: 48:00 / 48:20When we start building up code, we'regoing to use commands.Or statements.Which are actually things that take in a value and ask thecomputer to do something with it.So I can similarly do this, which is going to look strangebecause it's going to give me the same value back out, butit actually did a slightly different thing.And notice, by the way, when I typed it how print showed upin a different color?Watch at: 48:20 / 48:40That's the Python saying, that is a command, that is aspecific command to get the value of the expression andprint it back out.When we start writing code, you're going to see thatdifference, but for now, don't worry about it, I just want toplant that idea.OK.Once we've got that, we can certainly, though,do things like this.Notice the quotes around it.Watch at: 48:40 / 49:00And it treats it as a string, it's simply getting me backthe value of that string, 52 times 7, rather thanthe value of it.Now, once we've got that, we can start doing things.And I'm going to use print here-- if I could type, inorder to just to get into that, I can't type, here wego-- in order to get into the habit.I can print out a string.Watch at: 49:00 / 49:20I can print out--Ah!--Here's a first example of something thatcaught one of my things.This is a static semantic error.So what went on here?I gave it an expression that had an operand in there.It expected arithmetic types.Watch at: 49:20 / 49:40But I gave two strings.And so it's complaining at me, saying, you can't do this.I don't know how to take two strings andmultiply them together.Unfortunately-- now John you may disagree with me on thisone-- unfortunately in Python you can, however,do things like this.What do you figure that's going to do?Look legal?Watch at: 49:40 / 50:00The string three times the number three?Well it happens to give me three threes in a row.I hate this.I'm sorry, John, I hate this.Because this is overloading that multiplication operatorwith two different tasks.It's saying, if you give me two numbers, I'lldo the right thing.If you give me a number and a string, I'm going toWatch at: 50:00 / 50:20concatenate them together, it's really differentoperations, but nonetheless, it's what it's going to do.STUDENT: [UNINTELLIGIBLE]PROFESSOR ERIC GRIMSON: There you go.You know, there will be a rebuttal phase a little lateron, just like with the political debates, and helikes it as a feature, I don't like it, you can tell he's nota Lisp programmer and I am.Watch at: 50:20 / 50:40All right.I want to do just a couple more quick examples.Here's another one.Ah-ha!Give you an example of a syntax error.Because 52A doesn't make sense.And you might say, wait a minute, isn't that a string,and the answer's no, I didn't say it's a string by puttingquotes around it.And notice how the machine responds differently to it.In this case it says, this is a syntax error, and it'sWatch at: 50:40 / 51:00actually highlighting where it came from so I can goback and fix it.All right.Let's do a couple of other simple examples.All right?I can do multiplication.I've already seen that.I can do addition.Three plus five.I can take something to a power, double star, just takethree to the fifth power.I can do division, right?Watch at: 51:00 / 51:20Whoa.Right?Three divided by five is zero?Maybe in Bush econom-- no, I'm not going to do any politicalcomments today, I will not say that, all right?What happened?Well, this is one of the places whereyou have to be careful.It's doing integer division.So, three divided by five is zero, with aWatch at: 51:20 / 51:40remainder of three.So this is the correct answer.If I wanted to get full, real division, I should make one ofthem a float.And yes, you can look at that and say, well is that right?Well, up to some level of accuracy, yeah, that's .6 iswhat I'd like to get out.All right.I can do other things.Watch at: 51:40 / 52:00In a particular, I have similar operations on strings.OK, I can certainly print out strings, but I can actuallyadd strings together, and just as you saw, I can multiplystrings, you can kind of guess what this is going to do.It is going to merge them together into one thing.I want--I know I'm running you slightly over, I want to doWatch at: 52:00 / 52:20one last example, it's, I also want to be able to do, havevariables to store things.And to do that, in this it says, if I have a value, Iwant to keep it around, to do that, I cando things like this.Watch at: 52:20 / 52:40What does that statement do?It says, create a name for a variable-- which I just didthere, in fact, let me type it in-- mystring, with an equalsign, which is saying, assign or bind to that name the valueof the following expression.As a consequence, I can now refer tothat just by its name.If I get the value of mystring, there it is, or if IWatch at: 52:40 / 53:00say, take mystring and add to it the string, mylastname, andprint it back out.So this is the first start of this.What have we done?We've got values, numbers and strings.We have operations to associate with them.I just threw a couple up here.Watch at: 53:00 / 53:20You're going to get a chance to explore them, and you'llsee not only are there the standard numerics for strings,there are things like length or plus or other things youcan do with them.And once I have values, I want to get a hold of them so I cangive them names.And that's what I just did when I bound that.I said, use the name mystring to be bound to or have thevalue of Eric, so I can refer to it anywhere else that Iwant to use it.Watch at: 53:20 / 53:40And I apologize for taking you over, we'll come back to thisnext time, please go to the website to sign up forrecitation for tomorrow.