 So, welcome back to the continuation of the previous session. As I mentioned, I will very briefly discuss what is titled here as Hemchandra's problem. Actually, it should be renamed as Virahanka problem. I will mention the reference later. The objective of this particular example will become a clear as we discuss this example. Please note that what I have been trying to emphasize is that teaching our students the basic skills in control structures and data structures is important and critical. But once they learn those basic skills, what exactly to do with those skills, what programs to write depends upon the problems that we wish them to solve. Each problem should be so chosen that it illustrates not only the proper translation of algorithm into a program, but it also relates to some interesting real life problem which our students can relate to. So, here is an example where I start with a problem which is both real life as well as slightly artificial. The real life connection is established through an example of talking about building a wall. A wall is built using bricks. We will convert it into some kind of a permutation combination problem and then try to see how this problem is solved. This particular problem of course has a greater relevance as I mentioned at the very beginning. This is the first time we will talk about a recurrence relation to our students. So, here we go. Suppose I have to build a wall of length 4 feet. Suppose I have bricks of only 2 sizes. One brick which is 2 feet long and another brick type which is 1 foot long. I have a large supply of 2 feet bricks and I have a large supply of 1 foot long bricks. The question that is being asked is that if I have to build a wall of length 4 feet in how many ways I can lay the bricks so that I can fill the length of 4 feet. This is very simple. The length is 4 feet. There are 2 feet bricks and there are 1 foot bricks. How many different ways in which I can fill up this length can be easily imagined by our students? We write those possibilities. One, there can be 4 bricks of 1 foot long. So, I cover the length 4 feet. Second, I have a 2 feet brick and 2 bricks of 1 foot each. Third, I put 1 foot brick first, then a 2 feet brick and then a 1 foot brick. Fourth, I put 2 1 foot bricks first and then put a 2 2 feet brick. And lastly, I can choose 2 bricks of 2 feet each. So, these are the different ways in which I can use 2 types of bricks 1 foot long and 2 feet long to fill up the length of 4 feet. Having done this, suppose we ask the question in how many ways can this be done if the length of the wall is say 3 feet or if the length of the wall is 5 feet or the length of the wall is 8 feet. Now, individually for any length that we have, people can work out all the possibilities. However, our aim is to illustrate that there is a certain pattern in the way the bricks can be used to fulfill any given length. This is explained in the next slide here. These are the possibilities if the length of the wall is 3 feet, 4 feet or 5 feet. So, here are the possibilities written if the wall is only 3 feet long. One, I can use 3 bricks of 1 foot each. Second, I can use 1 brick of 2 feet first followed by 1 brick of 1 foot long. Third, I can start with 1 foot long brick and then add another 2 feet long brick. So, there are exactly 3 possibilities if I want to build a wall of 3 feet length for laying down the bricks. 4 feet wall we have already seen. I have repeated all the possible ways here. If I were to have a 5 feet wall, then I can write the various possibilities here. Notice the possibilities are written in a peculiar fashion. What is this fashion? The fashion is that I notice that for example, if I have to build a 4 feet wall, then the number of possibilities are worked out by first taking all the possibilities in building the 3 feet wall, repeating them here and then adding just a 1 foot break for each of the possibilities. So, there were 3 possibilities in which the 3 feet wall could be built. I take each one of those possibilities, add 1 foot break and then I will get the possibilities, some possibilities for building a 4 feet wall. This is natural because I have a 3 feet wall. If I add one more foot to it, it becomes a 4 feet wall. So, it is natural that I add 1, 1, 1 here and I will get a 4 feet wall. But additionally in a 4 feet wall, I have 2 more possibilities. I can have 1, 1, 2 and I can have 2, 2. That means I added 2 more possibilities in which the last brick is 2 feet long. In all the first 3 possibilities, the last brick was 1 foot long. This is the crux of the observation by Hemchandra and even before that by Virahanka. I will explain that later. But let us look at this in a more systematic way. So, let us go to the next slide. Here it is shown that the possibilities for building 4 feet wall are partially determined by the possibilities of building a 3 feet wall and by adding one to it. In addition, I have 2 more possibilities. Now, if you notice carefully, these 2 possibilities emanate out of considering the possibilities of for building a 2 feet wall only. If I were to build a 2 feet wall, I will have a 1 foot and 1 foot brick or I will have a 2 foot brick. So, there were 2 possibilities. For each of these 2 possibilities, if I add a 2 feet brick now, I get a 4 feet wall. So, 4 feet wall essentially can be built in how many ways? 1. As many ways, I can build a 3 feet wall by adding a 1 foot brick and plus as many ways, I can build a 2 feet wall and add a 2 feet brick. Now, I extend this further to 5 feet wall. So, if I go to the next slide, I have shown it here. What is this 5 feet wall? The 5 feet wall contains combinations which were all there in the 4 feet wall. For each of the possibilities of building the 4 feet wall, I take all these possibilities and add one more brick. I get a 5 feet wall. Additionally, if I take the possibilities for building the 3 feet wall and put them here in addition to the earlier possibilities and add a 2 feet brick, then I will get a 5 feet wall. This leads us to the conclusion that the possibilities for 5 feet wall is the possibilities for 4 feet wall plus 1 brick added and plus possibilities of 3 feet wall plus 2 brick added. What it means is, if I just look at the total number of possibilities, then the total number of possibilities are simply the number of possibilities for building a 4 feet wall plus the number of possibilities for building a 3 feet wall. If I add these two possibilities, I get the possibilities for building a 5 feet wall. The actual problem which Virahanka and later Himchandra Tackle was slightly different. The Virahanka's actual problem was that of building a poetic meter. Now, I do not know how many of you are familiar with poetic meter, but it is suffice to tell our students that a poetic meter is made of short syllables and long syllables. So, a long syllable l has 2 beats and a short syllable s has 1 beat. Please note now, people can relate this 1 beat and 2 beats to the 1 foot long brick and 2 foot long brick. Just as an example of a poetic meter, you can take any one of the standard poems or songs that you come across. Here is an example that I have chosen from something which is well known in India. This is part of the Saraswati Vandana, Ya Kundendutushara Haara Dhavala, Ya Shubhra Vastravrata. I have written this line and I have shown the syllables which are used in this particular line. So, Ya Kundendutushara Haara, these are all long syllables, Ya Kundendutushara Haara, like that. So, you have long, long, long, short, short, long, short, long, short, short, etc. And this particular sequence is an example of a poetic meter. Now, the question that Virahanka raised is, if I am designing a poetic meter with 8 beats, how many ways are there of filling 8 beats? You will appreciate that my student who has first seen the example of Brex and which he or she can relate easily to, will find it very simple to extend that example to the concept of determining the possibilities in which such a poetic meter can be constructed of as many beats as we prescribe. Here, we are saying that if I am designing a poetic meter with 8 beats, how many different ways of filling these 8 beats are? The interesting solution by Virahanka was to simply say that if I follow the method of Pingala, Pingala was a person who lived in 200 B.C. There is a mathematician poet of that era. Then, according to that method, it is enough to observe that the last beat is long or short. Very interesting. He is saying the number of possibilities can be determined by merely observing whether the last beat is long or short. Let me go back a few more slides to emphasize this point from our example of the Brex. If I want to determine how many ways a 5 feet wall can be constructed, I have to write all the ways. If I observe whether the last brick is 1 foot long, that is short brick or the last brick is 2 feet long, which is the long brick. If I combine the number of ways in which the last brick is 1 foot long or effectively for poetic meter, the last beat is short. All the possibilities where the last beat is long or the last brick is a longer brick, then I automatically know the total number of possibilities for the 5 feet wall or a 5 beat meter. Let us go back to the next slide here. Here is another point that Professor Abhiram Ranade had stressed during his lecture. Although I find that he has not emphasized it in his textbook, but please notice that Hemchandra is giving credit to someone who lived more than 1000 years before him. In Hemchandra's writing and also in Virangaka's writings that have been since, both mentioned the method of Pingal, that means they are giving credit where it is due. Moral for us academicians and this is interesting and useful to emphasize to our students copy if necessary and if permitted. Pingala, Virangaka and Hemchandra were obviously the firm believers of open source knowledge. So, they have left all their knowledge without any incumbency of intellectual property or whatever anybody can use it, but it is correct. So, therefore it is permitted. However, it is important that when we copy, we always give credit. I think this is not related to programming, but this is an important lesson that we should all like to empathically tell our students to internalize. Anyway, let us go ahead with this discussion. So, the original solution said that an 8 bit pattern can be made of take any 7 bit pattern and add a short bit or take any 6 bit pattern and add a long bit. Very obviously, then the total number of possible 8 bit patterns is simply the number of 7 bit patterns plus the number of 6 bit patterns. In short, the number of 8 bit patterns is equal to the number of 7 bit patterns plus the number of 6 bit pattern. I hope now all of you are realizing what I am leading to. Algebraically, if h n is the number of patterns with n beats, then h 8 is equal to h 7 plus h 6 and in general h n is equal to h n minus 1 plus h n minus 2. Anybody who can recognize this relation does this help us to compute h 8? Yes, provided we know the value of h 7 and h 6. Well, does this formula help us to calculate h 7? Yes, provided we have the value of h 5 and h 6. This is a beautiful way of telling our students of what a recurrence relation is. A recurrence relation is built step by step starting with some initial value. The recurrence formula is simply h n is equal to h n minus 1 plus h n minus 2. Let us use one more slide to explain to our students how do we calculate successive values of h n. So, we say we start with h 1 which is the number of patterns with 1 bit which is just 1 say short bit. h 2 which is number of patterns with 2 bits which are 2 short, short and long. h 3 which is the number of patterns with 3 bits which as we saw from the recurrence relation will be h 2 plus h 1 which is 2 plus 1 and we can verify that indeed there are 3 possible patterns short, short, short, short, long, long, short. Subsequently when we tell our students this formula we need not elaborate and write down all the possible combinations, but people will understand it. What is more important from the point of view of learning to program this problem is to illustrate that h 4 is equal to h 3 plus h 2 which is 5, h 5 is h 4 plus h 3 which is 5 plus 3 which is 8. We have already given a sample illustrative example figuratively for these 5 and 8 ways by the example of all the bricks. By now students will very clearly understand that if I continue evaluating this recurrence relation for h 6, h 7 finally I will get the value of h n. We now know that my dear students to calculate the value of h n we need to use two previous values. By using any two previous values we can calculate the next value. Now this is a recurrence relation. Some of us might want to elaborate something more about recurrence relation at this stage. Some others like me would say that we will worry about the notion of recurrence at a later stage, but at this juncture we will just note that h n is equal to h n minus 1 plus h n minus 2 is a recurrence relation. However, we would like to use an iterative method to solve this problem. In this iterative method we can start with two values and then successively calculate the subsequent value. Now comes to the program design crux. We know the algorithm already. We need to use two previous values to calculate the next. We want to use an iterative solution within the iteration. Every iteration will do the following. It will use the current and the previous values to calculate the next value. Now that is not sufficient because whatever variable we store the current value in and whatever variable we store the previous value in will retain the same value if we blindly come back and iterate around this again. What we need to do is, before going to the next iteration we have to reset the current and previous value. So, whatever next value we have calculated must become the current value and whatever was the current value earlier in the loop must become the previous value. So, that is why I have stated reset these appropriately before the next iteration. And there is an additional comment made. Start with the first two values h 2 and h 1. You can give an example. I have written here in the slide that you can say h current h brave h next. By the way these are clearly the intuitive ways of naming the variables. Of course, people can use any names that they choose, but here I have chosen to use the words h current and h brave for the previous term and the current term. Using these I will be calculating the next term. I have written here starting values. You may use the white board or a transparency or whatever in your lecture, but do consider the following. Write down a set of at least some initial steps here. So, first iteration calculation. It is best for you to use such a sort of drawing on the board and write down physically against this what will be the value of h next. It will be simply 2 plus 1 that is 3. Now, against this reset the two values what you have to do is you have to say the value 3 becomes the h current value, but before that the value h current goes into the h brave. So, when I go to the second iteration I would have h current as 3 and h brave as 2. This resetting has to be explained to the students. As I said you can use either a slide and write on the slide or you can use a white board where you actually show demonstrate how things change in every iteration. I would like you to appreciate that while you and I as teachers who would have known the iterative solution for recurrence relations many times over, we will assume that resetting the two values is something which will happen automatically in our minds. Unfortunately for the first year students it is not very easy for them to understand that there are two variables whose values need to be reset before you go to the next iteration. That h proof must be reassigned the value of h current and h current must be reassigned the value of h next before you go to the next iteration is important. It is therefore useful to always show this draw the diagram and write down the values as they change. It is only after this that we can go over to write the program to compute h n. Interestingly the program is extremely simple. It says collect the value of n which m channel number you want to compute whether it is h 5, h 8, h 10 or whatever. Then I start with the initial values int h proof and h current. h proof is assigned the initial value 1, h current is assigned the initial value 2. I also define the variable h next which at any point will be the next him channel number calculated. I set up an iteration now. Please notice that I cannot calculate the first and second number by using that relation. These are predefined values which are assigned by knowing that the first value is 1, second value is 2. Very obviously if somebody gives an input which is 1 or 2 the program will not work correctly. The loop says for int i equal to 3 i less than equal to n i plus plus. So the first iteration starts with i equal to 3 then it will be i equal to 4 and so on. It simply writes down the assignment statement h next is equal to h proof plus h current. That is all you have calculated the next n channel number. But if you want to go to the fourth and the fifth and the sixth you will have to reset those values as I said. Here is a comment which says prepare for next iteration by shifting values of objects which are these objects h proof and h next. So I say h proof equal to h current and then I say h current is equal to h next. Having done that this iteration will continue till n. When I come out it is very obvious that the last value calculated of h next will be the one which will be the nth Hemchandran number I output that. So notice that even though the program is only a five six seven line program for many students this logic of resetting the values before the next iteration will be slightly cumbersome. They would have done similar things earlier in the context of some other example. But in the initial days when we engage the students in their understanding iterative solution it is useful to emphasize that such resetting will be almost always a basic feature of most iterative solutions that we set up. In the earlier problem the mere change in the value of I took care we did not have to reset anything. But in a majority of the problems we will have to preserve the value that was computed in the previous iteration as the starting value for the next iteration for some purpose or the other. In this particular case there are two such values. Professor Ranade calls this mathematics from poetry and I agree with him. This interesting series has been since well-known and the reason why it has become well-known is that a European scientist extended this series to many interesting usage. For example number of petals in many flowers ratio of consecutive terms of this series tends to a limit which is known as golden ratio. Now all our students and all of us know these more commonly as Fibonacci numbers. Hemchandra and Virahanka who actually given the Pingal Sutra solution lived before Fibonacci and Pingal lived several centuries earlier. I like this example for another reason. It is only recently that the correct attribution to the original discovery of Fibonacci numbers has been given back to the Indian origins. If you look at the Wikipedia article it clearly mentions and in fact there are several recorded historical documents which indicate that Fibonacci himself admitted that he learnt about this interesting series from some Arab scholars when he was visiting Arabia. And that several Arab scholars mentioned to him that the basic theme for these sequences they learnt from some Indian scholars. That is how the history has been traced back and has been established. Nothing very big about it and nothing much related to computer programming really. But it is a point that we should make to our students that while much of very useful knowledge has come out of innovations, discoveries and inventions from the developed countries. There are several important Indian discoveries which ought to be remembered by us rather proudly. I will stop at this juncture. There are some hands raised. Let me go over to Dronacharya College of Engineering. Yeah, I have given this solution of bi-state description of patterns which you have just discussed through Fibonacci series. Fibonacci series is generally the bi-state pattern descriptor which depends on two of its previous states. And whatsoever the two previous states are if we append those two states then we get the current one. That is the generator of Fibonacci series generator. Very good. Thank you so much. Let us go over to some other institution. Is Vivekanan College of Engineering? Sir, I am Malathi from Vivekanan College of Engineering for men and women. I am interested in the relationship between the Dutunaki series and the Hamachandra series. Oh, okay. The relationship is very simple. They are identical, exactly the same series. In fact, this is what I tried to explain. Hamachandra sequence or Virahanka sequence as it is now more correctly called is nothing but the Fibonacci sequence. And in fact, the Fibonacci sequence is not the right name as has been established now. It ought to be known as Virahanka sequence. So, there is no question of any relationship. They are exactly same. They are identical. It is just that the name Fibonacci is more popular because that is what got printed and circulated everywhere. But it has been established that the initial discovery of this series happened in India. That is all. The name is different, nothing else. Okay. There is a hand raised by a C.S. graduate school of teaching. I am Aparna Vandoru and he have total seven participants over here. And the question is, can we use this, the first example which you have showed us finding out the logarithm. Can we use it for double, triple, integral and extend simultaneously for first year students to explain? Interesting question. So, my answer is as followed. Yes, I can actually extend it, but the issue here is not so much to solve complex integral calculus problem. The issue here is to explain to first year students how to do approximation of an integral value and how to implement that using a computational procedure for which we can write programs. My suggestion madam would be that we should spare our first year students in very complex mathematical theory that they will learn in due course of time. But in the subject of computer programming, while it is important as you point out to relate to the issues of integration and so on, but the emphasis must remain on translating such approximation methods into computations and to write program. So, I would suggest avoid double integrals or triple integrals in the first year level. In fact, students will get completely confused with the integration process rather than concentrating on programming. That is my view of course, but the question is well taken. Thank you. Let us go over to another question that has been raised here. SVP Engineering College. Sir, we would like to know about a particular aspect as far as the university syllabus is concerned for the first years in our college. We have numerical methods as well as computer orientation being written in C programming. How better it is to make student ease with numerical methods along with programming? First of all if that is the university syllabus then it is necessary to fill that up. Our own opinion in IIT is that in the first year you should teach the basic skills in programming and in the second semester courses like numerical analysis etcetera could follow. Traditionally please remember that numerical analysis is a subject which has been taught even before there were computers and quite often it was taught at the elementary level. That is how it has remained perhaps as a first year first semester course. If that numerical methods course is there and the computer programming is also taught perhaps some coordination by two teachers will ensure that whatever numerical methods are covered in the numerical methods subject are also used by programming course teachers to implement the corresponding computer programs. My own opinion is that a course in numerical methods using computers should follow a programming course. As regards the other part of your question that C program is mandated by the syllabus I would urge you to work with your university not to a particularly state that only a particular language like C should be used. Professor Ranade has already mentioned the problems in using plain C programming because you have to start with scanf and printf which people will have to just mug by heart because they really cannot understand why pointers are being used here and what is the method of formatting string when they do not even know the string. Please also note that all the examples that we use in IIT Bombay are actually C programming examples. We do not use any C plus plus specific construct in the entire course except towards the end when we introduce the notions of object oriented programming. The only syntax that we have used which is non C syntax is C in and C out. I will take your point in one of the sessions here we had used some macros to define some very simplistic input statement such as input integer or output integer which would map into a corresponding scanf and printf statement. The major difficulty in teaching C programming in our opinion is the clumsy syntax. C was never designed as an introductory programming language but C has come to be used as an introductory programming language. It is my personal wish and the wish of almost all faculty members in IIT Bombay who have taught programming that universities will now define a syllabus for first year programming course which they will generically say C plus plus. However, the syllabus will make it clear that in the initial period of the course only procedural programming should be taught and the object oriented programming should either be a matter of a second semester course which is there in many universities or could be very briefly introduced in the first course. Sorry for this elaborate answer but I understand that this is an important point but I would still suggest that much of the material that we are generating in this workshop effort is usable by the teachers at least partly by appropriately modifying the computer program if you have to insist on C programming in your college. Thank you so much. Now we will stop at this juncture.