 of today's talk. So we are going to look at our CPP Dumbo, who executes our C++ programs. We'll revisit numerical computations, specifically looking at how the values, numerical values are handled and how arithmetic operations are done by our CPP Dumbo. Then we'll actually program Mr. Dumbo to do some numerical computations. I have already made the announcement for makeup lab, so we are done with it. So as we have already noticed, our C++ Dumbo can read and understand programs written in C++, and of course, he can execute these programs. We have already seen how Dumbo allocates memory locations to store values and manipulates those values. We have not yet explicitly modeled how the Dumbo gets our program and understands that program. That process actually is called compilation. The program that we write is written in terms of a lot of instructions which are put together in what we call a computer file which is stored on the disk of a computer. We have not discussed the disk and such mechanisms yet, but you will become familiar when you do the first lab assignment as to how exactly these instructions are given, how do you log in and so on. So effectively an abstract model is that Dumbo interacts with us on a computer terminal in which it shows some sign typically ending with a dollar symbol saying, okay, give me your command. So if we give it a command to read a program and understand it, which is called compilation, we shall see some example of that. Mr. Dumbo can actually take our entire program, all instructions, understand those instructions, prepare the appropriate memory locations whatever and subsequently when we tell them, please execute my program, it will execute those instructions. That is the roughly abstract mechanism. So here is a session with CPP Dumbo or C++ Dumbo. What you see in the first line in brackets is called the current directory. So when you, the directory is a notion of building some kind of cabinets inside the disk. So a directory is sort of a description of what each cabinet is labeled with. So here is a directory called localhost. Afterward you see that sign dollar. This dollar is actually the CPP's way of telling me that I am waiting for you. What I have written here is called PWD. PWD effectively gives me what is known as working directory or present working directory. So slash home slash DBP is my home directory. If I say CD, CPP, CD means change directory. So this will change directory to another name called CPP. So within this directory, there is another directory CPP. It is indicated on my terminal by Dumbo saying I have gone to CPP now. Again it gives a dollar sign. When I give it a command LS which stands for list, it will actually list out all the files which exist inside that directory or in that filing cabinet. So which are these files? There is a file called logcalc.cpp. As we shall see later in this lecture, logcalc is actually a C++ program to approximately calculate the natural logarithm of a given number. There is another program called square root dot CPP. There is another file called A dot out. It is a very funny name but it is a standard name. As I told you, CPP Dumbo takes my program which is written in a file with a file extension called CPP. That is why you see logcalc dot CPP, square root dot CPP, etc. When it compiles that program, it actually understands that and creates internal instruction for itself which are actually effectively machine language sort of instructions which we do not understand. These compiled instructions are also assembled in a file in a computer file. We can give a name for that file which Dumbo faithfully executes but if we do not, it will give a default name to such compiled instructions called A dot out. So if you do not give any option, CPP Dumbo will take my program, compile it into a file called A dot out. Those are the instructions which it will later execute. There is a command. When you say dollars, I am here. Again, I give a command less logcalc dot CPP. Less or more, a funny ways of the operating system which Dumbo follows called Units or actually Linux. Less means show me all the lines of the instruction of this program but only do not show all of them. Show me less of them. What does less mean? Show me one screen fold. When I press a return key, then show me the remaining lines so that you do not have to worry about lines going beyond your vision and so on. Here is a program logcalc dot CMP. We shall revisit the program later but it is worthwhile to look at that program to understand how Dumbo is instructed in C++. You are already familiar with the first three lines. Hash include IO stream using namespace std semicolon slash slash. This program computes log. The third line is a command meant for us. First two lines we take it as sort of standard instructions for Dumbo. We will later on worry about them. The next one says int man which is the beginning of my program. Float x comma w comma area equal to zero. You can see area equal to zero can also be specified in the declaration of a name for a location. So that will initialize the value of area to zero. Then I am saying int precision equal to thousand. Then I am giving a output instruction to Mr. Dumbo which will show out this string. Enter the number whose natural log needs to be computed. Notice at the end I have written nl. Last time we had a funny string called backslash n. nl also means the same thing end of line. That is the symbol which Dumbo understands and takes the cursor to the next line on your screen. Next please. Here is a program. Again as I said we will revisit this program later but just for curiosity I said this is how logarithm will be calculated. So I asked the Dumbo to get an input from me for a value x. x is the number whose logarithm I want to compute. Then there is a for or repetition loop for int i equal to one i less than equal to precision i equal to i plus one. Then repetitive actions for this iteration is w is equal to x minus one by precision. Area is equal to area plus w by one plus i minus one star w. Very complex. We shall actually examine this example in detail. Then it says see out a string called ln opening bracket followed by x followed by a string called closing bracket and equal to followed by area. This will actually print logarithm of so much so is this much area. We shall see why area is being printed later and then return zero that ends it. Please note that we started this description of the program through a command given to Dumbo called less log calc dot c p p. That means we have asked it to show us something on the screen. After showing all of that the last line again Mr. Dumbo says okay I am now ready for any further command from you. Next at this stage I can ask Mr. Dumbo to compile my c program. The command for that is c plus plus log calc dot c p p minus o log calc. What this means is Mr. Dumbo please compile my program using c plus plus programming language. The program is written in a file called log calc called c p p but when you compile and understand it put your understanding out in a dot out which is the default file but put it in a file called log calc because that is the program by which I understand my instructions. Dumbo will do that and again give you a dollar symbol. At which stage you give another funny command dot slash log calc. Why dot slash why not just log calc after all Dumbo has just compiled my program and knows that the instructions so compiled are in a file called log calc. We shall see why dot slash is required and we shall later on see why we can how we can remove that dot slash completely but for the time being we will go by this command. When I say dot slash log calc and press return Dumbo starts executing my instructions. You will recall briefly from the program that we had seen there was an instruction which says c out and it will give you out string. What was that string enter the number whose natural log needs to be computed. So this is being shown to us on the screen by Mr. Dumbo. Now it will wait for us till eternity because there is a c in comma getting in the value of x. I type here 1 and Dumbo will print log of 1 is 0. It will be interesting to see what happens to our program if you give minus 7 for example. So I was asking you if instead of 1 I give minus 7 what should happen what is logarithm of minus 7 not defined what do you think Dumbo will do. Well you find out what Dumbo does when we say error what exactly is the way of Dumbo telling you that you are given a wrong input. Luckily Dumbo does not shout at us it can only show things on the screen next. Here is the re execution of the same program at that command line I say dot slash log calc again it will say enter the number whose natural log needs to be computed I have given 2.73 and it will now calculate executing that algorithm which had an iterative computation which we shall see later log of 2.73 it will show as 1.00485 any guess on what 2.73 resembles yes logarithm of E is 1 actually. So this is how exactly we interact with CPP Dumbo when you do not just this lab which is a preliminary lab but subsequent lab you will get to see all of these details probably without fully understanding them but do not bother please note that I gave an example I think earlier when you are going to learn to drive the car you will often be curious about how the internal combustion engine works what happens when you press an accelerator where does the cable go etcetera but it is not required to understand those mechanisms in complete details because you want to drive the car. So as long as you understand how to instruct Dumbo to do your bidding that is ok the instructions might sound cryptic but that is ok you give those cryptic instructions later on in this course we shall understand all that cryptic matter completely next here is a modified program again my friend has asked what that first line means. So here what I have done in between is I have taken that program which was written in C++ and modified it suitably I have created another version of the program that version of the program I have given the name lock calc mp mp actually stands for multiple procedures note that earlier in that program we had a value for precision called 1000 an arbitrary value I wanted to see what how does the logarithm is computed if I give precision 10 precision 100 precision 1000 etcetera. So I have put another iteration inside to say first calculate logarithm using precision 10 then with 100 then with 1000 we shall see that program later in the lab next week. However since I have a new program called lock calc mp I must ask Dumbo to compile that and understand it. So I give the same command so I say C++ lock calc mp dot cpp minus o lock calc mp and then afterwards I execute that command execute that compiled program as Dumbo to execute it by saying dot slash lock calc mp again why dot slash we will forget about it right. But now see the execution of the program it again ask me enter the number whose natural log needs to be computed I have given the value 2.7182813 is closer to E yes. So I would expect the value 1 notice that the log calculated for that with precision 10 is 1.05643 with precision 100 is 1.00545 and with precision 1000 it is 1.00054. Obviously larger the precision the better is the accuracy of my result how exactly this is happening we shall see that in details when we understand how Dumbo does numerical computations and how we can instruct Dumbo to execute instructions in a repetitive fashion using our conditional decision making next and of course when Dumbo finishes as usual it comes back on the screen with this kind of side which shows me which directory in his cabinet I am in and shows that dollar symbol ready to take any other command. So Dumbo is almost like a genie tell it to do something it does it and again says what next okay next. So now we try to understand how Dumbo handles numerical values this example we have seen earlier it when we specify int x for example we had assume that in the cupboards that in the in the memory cupboard that Dumbo has it will preserve a one drawer label it as x and will remember that the drawer x has to contain integer values. So int x reserves one location in memory what kind of values can it store can it store 25 yes can it store minus 207 of course yes what is the maximum and minimum value surprisingly our C plus plus Dumbo has a very funny rule please do not give me any number larger than 2 to the power 31 minus 1 please do not give me any number smaller than minus 2 to the power 31 minus 1 this looks kind of all right I mean we speak of 3 digit numbers 4 digit numbers 10 digit numbers positive or negative but Dumbo does not seem to understand our notion of size of a number we measure the size of number in terms of number of digits that the number has digit means decimal digit 0 to 9 unfortunately Dumbo does not use a decimal system 2 to the power 31 as we know it is very close to 2 into 10 to the power 9 effectively we are talking about 9 digit numbers Dumbo cannot handle numbers larger or smaller sorry larger than this or negative numbers smaller than minus on this how do we store larger numbers by the way this is important Dumbo does not intrinsically understand decimal arithmetic inside outside he makes a facade of understanding your decimal numbers perfectly well that is why in our programs and all we do not have to write binary numbers we write decimal numbers only when Dumbo executes my instructions for arithmetic operations internally it translates all decimal numbers into some funny binary format we need not worry about how it does that and that is why these funny limitations come up otherwise it can do all the computations that we so desire but again come back to the question how do we store larger numbers for example if I have a larger than 9 digit number what do I do well my CPP Dumbo has a small special instruction instead of saying int x if I say long x long as in larger number of digits with long x Mr. Dumbo is able to store numbers in the range of plus 2 to the power 63 minus 1 to minus 2 to the power 63 minus 1 again this funny power of 2 comes in we shall worry later as to why and how that happens but it is good enough for us to understand that with int x int a int b int count whatever we will be able to roughly store 9 digit numbers plus or minus and with long x long y whatever we will be able to store about 19 digit numbers that is good enough precision for most of the integer operations but that is not the end of scientific calculations scientific calculations for example avogadro's number anybody remembers what is avogadro's number 10 to the power 23 Mr. Dumbo will go fuck why 23 is ok with long x no it is not ok because avogadro's number is a fraction and we are talking about integer numbers our CPP Dumbo has tremendous aversion of mixing integer numbers with decimal fractions it does not understand decimal fractions when we talk about integer integers must mean pure integer numbers nothing else so we have to find out a way of storing fractional values incidentally Dumbo ordinarily even our CPP Dumbo cannot understand fraction in the conventional way how do we understand fraction 3 by 5 4 by 8 3 by 7 etcetera these fractions do not mean anything to Dumbo the CPP Dumbo understands integer value and as we shall see shortly it also understand decimal values such as 4.311 minus 2.894 etcetera we must now understand how CPP Dumbo handles what you call fractional numbers next piece this is some more explanation which I already gave the real Dumbo uses binary or base 2 representation thus we think these values are expressed in power of 2 we have already seen that for the time being we will continue to believe that Dumbo uses decimal values that is base 2 representation we need not worry about how it does actually for integer numbers decimal and binary numbers have exact 1 to 1 correspondence so there is no difference whatsoever when we give a decimal value to Dumbo and Dumbo internally translates it to binary value and handles it as far as integer has been discussed sadly for fractional values which are expressed by us in the form of 2.713 or minus 17.28 etcetera the decimal values have to be handled decimal fractional values have to be handled completely different first we will try to understand how CPP handles these fractional values in terms of pure decimal notation that we use next it uses a representation called floating point representation point refers to decimal point or internally for CPP a binary point we will not refer to anything binary from now onwards hoping that Dumbo understands decimal notation so we provide CPP with a mechanism to declare memory locations which can contain such fractional values by using a new name called float y float y is a designation where Dumbo preserves a location called y in his memory drawer but inside y it will not keep a single integer number as earlier it will instead store a floating point format number so what is a floating point format the number y actually is represented by two components one component is called mantissa and the other is called exponent this is actually a standard scientific way of representing numbers for example the number value will be taken as m multiplied by b raise to e so m is mantissa e is exponent what is b b is the base of such representation b could be 2 3 5 6 10 18 whatever whatever as far as we are concerned the base b is 10 but as all of you can guess as far as Dumbo is concerned internally after it compiles your program and starts executing it its internal base will be 2 and of course it will have to do a lot of conversion from decimal to binary binary to decimal etc. again we will not bother about it at all at this time so we will assume that CPP understands decimal numbers but when it has to store very large or very small numbers like 10 raise to 28 or 10 raise to minus 39 with some lots of fractional digits etc. then it will use this form m multiplied by b into e so let us look at how these numbers are stored here is some example this is a drawer which we call let us say x or y or whatever in this drawer Dumbo has made two partitions one is called mantissa one is called exponent here the value stored is minus 4127 here the value stored is 11 here is another example in this drawer Dumbo has stored 1 9 4 6 2 a positive number as mantissa and minus 2 1 as exponent as far as Dumbo is concerned the first value is always taken to mean 0.4127 multiplied by 10 raise to 11 notice that 11 is the exponent and 0.4127 is taken to be the mantissa where the value of the mantissa is stored as an integer 4127 of course is a negative number and so this number is minus 0.4127 into 10 raise to power level this number which has a integer part m as 19462 and exponent part as minus 21 is interpreted by Dumbo always to mean the value 0.19462 multiplied by 10 raise to minus 20 you are familiar with this notation all of us as scientists and engineers would necessarily use this notation to represent larger small numbers for example we would write this first number as minus 412.4127 e 11 you all agree with this this is how we will write that number e is an exponent we assume it to be 10 to the power 11 so this is mantissa for us please note however that as far as we are concerned in our own handling of these numbers we can write the same number also as minus 41.27 e 9 we agree that this and this are same numbers minus 41.27 e 9 is minus 4.127 e 10 or minus 0.4127 e 11 so I can keep shifting the decimal point by adjusting the exponent and still the value of the number will be same that is the reason why this format for Dumbo is called a floating point format as far as we are concerned the point can float anywhere the correct value will be represented by adjusting the exponent appropriate so what Dumbo does is for us to facilitate writing the numbers either as this or as this or anything else please note in our programs when we write value or as input when we give a value to Dumbo we can give it either like this or like this or in any one format it does not matter Dumbo will take that value will move the decimal point automatically to the left most point like this and will store this integer as mantissa and this value as exponent so this is the CPP Dumbo's way of handling decimal fractional numbers large or small now here is the problem because this width is constant of the drawer how do we know the width is constant well when we looked at integer what was int x we said int x can be at most a 9 digit number kind of thing do you remember that now obviously each drawer is exactly the same length so if Dumbo has to make two parts of that drawer it has to designate some larger part may be for mantissa and some part for exponent please note that both of them can be positive or negative so he has to give enough space for that consequently what happens is that our CPP Dumbo has only about 7 decimal digits to store for mantissa and it has only about 2 digits or just about 3 so the exponent can be 100 or minus 100 or plus 100 whereas the fractional part the mantissa can be about 7 decimal digits again we will have a problem because 7 decimal digits may not give us adequate precision we might want a larger number of digits to be accurately represented and used for calculation then just as we had long why they are long z again Mr. Dumbo has a provision to say double z this longer double is equal to 0. Can be conceptually abstracted to mean a larger cabinet with larger drawers just the double the size of the normal drawer so ordinary memory locations of some size drawer the larger which is used for storing double or long etcetera have double size drawer that is the best abstract comparison in summary the first everybody is familiar with chronicle have you heard this name chronicle delta is an important mathematical notion anyway he said God made natural numbers the rest is work of man I have added to it that humans made fractions and decimal numbers the rest is the work of Dumbo so you have to be very careful while dealing with Dumbo Dumbo's deal with numbers in a very peculiar fashion if we do not understand them we will assume we have given very nice instructions correct instructions but the result that we will get may be all crap we shall examine what happens when internally computations are made next yeah okay here is an example of what happens in floating point let us say I have declared to Mr. Dumbo a memory location w which contains a floating point value float w I have also declared another location of drawer avogadro remember I asked you about avogadro's number is approximately avogadro's number 6.023 10 to the power 23 notice that we could not have stored this as an integer number although it is an integer number it is too big so we store it as a fraction mantissa will be stored as 0.6023 effective 6023 and exponent will be stored as not 23 but 24 Dumbo will rationalize all that that is fine so it has stored this number avogadro it has stored another number called y which is 1.5 now you want to add avogadro's number to y a legitimate addition that humans can do very well unfortunately when Mr. Dumbo tries to add and create a sum for w what will be the value of w the problem is even in human calculation if we sit down and write down the long form of avogadro's number and then represent 1.5 whatever that 1.5 will come somewhere the faggadro that number and then the final number will be a 23 digit long number but it the two numbers avogadro number and w will differ only in the last digits unfortunately Mr. Dumbo when dealing with floating point representation has no mechanism to store anything beyond 7 digits in mantissa so all subsequent digits beyond 7 digits will be simply lost this is called a round off error Mr. Dumbo simply ignores such digits beyond 7 and if you have used the double kind of thing it will ignore digits that but whatever there will be a limit so this is the first example of how careful we have to be when we are instructing Dumbo to handle fractional numbers large or small using floating point representation so in conclusion Mr. Dumbo will think w is same as avogadro although mathematically w and avogadro are not same as far as we are concerned we have to contend with this remarkable dominance of Mr. Dumbo and handle that appropriately using some other algorithms later on when we study more programming you can see that packages have been written to provide what is known as a large precision arithmetic so you can actually write computer programs to make even Mr. Dumbo do arithmetic with precision of even 2000 digits 5000 digits but all those programs have to be artificially written basically you have to teach Mr. Dumbo how to handle large values with larger precision ordinarily Dumbo does this next Dumbo can handle mixed arithmetic when it has to handle numbers for example some number is integer some number is float Dumbo is able to convert from float to int and vice versa as required so look at this int x equal to 10 float y equal to 6.5 one is integer another is float if I say x equal to y x will not become 6.5 because x is declared as integer x will become 6 instead please note that when a floating point value is assigned to integer the value is rounded down so only the integer part is retained fractional part is simply forgot if instead I say 360 by x note these are not to be considered as statements given in sequence each one is an independent statement we are looking at what Dumbo will do any time we give it either this or that or that so do not execute them in sequence so with the values of x as 10 and y as 6.5 if I say 360 by x integer result is calculated because x is integer and 360 is also integer however if I say 360.0 dash slash x here x is integer and 360.0 is considered as a floating point value a point to be noted Dumbo always interpret actual numerical values that we write as either integer or floating point depending upon whether a decimal point exist or it does not exist so 360 and 360.0 are two completely different internal representations for Dumbo one is an integer representation whereas 360.0 will be represented using our floating point form and once there is a floating point format and an integer format where these two different numbers are to be arithmetically operated upon then it uses its own conventions for example a float and an integer in a mixed arithmetic operation the result will be float. What will happen if you say 360 by y well what I told you just now 360 is integer but y is float so the result will be float what will be the value you can check that up when you execute the program next here is a simple numerical program we had seen this earlier int main float c c out centigrade temperature n line c in c c out current heat c star 9 by 5 plus 32 please note that I am not computing the value and assigning it to a different drawer or in the memory I do not need to do that if I have a simple computation I can actually make the c out instruction to do that computation directly and the computed value will be outputted by dumbo. So when dumbo executes the last line it will put the string Fahrenheit and it will simply put the value of c multiplied by 9 by 5 plus 32 notice that c is float and therefore you will get the right result in floating you can execute that and see what happens next in general the arithmetic operations have to be first of all they have to be explicitly stated in algebra if you say x y you automatically imply x multiplied by y in algebra if you say 3.6 z you always mean 3.6 multiplied by z there is no such implication dumbo is really dumb if you mean any arithmetic operation you must explicitly write that arithmetic operation the typical arithmetic operations are star which stands for multiplication slash which stands for division percent symbol which stands for modulus operation we shall see an example plus for addition minus for subtract these are all binary operators that means there are two operands connected by one operator and they will result in a value multiplication and division have higher precedence than plus and minus multiplication and division within themselves have equal precedence. So if you say a star b slash c what will happen first well whenever there are equal precedence operators this c plus plus dumbo will execute them from left to right that is the order so within the equal precedence anywhere the expression is evaluated from left to right same thing for plus and minus for multiplication division is important because a star b slash c whether you multiply a and b first and then divide by c or whether you divide b by c first and then multiply by a would have different results if a b c are integers if they are floating point numbers it may not matter but if they are integers it will matter hell of a lot. So be careful about the precedence in case of any doubt you can put parenthesis to overwrite the default precedence again more or less the standard mechanism next you must write comments as I had already explained to you last time because programs are not only read by dumbo compilers but also by other programmers. So extra description first tile is slash slash that is the kind of comments we have been seeing the other kind of older comment style which comes from c programming language where in an entire line or multiple lines you start one line with slash star and then keep writing commentary if you want complete paragraph or something at the end you put star slash the whole paragraph is treated as a comment this style is recommended only in certain cases ordinarily that may not be a good idea we shall see why later here is an important idea reemphasized of reassignment you might have seen statements like count equal to count plus one etcetera some of you may be wondering what is this here is an example int m equal to five m is equal to three star m plus one this is called reassignment and I would like you to emphatically remember that this is not a mathematical equation I hope all of you can see that very clearly if this where a mathematical equation is absurd where the m equal to three star m plus one can be immediately reduced to mean zero equal to two star m plus one and that cannot be true even if for whatever value of m this cannot be a two equation at all so this is not an equation this is an instruction to mr. Dumbo mr. Dumbo look at the right hand side of this expression right hand side of the equal to symbol it says three star m plus one don't bother about the left hand side the right hand side is the expression which I want you to evaluate using existing values of those variables like m or whatever so here is what Dumbo will do Dumbo will calculate the value of the right hand side which for m equal to five works out to five into three plus one which is sixteen now it will take this value and look at the left hand side left hand side incidentally happens to be m it could have been zed be count whatever whatever is the left hand side that is the drawer in which this final value will be kept if it so happens that that drawer's value was used earlier in the right hand side expression so be it that old value will be destroyed so after executing this reassignment this drawer will now contain the value sixteen and not five and if you re-execute it the next time the expression will be evaluated using m equal to sixteen resulting is sixteen multiplied by three forty eight plus one forty nine and then we'll become forty nine in fact this kind of reassignment is used as the kernel of almost all our iterative loops which we shall see later in in the examples next common programming pattern for repeat n times with i taking different value here you can cleanly specify the iteration in a format where you have a previous statements followed by this funny looking pattern for xxx semicolon by yy semicolon zzz and in opening brass and closing brass www and followed by next statement this fall block as it is called is an extremely important programming construct by which we can stipulate to Mr. Dumbo please do certain things again and again and again using what is known as a for loop next try to draw a spiral using your K turtle those of you have not done the lab you can try that in fact in the labs on Monday Tuesday Wednesday and others can try it next week in time for i equal to one i less than six i equal to i plus one execute whatever instructions you want these are the repetitive actions end of brass all the repetitive actions stated will be executed first with i equal to one then with i equal to two then with i equal to three then with i equal to four then with i equal to five but when i become six i will get out that is the iteration last time i briefly explained through a flow chart i will try and prepare some notes which are post on the page so those of you had some difficulty in understanding that flow chart can figure that out next here is a detailed explanation what happens first xxx is executed so it must be an assignment statement it is called loop initialization next evaluate condition yy yy this is called loop test if that test is true that means answer to that question is yes okay you go ahead with step two otherwise false statement execution ends complete if you get into the for loop you execute www which is called the loop body at the end of executing loop body you execute the increment i equal to i plus one which is written as zz that is called loop increment this is how it continues condition the loop condition which is same as the condition that we put in any if statement we had seen earlier what kind of format can we use for conditions conditions are always written in terms of some value some operator some other value the operator is typically called a comparison operator so a of b is the standard format of a condition where operator can be less than greater than as than equal to greater than equal to equal equal means equal don't use equal to symbol alone equal equal has to be used why because dumbo whenever we give a single equal to symbol it thinks it's an assignment when we mean comparison we have to say equal equal so a equal equal zero means is a equal to zero whereas a equal to zero means take zero and put it in a they're two completely different parallel similarly not equal is written as exclamation mark equal again dumbo is funny we have to understand the funny symbolisms so equal equal is equal to exclamation mark equal is not equal conditions can be combined you are familiar with logical operators and or not all of your familiar good so and or not can be put together there is a truth table for these and or not logical operators for example true and true is true true and false is false true all true is true false or true is true but false or false is false this is the mechanism of and and all those of you don't understand again can refer to any book on logic or simple maths dumbo is capable of understanding these provided we give you instructions like this a greater than zero and a less than equal to nine again notice that and is not written as a single and symbol two ampersands are used and and because for a single and dumbo has a different meaning you see dumbo's language evolved from scratch so there are some very funny things in dumbo's language called c++ it does not understand English so you have to understand we have to understand the symbolism so and and is conjunction which is called and and two vertical bars is called or which is disjunction there are more examples of fall I will just leave this slide you can read that slide on the on the web page I wanted to quickly conclude with the example of the numerical calculation of natural logarithm everybody's familiar with this definition of logarithm log of x natural logarithm of x is actually integral of one to a log of a for example if a number a is given log of a is defined as integral one to a one by x dx how do you calculate this dumbo cannot integrate or differentiate so dy by da d square y by dx per etcetera don't mean anything to him so we have to use arithmetic operations to calculate this fortunately there is an arithmetic equivalent approximation to calculate this integral in terms of Riemann integral everybody's familiar with Riemann integral everybody's familiar with integral 0 to 1 fx dx good basically we try to find out the area under the curve fx equal to one by x from one to a and that area is equal to the value of the integral numerically that area can be calculated we can approximate that area by small rectangular here is what is known as Riemann integral or Riemann sums instantly how many of you have visited Wikipedia can you raise your hands fairly large numbers how many of you have not visited Wikipedia can you raise your hands okay very very important to locate Wikipedia site and visit it it is far superior to Google in terms of knowledge inputs the definition of logarithm for example definition of Riemann integral and definition of counting this Riemann integral using an animation is all included in Wikipedia site so those of you who want may visit that for better mathematical anyway here is what we wish to do calculate some of areas of all rectangles between one and a so notice here what is happening how many rectangles should I have well I don't know how many I can have only one rectangle obviously if there is one rectangle I will get a very funny value but if I have multiple rectangles I will get perhaps a better what I need to do now calculate the area of this rectangle this rectangle this rectangle this rectangle this rectangle and add them if I add them up that is the approximation to the integral and therefore the approximation to logarithm of a so how many rectangles well I have said more the merrier so let's say I take thousand rectangles now what is the total width of rectangles a minus one let's go back to the previous slide this is a this is one so the total width is a minus one so width of any rectangle will be a minus one divided by number of rectangle so a minus one divided by thousand I call it w what is the x coordinate of the left side of rectangle I have given a formula here x equal to 1 plus i minus 1 into w and what is the height of a rectangle which is one of x is equal to 1 upon 1 plus i minus 1 by w sounds complex let us quickly look at some diagrams here I am assuming that this is i th rectangle the shaded rectangle notice that i th rectangle this is first this is second this is actually third I have tried to represent the width of this rectangle since width of all rectangles is same if I have n rectangles then w will be equal to a minus one by n agreed this is a this is one so a minus one by n is the width of any rectangle what is the x coordinate of i th rectangle I have represented x coordinate as 1 plus i minus 1 by w let us examine whether this is correct by giving some value to y this is apparently third rectangle in my diagram this is first this is second this is third if I put i equal to 3 I get the value 3 minus 1 that is 2 w 2 w plus 1 well that is correct this point is 1 this point is 1 plus w and this point is 1 plus 2 w agreed so 1 plus 2 w is the correct coordinate of the third rectangle x coordinate beginning similarly i th rectangle will have this as the value of x coordinate so x coordinate of the i th rectangle of the left corner is this now if that is so then what is the height of that well that is the beauty the height is determined by the nature of the function the function is f x equal to 1 upon x so if x is the coordinate value for this the height h will be equal to 1 by x and that is nothing but 1 upon whatever formula I wrote for the i th corner now you can see I can easily calculate the area of this rectangle what is the area of a rectangle width multiplied by height width w is known height is known so for any i th rectangle I can calculate the area and then I can set up an iteration to calculate the sum of those areas I am saying float x area equal to 0 and w I am I am announcing all of these as a sort of floating point numbers I get in x x is the value whose logarithm I wish to calculate I calculate w as x minus 1 divided by thousand what is thousand I am assuming there are thousand rectangles this is my precision or this is my factor since w is known I now set up a loop because I have to sum up thousand rectangle areas I run the loop or iterative thing for i equal to 1 to thousand in steps of 1 by the way that is the most simplistic meaning of this instruction do the repetitive action starting with i equal to 1 in steps of 1 that is 1 2 3 4 5 right up to thousand then you finish thousand get out and what is the action want to do calculate the area of the i th rectangle which is w multiplied by this height and added to already existing area so area is actually a moving sum initially I start with area equal to 0 then I add the area of first rectangle second rectangle etcetera etcetera and all thousand rectangles I will get the final value is that clear this is an example of program to compute logarithm you can actually go back because these slides will be put up on the on the net so you can look at those slides and now if you re-examine the original program which we had seen you will probably be able to understand it better this is a small explanation i th iteration adds area of i th rectangle I am sorry I think we are exhausting our time so I will leave this explanation for you to understand I hope generally the explanation was clear to all of you this is how you do numerical computations by the way