 So, okay. I want to give a view of programming and modeling. We're learning how to program, so the class is about, and it's based on modeling. So, two questions I want to look at. What is modeling, and how is programming an example? I'm really going to take a sort of extreme view, which is more than you might see in some treatments, that programming, the essence of programming, really is all about modeling. It's really more like, okay, so that's our agenda. Step one is what is a model? What is modeling? What is modeling? And, you know, if I'm completely honest and I try to imagine it from a fresh perspective, I would probably think modeling is what Heidi Klum does. I don't know, many guy, red pit, I don't know, saw him next to perfume in the paper the other day. I guess that's modeling. What else? Lionel trains, model trains, model planes. That's obviously modeling. Modeling clay, modeling. All things that we say that modeling is, I want to add programming to the list. And so, how we start with like a train. You know, a train obviously seems like a little toy train looks like the real thing, it's just smaller. And it's not literally a real train scaled down. It's something that's made to have certain aspects of the thing that it is a model of. So overall, we're talking about the elements of a model. There are basically just a few things. It is reality. And reality doesn't actually have to be real, that's why I put it in quotes. It's just the thing that we are making a model of that could be just about anything. It could be another model. Then usually in the model, we're going to focus on discrete models. There can be models that don't have this. Usually there's some objects and rules of behavior that govern what happens. And it's easy to think about this as being like a game. You have cards and you can only put a red card on a black card and vice versa, whatever it is. This is the stuff of the model. And then crucially, you have a mapping between one and two. A mapping between reality, states of reality. Reality states getting mapped to model states. So that's the real key. And so we can look at, you know, we have a real train. We have the road runner sitting outside Placidas, getting ready to head to Santa Fe. In my model, when I had trains, when I had Lionel trains, I had O-Gauge trains, which were scaled down 48 to 1. So 48 feet out in the world became 1 foot in the model, or 4 feet in the real world became 1 inch, 4 feet, 1 inch. And they have the rules of behavior, how they interact. Lionel trains are all electric. They rolled down the tracks. They did whatever they did. If you had two of them and you tried to make a collision, like Omer's Adams always did on the Adams family, they would do whatever they would do. Then we have the mapping. And in the case of the trains, the mapping superficially seemed to just be, you know, a spatial scaling down. It turns out that they're not really literally just 1 to 48 in all ways, because it wouldn't really work. The things would fly, the little hooks that hold the wheels onto the tracks have to be bigger than they ought to be, or else the model trains wouldn't stay on the tracks. So there's some mapping, something to say, if this is the state out in the world, then this is what we get in here. And then what we're trying to find out is, we're trying to find out, is this model predictive? Okay, there's lots of things we can do with a model. One of the main things we do, at least with scientific models, is we try to make predictions. So let's look at the master picture. Whoops. Diagram. And so here we have reality. And again, I'll put it in quotes. And then we have the mapping, which takes us to objects in the model, objects and rules. And we can then run the model. We can then operate the model using its rules, saying if the model is in, if the objects are in this particular state and you ask for time to pass or you pump in some money or some water or whatever it is that the model is driven by, then you get to a new state of objects. This is objects number two. This is objects number one. This is reality number one. And then the idea is, is we ought to be able to take the mapping backwards. It's called the inverse mapping and come up with a new state in reality. And you notice that whereas reality number one was all kind of raggedy and jaggedy, I've drawn reality number two with kind of boxy because we've lost all of the little nooks and crannies of reality when we abstracted it, this step is called abstraction. Step is called instantiation or other things. We have no basis. We have this very simplified model just has trains and tracks and rules that says if you turn the knob on the thing, the train will go. And it gets to another state where the train crashed into another train and they both fell off the tracks. When we do the inverse mapping, we do not get all of this extra stuff of reality back. We just say, well, there should be two trains and one ought to be fallen this way and one ought to be fallen that way. And if we did this all right, if we made a good abstraction that had objects that were naturally separable objects and the rules for the objects to do things were rules that corresponded to the things that tended to happen in actual reality and then when we do the inverse mapping, we will come up with a state of affairs that is similar to if the real reality happened to be, and this is life stuff, right, that we go from one state of reality to the next state of reality. And if this really works, if what's in state reality number two is similar in a useful way to what, starting with state number one in reality and letting life happen, then we say the model is predictive. It's a good predictor. All right, so we talked about what that might be like in the case of trains, in the case of modeling, like fashion modeling. Well, I mean, you know, there's the reality. When we abstract it, we have something like people, clothes, perfume, shoes, whatever it is. And the mapping that's being offered is, you know, I am Brad Pitt. So the dynamics implicitly say, and this is what, you know, the marketing is all designed to do, that, you know, if I am standing next to this perfume, then whatever would happen to Brad Pitt will happen to me. That's the implicit model that's being offered by fashion modeling, by all of modeling. Is it really very predictive? You be the judge. Clay is just like modeling trains. We can take modeling clay and we can make it into just about any shape that we want. It just doesn't have very good rules of behavior. Once we've finished putting the clay into the shape that we like, and we just let time pass, basically it just kind of shrinks a little as it dries out, or if we put it in the oven, it turns into stone. But that's about all it does. So it's good for, clay is good for modeling a moment in time, but not so good for modeling things changing over time. And that's, in fact, where programming comes in. Programming a computer is, in fact, like active digital clay. What programming is all about is about, just like clay allows you to very flexibly make shapes, programming allows you to very flexibly make behaviors. So all of the things that we had here, in elements of a model, also become, let's take this for example, and to do, interesting. All of these things carry over to programming as well. And really, if you want to know, when you first start out programming, it's really just, you know, there's so much stuff, and the computer doesn't like what I said, then it's terrible. But after you get past the hump of learning how to talk to the computer, and we're using a language, we're using NetLogo, which as languages go, is really pretty gentle. It's still confusing. The computer is still a complete jerk, and you have to get everything exactly right, or else nothing happens. But once you get over that hurdle, then things that start happening wrong, happening wrong for sort of interesting reasons. It's like you've learned to speak to the computer, but what you said didn't do what you thought it was. It's not like you and the computer disagreed. It's like you said, do this, and it said, okay, I do this, and the result was not what you kind of thought it was going to be. And that's an awful lot of what programming is. But really, it's about the essence of programming is figuring out, given we have reality, we have some kind of issue out in the world that we're going to write a program to predict, to manage, to represent in some way, the goal of the programmer, the real goal is to figure out what is the model that, what objects do I want to have, and what rules of behavior do they want to have between them so it captures what is important for reality in this particular problem. And you can take the exact same reality and have two different problems and you'll have totally different objects and rules of behavior, okay? So the ultimate effort, the ultimate creativity that really goes into programming is into taking what's out there and some purpose or goal and figuring out what we need to do that is, well, we're going to represent not the train at all, we're going to represent the people in the train and we don't care if they happen to be in a train or a car or walking because what we are writing a program about is something about how disease spreads and it doesn't really care what mode of transportation, it only cares how fast they're going and how many people they're near, or whatever. So, all right, figuring out the objects, figuring out the rules of behavior and the mapping, the input and output between the model and reality is what it's all about. So finally, and then we'll wrap this up, examples of programming models. So, Solitaire mentioned it before. Computer games in general. Bank account. Weather prediction, say. As an example of scientific modeling. So, in Solitaire, the entire world becomes cards and you can put red on black and the numbers have to go down, whatever sort of rules you're playing and everything else goes and hangs and in particular, the actual act of you shuffling the cards is not generally modeled in a Solitaire game and in fact it would be a pain in the butt and the main reason it's so much more fun to play Solitaire on the computer is that it's not realistic that the obvious moves, the cards just go flying. If you've ever tried to go back and play Solitaire with physical cards, oh, I have to do it all myself, it's a drag. But you have the exact same, the exact same model in the sense that if you had a particular stack of the deck and you played it out in a computer and you played it and you won in a certain way, that with very high probability, if you stacked a physical deck the same way, laid it out, you could make all the same moves and you'd win or lose in exactly the same way. So, the Solitaire game, very predictive. Similarly, the bank account, now totally different objects, now there's accounts, so now I, me, I am represented in a bank account by an account number and a balance. And the rules of behavior are if I deposit a penny, I have a penny more. If it's six months later, it's time to give me interest and the interest rate of zero plus whatever my account is, gives me the same amount and so on. And finally, weather prediction, we're taking, you know, cubic kilometers of atmosphere and saying what temperature they have, which direction is the wind going and then making rules like, well, if the wind is going this way in this cube of air, well, then the wind probably ought to be going about the same direction in the next cube of air unless it's being pushed by other forces coming in on other edges of the cube and so on. And you can grind through that using all of the data that you have, an Albuquerque, it's 43 at 6 a.m. and so on, and you come up with a prediction. Programming is modeling. The essence of programming is not the if and the then and the while and the for loops, although that's what you do to express the dynamics, that's what you do to express the rules. But the essence of programming is what are the objects, what are their relationships? Given that you have some gnarly reality out there but you have some limited purpose, some limited intent, and it's that intention, that problem that you wish to solve that lets you say, well, I don't care about the weather, I care about the pennies. And once you get to that level, it takes some time, but it's a blast. Okay, that's it.