 Welcome back to this session on computational procedures. In the last session, we have seen written procedures for complex activities and we had also seen that the procedures must first be understood and then executed. We will now look at a computational procedure because eventually we want to learn to write programs for the computers. In the process, we will also see how a program would be executed by a computer. In the, this would exactly be in the same manner that a computational procedure is carried out by human beings. So, let us look at a problem. Suppose we have a tank which we have erected in our yard to store water. Now, the tank may rust. So, to prevent it from rusting, we wish to paint it. Now, suppose we are given the painting charges in rupees per square meter. We need to find out what will be the cost of painting the entire tank. Of course, we must not forget the top cover which will be on top of the tank. So, we need to calculate the total painting charges. Now, this is clearly a computational problem. So, we will need to make some kind of a simple mathematical model for solving this problem. First, we try to see how we can calculate the surface area. This is the picture of a tank. This tank has some radius. It is a cylindrical tank. It has some radius r and it has some height h. Those of you who have done simple geometry in your earlier classes would easily understand how to calculate the surface area. Let us look at the calculations. First, the surface area of a tank to be painted, which has a radius r and height h is equal to the area of the outer surface plus the area of top circular cover. Our geometry knowledge tells us that area of the outer surface is 2 pi r h, where r is the radius and h is the height. In exactly the same way, we can find out that area of the circular cover will be pi r square. Once we know these two areas, their summation will be the total area. Having modeled this problem in terms of the mathematical formula which we need to calculate the painting cost, we are now ready to write down a procedure for computing the cost. The procedure is written as if it will be executed by some person. So, I am telling that person get from me value of painting price p in rupees per square meter. Then get from me values of radius r and height h. Next step says calculate area a, which is a is equal to 2 pi r h plus 1 pi r h square. And the last step says calculate cost c, c is equal to p into a. Did you have any difficulty in understanding this? Observe that we have deviated slightly in the symbols that we have used. We have used small r for radius in the previous slide. Here we are using capital R, but you understand it easily because for you it does not make a difference whether R is smaller capital. It still means a radius to you. However, later on we will note that when we write computer programs, we have to be very careful because each name has to be unique and it must be used exactly in the same way that is used elsewhere to mean the same thing. Consider the steps of this procedure. Do you agree that this procedure will give you the final computed printing cost? Do you agree that this procedure will get you the final printing cost computed by this process? Sadly the answer is no. Let us examine why. Let us go through these steps again. Get from me value of painting price alright. So the person who is executing this procedure will collect the value p from me. Next the procedure says get from me values of radius r and height h. Again the person who is executing this procedure will collect from me one value for radius r and a value for height h. The next instruction says calculate area A by the formula A equal to 2 pi r h plus pi r square. The person will religiously do this multiplication of pi r square. Do this multiplication of 2 into pi into r into h. Add both these values and find out one resulting value which it will assign it to the symbol A on the left hand side of the equal to symbol. So we have got the value of area A. Next instruction says calculate cost C. The person who is executing this procedure will correctly calculate the cost C which is given by p into A. So it is the problem. The problem is that when the entire procedure is executed the person who is executing the procedure will have the cost C. But we will not have the cost. Why? Please remember we ask that person to get from us the values of p values of r and values of h. But we forgot to tell him to give us the value of C which he has calculated. Please note that a complete procedure must contain each and every instruction which will finally get us the value of C. So look at this procedure. We have to add this step here after collecting the input values, after calculating the area and the cost there must be an instruction in our procedure which says give me the value of C. That is when the person executing the procedure will give us the value of C and will fulfill our requirement of finding out what is the painting cost. We have to write such procedures to be executed by a computer. When instead of a person a computer executes a procedure like this then the procedure is called a program. We note that a computer is capable of doing exactly the same thing that the person is capable of doing while executing a computational procedure. Namely, the computer can read the entire program and understand all instructions. This step by the way is called translation or compilation. We shall explain the meaning of these technical terms later. But for the time being we note that the computer first reads the entire program and understands all instructions. Once it has done that then it carries out instructions of the program one by one in this stipulated order. This is called the execution of the procedure very much similar to the execution of the computational procedure that we just saw. Well, let us have some life experience with a hypothetical program. I have written a program. It is a test program. Of course, the instructions in that test program can be easily carried out by a human. I would like you to behave as if you were a computer. Compile and execute that program. Please understand that you have to work as correctly as possible and as quickly as a computer can. Remember that a computer can execute millions of instructions per second. You may not be able to carry out millions of steps in a second. But let us see how fast you can be. So good luck. Compile and execute this program. I will give you 30 seconds. So let us analyze this program. The first step says raise one of your hands. Next step says put down your raised hand. The third step says close your eyes and count loudly up to 10. The third one says loudly say ha ha ha. The next step says write the value of pi correct to 3 decimal places. The next one says speak loudly the name of your mother tongue. And the next step says clap 3 times. I am sure that many of you in your eagerness to execute the program as fast as a computer would, you would have done most of these things. In a classroom whenever I have tried this, almost the entire class quickly starts raising the hand, closing the eyes and counting loudly saying ha ha ha clapping etcetera. Only those few who understand that the first step is to compile a program and then only execute it. Which means you have to first read the entire program. Those who do that would have realized that the last step says while executing this program ignore all earlier instructions and just raise both hands. In fact the fastest person who correctly executes this program is one who did nothing of these steps, but just raise both hands. This might be fun, but this is what we need to remember when we deal with a computer. Let us now look at the capabilities of a computer. A computer has ability to handle numerical values. We of course expect that. For example, it can handle values such as 257 or minus 78 or 4.675 etcetera. It can also handle very large and very small value. Most of you should be able to decipher what this symbol is a means. 1.4 e 18 actually means a value 1.4 multiplied by 10 to the power 18. Similarly, this value means 0.356 multiplied by 10 to the power minus 9. Observe that this value is very small. This value is very large, but a computer is capable of dealing with such very large and very small values subject of course to a limited precision as we shall see later. The computer of course has the ability to carry out numerical operations. For example, it can add, it can subtract, it can multiply, it can divide. For addition and subtraction and division, we use the symbols plus minus and slash. For multiplication, however, most computers use a symbol star. Can you guess why? Ordinarily when we want to depict multiplication on a piece of paper, we say something x something. The symbol x which is used for the later x is also used to denote multiplication. But because computer programs do not want to be confused with letters and symbols, they use the symbol star for indicating multiplication. More importantly, a computer has the ability to collect values from us as input and to give back to us the calculated result as output. It has ability to store these values temporarily. So, there will be a notion of a memory location which we shall see in the next lecture. It also has ability to refer to these locations by symbolic names. In summary, the computer programs are usually computational procedures. These will generally involve collecting some input values from the user, performing calculations and getting some result values and giving back the result values as output to us. Thank you.