 Hello, welcome to the second lecture sequence of the first week of the NPTEL course on an introduction to programming through C++. I am Abhiram Ranidhi and the reading for this lecture sequence is chapter 2 of the textbook. So in this lecture, we are going to ask some basic questions, really one basic question and provide some very high level answers to it. So basically the question is how can a computer do so many things? It can search for information, predict weather, process pictures, pledges. In this lecture, we want to provide some high level answers, not detailed answers but sort of just to make things plausible. So all these tasks seem too difficult and too unbelievable. So we are going to provide you just the small amount of information which will make them seem a little bit more understandable. So the answers are going to be of the following kind, we are going to argue, we are going to propose really not a detailed argument, we are going to propose that most real life problems can be viewed as mathematical problems or problems on numbers. And a computer can be made to solve mathematical problems. Well, this statement is a little misleading because a computer does what it is told. So if we can solve that mathematical problem, then we can tell the computer go ahead and solve it. So in that sense, a computer is good at solving math problems. So these high level answers we are going to provide and the hope is that these high level answers will give you enough background for whatever happens later in the course. So here is what we will do. We will see how to express real life problems as numerical problems. So we will take examples of feature processing, predicting the weather and processing text or language. Then I will talk about algorithms and programs. Then I will tell you how a computer really does all these things. So this will be a really whirlwind introduction to digital circuits. So a topic which can take courses in electrical engineering. But we are going to again go through it at a very high level. So I will tell you how a digital circuit works, how numbers are represented using electrical quantities. I will tell you what the parts of a computer are and I will tell you the notion of a machine language program and compilation. So all these things together will be background material for what happens later in the course. So let me start with this question. So you see this colorful picture in front and if I ask you what is in this picture, you could tell me right away that there is a chameleon. By the way, this is taken from a Wikipedia page. Now we would like a computer also to do it and in fact today computers can do it. A computer will tell you that there is a chameleon. How does a computer do this? Well for that we need to know how to represent pictures using numbers. So I am going to start off with black and white pictures. So how do you represent black and white pictures using numbers? Suppose I have a 10 centimeter by 10 centimeter picture. So I am going to divide it into tiny squares. So each square says 0.1 millimeter by 0.1 millimeter. So the side length is 10 centimeter and the side length of the small square is 0.1 millimeter. So really there are 1000 squares on each side. So 1000 by 1000 that is the total number of squares or 1 million squares or pixels are there. Now if one of those million squares is mostly white, we are going to represent that whiteness as a 0. If it is mostly black, we will represent it as a 1. So for 1000 by 1000 squares picture, we will have a million numbers. So we will have a sequence of million numbers which will represent that picture. Here is an example. So that smiley face on top of that I have put smaller squares and as you can see say a square over here, square somewhere over here is mostly white so I get a 0 over here. Whereas this square is mostly black and so I get a 1 over here and so in this manner I have put 1s and 0s. So this is going to be a representation of this picture. Now I would like to note this representation is not perfect. So really if you give me this, I will be able to say that look the picture could be something like this as well and this is not really the same as this picture but it is close enough and in fact you can observe that if I make the square smaller and smaller, I will get a better and better representation of this picture. So if instead of having 1000 by 1000 pixels, I divide it into a million by million pixels then I will get a nearly perfect representation. In fact it turns out that really 1000 by 1000 is not bad. Your screen, this screen for example is probably having something like 3000 by 2000 or something like that and yet you cannot make, you cannot make out that it is made up of small squares. Then other things are also possible. So a square may not be completely white or completely black. So there may be some gray levels. So instead of using 0 or 1, you could also use the number 00.1, 0.2 and so on. So you might have different gray levels, so numbers to represent different gray levels. So your numbers are not just 0s and 1s. So it is not just sequence of 0s and 1s but a sequence of 1 of 10 numbers whatever or whatever 11 numbers. What if you have color? Well colors can be broken down. So a picture now is going to be made up of 3 sequences, a sequence for the red component, a sequence for the blue component and a sequence for the green component. The actual color is made up by adding these components. So that is how a picture is represented. Now what can we do with such pictures? Well we can ask questions like is there a chameleon in it or what is in it? So typically what do these problems look like? So we are given as input a sequence let us call it P of a million numbers and let us take our simplistic picture which is a black and white picture 1000 by 1000 pixels. So there are a million numbers 0 and 1 and these pixels are given to us in top to bottom left to right order. So these are representing a 10 centimeter by 10 centimeter black picture given in left to right top to bottom order like the way you would write text on that page. Now instead of worrying about chameleons let me pose a very trivial not even a problem which might be of interest to a child but a really really trivial problem. What is the problem? Is there a vertical line in this picture? So let me draw it here is my picture and suppose there is a line in it so I am asking is there a vertical line that is all that I am asking. So what do you do with such a question? How do you represent this question using numbers? So you have to ask what property does the sequence need to have if it is to contain a vertical line? Well if I take this picture and convert it into numbers what is going to happen? So I am going to get lots of zeros but suddenly there might be a 1 again lots of zeros then lots of zeros over here then there is a 1 in the same column lots of zeros 1 in the same column zeros here zeros here and maybe all zeros here. So the point is that there is a 1 for some rows some consecutive rows of some column. So can I describe what pattern this sequence of zeros and ones is going to possess? Well here is the pattern suppose the first one is in the ith position where is the next one going to be? Well how many steps are you going to go from here to here? So you will go all this distance you will go all this distance. Remember that the zeros and ones are given to you in the top to bottom left to right top to bottom order. So if an 1 occurs in the ith position then next one will appear in the i plus thousandth position because there are because this distance is 1000. The 1 after that will appear in i plus 2000 position i plus 3000 position and so on. So in fact that is exactly the pattern. So there are going to be 1s in position i, i plus 1000, i plus 2000 and so on for some i. So at this point we have described what it means in mathematical terms for there to be a vertical line. Is there a vertical line is as good as saying does the sequence p of 1s and zeros satisfies this property that for some i there are 1s in positions i, i plus 1000, i plus 2000 a few such entries. Now how do you solve this problem? So this problem is actually quite easy you can try out different values of i. So you can check is there is this pattern valid for i equal to 0. If it is valid for i equal to 0 that is as good as saying that there is a pattern right here that there is a line right here. So this effectively for different values of i will give you different lines and then if you find that is for some values of i this pattern is actually there then you can claim yes there is I have found a vertical line. Now the question does this picture contain a chameleon? In principle is identical okay why again you have to you need to identify a set of properties that the sequence of numbers representing the picture must satisfy in order for the picture to contain a chameleon. These properties will be really complicated but some properties will have to be identified there is no escaping this step then you will have to decide how do I check whether these properties are satisfied. Again this is a difficult mathematical problem but it can be solved okay and in principle it is the same problem that we saw that problem was a trivial problem but again for the vertical line but again the problem was similar in principle that you needed to identify a set of properties and you needed a procedure for checking whether the pictures satisfied those properties. So in practice this requires enormous ingenuity and but people have displayed that enormous ingenuity. In fact this is the main concern of a deep subject called computer vision. We are certainly not going to study computer vision in this course but all that I wanted to point out to you was how basically that subject works that subject works by representing pictures in terms of zeros and ones by associating a property that that sequence of numbers has to have if it is to contain a certain object and designing computations which will decide whether that property is satisfied by a given picture. Let us turn to one more interesting problem you hear the weather report and you may wonder how do they do that. So here is what happens again at a very very high somewhat superficial level. So they divide the surface of the earth into small regions just like you divide a picture into pixels and for each region you are going to have variables say P i, T i and H i which represent the pressure, temperature and humidity in that region. Now we know enough physics to say if you tell me the pressure, temperature and humidity in a certain region and not just in a certain region but the regions nearby so adjacent regions or regions which are not too far something like that then I can calculate by using laws of physics which are mathematical in nature what the future temperature pressure and humidity are going to be. So if we measure the current pressure, humidity and temperature then we can calculate what happens say 1 second from now on but then we can calculate 2 seconds, 3 seconds and we can eventually calculate what will happen tomorrow. Now I have greatly simplified what is actually going on but what is going on is in essence this. So we are using physics we are talking about values of things like pressure, temperature, humidity and we are using laws of physics to say how they are going to change and this requires lots of computations but that is what computers are for. Then like picture processing if we make those regions smaller and smaller then we will get better accuracy why because if a region is large then it does not make sense to ask what is the temperature in that region because in one part of the region the temperature might be high in another part the temperature might be low but if the region is really tiny then you can say oh roughly it is the same temperature in that entire region just like picture processing. So if you make the region smaller then that means you are actually having to do more calculations but again as I said that is what computers are for. Computers can also process language of course they can do searches and you might be wondering how do they do that. Well here is a very simple scheme again this is this is too simple lot more sophisticated things happen but let me just tell you one plausible idea. So first we begin by defining a code for representing letters and the code that is commonly used is the so called ASCII code which stands for American Standard Code for Information Interchange. In this code the little a letter is represented by the number 97 the little b is represented by 98 the little c by 99 and so on so consecutive numbers are given for consecutive letters lower case letters and similarly some numbers are given for uppercase letters as well and not only letters but symbols say the equality symbol has an ASCII code digits also have ASCII codes so 9 as a number is different from 9 as a symbol that you see on the screen and the space character also has an ASCII code. So what is a word? A word can be thought simply as a sequence of ASCII codes for the letters in that word. So computer for example can be represented by the ASCII code for c o m p u t e r. If you check 99 is the code for c in fact it is the next code after 98 which we said is the code for b. So clearly it is the code for c but if you check the rest of the numbers are in fact consistent with this idea and they are in fact the codes that are used in ASCII. So a computer is a sequence of numbers what is the sentence or a paragraph well they are simply larger sequences. Now you can ask does the word computer occur in a certain paragraph what is that question? That question is simply the question does a certain sequence of numbers occur inside another sequence of numbers that is it. So if you can answer queries like this very quickly you can do searching for words in books or web pages or whatever you have. So here are some thought exercises that I would like you to do. So these are these are mental exercises I just want you to think about it because these are the kinds of questions we are going to ask later on and later on we will try to have very precise answers. So for example we talked about how do you represent how do you represent the fact that a certain picture has a vertical line well in a similar manner I would like you to think about what patterns of 1's and 0's would correspond to a plus of any size being present at the center of an otherwise white picture. Another question that I would like you to think about is suppose you are given a sentence in a language you cannot understand but you are given a sky course would you still be able to count the number of words in the sentence. So could you express this as a question on a sequence of the sequences of numbers representing the sky course of the different characters. How will you represent chess playing as a question on numbers or how will you represent a chess position for example. So once you can express a chess position as a number then you have a foot in the door to say to asking questions about what is the next good move what does it mean for the white rook to capture a certain pawn or something like that when can a rook capture a pawn. Those questions will start becoming amenable to analysis once you first decide what does it mean to represent a chess position. So what have we discussed we have said that questions about pictures whether documents can be converted to questions about properties of number sequences and these are just examples. The implication is that basically any question we should check whether it can be converted to a question about numbers and that is when we can solve those questions on a computer. But answering these questions requires solving interesting math problems so it does require a lot of ingenuity. So we will stop here and take a break.