 And welcome to the NPTEL course on an Introduction to Programming through C++. I am Abhiram Ranade. The lecture of today is on Virahanka numbers. Virahanka was an ancient Indian prosodist from the 6th or 8th century. And prosodists are people who study patterns of rhythm and sound in poetry. Virahanka asked a question about poetic meters and interestingly enough solved it using recursion. So that is what we are going to study today. So let me tell you a little bit about what a poetic meter is. A poetic meter is characterized by the number of syllables in the meter and the duration of each syllable. So syllables have either a short duration or a long duration and the long duration is just twice the short duration. So for example, a poetic meter could be described by the sequence of characters S L S S L S. So that means that there are 6 syllables and the total duration is 8. The additional 2 counts come from the 2 long durations. So let me give you an example for a poetic meter, an actual poetic meter. And here is a poetic meter called Shardul Vikridith. So this is used in many many poems and many many shlokas. And perhaps here is a familiar shloka that is in this meter. So I am going to sing the shloka and you will note that some of the syllables are going to be short and some of the syllables are going to be long. And it is the long and short, the long and shortness of the syllables which gives it, gives this shloka a certain character and that is what a poetic meter does. So ya kundendu tushara hara dhavala ya shubh bravastra vruta. So as you can see the first ya is a long syllables, kund is a long syllables, den is a long syllables. But then you sing ya kundendutu, so dutu are short syllables. So overall there are 19 syllables and the total duration is 30 if you count it. So prosodists were concerned with such poetic meters and they asked questions such as how many different poetic meters can there be and they sometimes even wanted to enumerate the poetic meters. So Virahanka's question was how many poetic meters exist of total duration d? So let us try this out, let us take a few simple cases. So if d is equal to 1, so you want a poetic meter of duration 1, well you do not have a choice. The only poetic meter possible of duration 1 is sort of a very trivial thing, a poetic meter which just has one short syllable. If you go to duration 2, then the duration 2 can be made either by one long syllable or it can be made by two short syllables. So at this point you have two possible meters, 3 if you work this out, if you try this out and if you try to do this exhaustively what do you get? Well you get that duration 3 can be made up by three short syllables or a short and long or a long at the short. So there are three poetic meters of total duration d. And for d equal to 4, you may again work this out. So there might be all four shorts or you might have SSL, SLS, LSS or just two longs. Now we want to ask this question in general and so let us say that v of d denotes the number of poetic meters of duration d. And what we have worked out is that v of 1 is 1, v of 2 is 2, v of 3 is 3 and v of 4 is 5. Virahanka wondered whether there is an easy way to calculate v of d. So that was his question and we are interested in this not because this is a course on poetry or prosody or anything like that but because this question has some interesting things to say about recursion. So let me tell you Virahanka's solution. So Virahanka observed that the first syllable of every meter must be S or L. Of course I mean there is nothing much over here but that is just the first step. So then he said that look let me use S of d to denote the set of meters of duration d in which the first syllable is an S. So let us take an example just to make sure that this notation is clear. So if you take d equal to 4 then the set of all meters of duration 4 which we just worked out is this and of these the first 3 have the first syllable S. So S of 4 is just those first 3 meters. And L of d we are going to use to denote the set of meters of duration d with first syllable L. So clearly L of 4 are the remaining so these 3 belong to S of 4 these 2 are the remaining ones from all the set of all meters of duration 4 and they clearly belong in L of 4. And clearly V of d the total number of meters of duration d must be equal to the short meters plus the long meters and since S of d and L of d are sets we are just taking the sizes of those sets. So checking it for d equal to 4 what we have is V of 4 is 5 which we counted over here and 3 of these comes from the short syllable first and 2 of these come from the set which has the long syllable first. So I am just using d equal to 4 just to make sure that our notation is being well understood. Now here is the key question to ask which Virahanka did. So suppose I remove the first letter from every meter in S of d what happens? What is what remains in S of d? If you remove the S from anything the duration will decrease by 1. So you started off with meters of length d so if you remove the first meter which is going to be S in the set S of d then you will be left with meters that have duration d minus 1. And interestingly enough not only will you be left with meters which have duration d minus 1 but in fact you are guaranteed to have all meters of duration d minus 1 after you remove the first syllable from the meters in S of d. So again let us go to our running example. So we have S4 which is this and let us remove the first syllable from these. So what do we get? Well from this 4 SS we get 3S SSL gives us SL and SLS gives us LS. So indeed if you look at the durations of these meters they are 3 and if you look back to what we did earlier these are exactly all the meters of duration 3. Now we should probably prove this so here is a very simple proof. So I am going to do it with respect to this set but you can see that it is really a general argument. So suppose this was not the entire set of meters with duration 3 and maybe there was some additional member that we did not have in this set. So suppose I take that additional member which has to be different from this and I add an S in front of it what do I get? So I will get a meter which starts with S and has total duration 4 but then that would have to be present over here. So either but that clearly is not the case so that means this is a set which contains all meters of duration 3. And since the number of all meters of duration 3 is V of 3 in general I can say the size of the set S of D must be V of D minus 1 because after I remove one letter from all the meters the number of meters in this set does not change. So that continues to be the cardinality of S of D and now we have established that is the same as the number of meters of size D minus 1 and therefore that must be equal to V D minus 1. So we can do the same thing removing the first letter from all meters in L of D. So what do we get? Well if you remove the first letter from L of D, L has duration 2 so now everything that remains will have duration D minus 2. So in fact not only will the meters that remain have duration D minus 2 but in fact by the same argument all meters of duration D minus 2 will be present. So again let us check this if I look at this L4 if I remove the first L what do I get? I get this and indeed these are all meters of duration 2 there are only 2 meters of duration 2 and these are here. So again the number the size of L of D must be equal to V of D minus 2. So combining this, this and this what do we get? Well V of D is cardinality of S of D but that is V D minus 1 plus L of D that is V D minus 2. So this is what we get and I should observe that this is valid only for D greater than 2 because if D is not greater than 2 then V of D minus 2 would not be bigger than 1 and our formulae all our discussion is for having at least one syllable in the meters that we are talking about. So our discussion is really about, so in our discussion whatever sets we are talking about should have say V of D so this has to be bigger than 0. So D had better be bigger than 2. So what have we discussed at this point? Well, so we have introduced Vran K's problem and that was find the number V D of poetic meters having duration D and we can work out by hand that V of 1 and V of 2 equals 2 and we said that working out larger V of D by hand is tedious and error prone and so we derived a relationship which is that V of D equals V of D minus 1 plus V of D minus 2 for all D greater than 2. Next we are going to write a program to calculate V of D but let us take a short break.