 Hi, in this lecture we will continue our discussion on floating point approximation of a number which we did from the last class. In this class we will understand what is mean by significant digits and what is the danger in losing significant digits in our calculation. Let us take the number 1 by 3 it is given by 0.333 and so on it goes on up to infinity and you take the number x a equal to 0.333 we can say that the number x a approximate x with 3 significant digits. So, this is kind of intuitively clear what we mean by saying x a is approximating x with 3 significant digits because you can simply count the number of digits which are matching with the digits in the original number right. The first position of the number x a is 3 which is also there in this of course, you have to forget what is there before the decimal point here. You just have to think that these are written in the floating point representation and then try to see the number of significant digits that is the number of digits which are matching with these 2 numbers. So, the first 3 digits and the first 3 digits here are matching therefore, we can say that there are 3 significant digits in the number x a when compared to x. Let us put this idea in the mathematical form and give the definition of or significant digits. Let us assume that our radix that is the basis beta and we say that the number x a is an approximation to x with or significant beta digits is or is the largest non-negative integer such that the relative error x minus x a divided by x and taking the modulus is less than or equal to 1 by 2 times beta to the power of minus r plus 1. Of course, here x should not be equal to 0 that is always assumed whenever we are talking about the relative error. So, if such a thing happens then this r which is the largest non-negative integer that we have taken and see that this inequality holds then that r is called the r significant digits present in the number x a when compared to x. Intuitively it will be like you just match these 2 numbers and see how many leading non-zero numbers are matching with these 2 numbers. However, due to some rounding problems it may not always work this counting idea therefore, it is always better to check this definition correctly in order to see how many significant digits are there in x a when compared to x. Next we will see what is mean by loss of significance and what is the danger in losing the significant digits for that we will take an example consider 2 numbers x which is given like this and y which is given like this and I am writing it in the floating point representation. Of course, I have to write a minus 1 to the power of 0 here, but I am just leaving them and now for this instead of taking the exact values x and y I am taking their approximate value x a and y a somehow approximated and then I want to perform the calculation with x a and y a instead of x and y. Before going into this you can see that x and y are correct to 7 and 8 significant digits respectively that is x a has 7 significant digits when compared to x and y a has 8 significant digits when compared to y. Now, we want to perform the subtraction between x and y instead of doing that you are doing the subtraction between x a and y a the answer is this. If you would have done the same calculation with exact values you would have got this number. Let us see how many significant digits are there in z a when compared to z you can see that z a minus z divided by mod z is approximately this number and this number can be written as minus 1 to the power of 0 into 0.49 into 10 to the power of minus 2. So, what you do in order to find the number of significant digits you just find this number first and get the number and write it in the floating point form and then you see what is the nearest 0.5 that you can dominate this you can see that this is less than equal to of course this is something which you can avoid writing you need not write all the time 0.5 into 10 to the power of minus 2. So, that is what I am writing here. So, once you write it in the floating point form then it is very easy to get what is the nearest number with 0.5 that dominates your original number. So, now once you get this you know that minus r plus 1 should come here and that happens to be minus 2 from there you can get what is your r and that happens to be 3 and therefore, z a has 3 significant digits when compared to the number z. So, to summarize we started with 2 numbers x a and y a which are correct to 7 and 8 significant digits with respect to x and y respectively and their difference z a has only 3 significant digits with respect to z. And therefore, we had a loss of significant digits in the process of subtracting this is what we understand here. So, what if you ask this question let us see the relative error in z a when compared to z is 53 581 times more than the relative error in x a when compared to x. Therefore, the process of subtraction has amplified the error in the initial data by a factor of around 53000. So, that is the danger which is happening in this calculation. And similarly you can also see how much the amplification have happened when compared to the relative error in y a. And this shows that the loss of significant digits is very dangerous it can magnify the error drastically. Suppose you just assume that you have a calculation and that calculation goes in a loop say for 1 million times. And every time the calculation is done in every single loop if the error is magnified by say 50000 times then 1 million times if you do the calculation again and again recursively you can imagine how much the error will be amplified in the final answer. Therefore, loss of significant digits is very dangerous in computation one has to be alert in the computation to see where all you are losing the significant digits. The process of losing significant digits is often referred as loss of significance. Let us take the example which we have done previously let us take f of x equal to x into root x plus 1 minus root x. And if you recall in the last lecture we have computed the value of this function at x equal to 1 lakh using 6 digit rounding and we got the answer as 100. The exact value of this expression is actually 158.113. You can see that there is a significant error involved in this calculation with 6 digit rounding which is obviously due to loss of significance because you can see for a very large x root x plus 1 and root x they are very close to each other. Therefore, they have lot of significant digits in them and they all get cancelled because of the subtraction and that is how the loss of significance happened in this case. Is it possible to avoid loss of significance in our calculations? Well this is not always possible, but a good news is that in the function which we considered previously that is this function you have a way to avoid this loss of significance. How to do that? Well that expression can be rewritten in this form. How will you do that? Well you can multiply and divide by root of x plus 1 plus root x divided by root of x plus 1 plus root x. Now what happens? Numerator will give you just 1 and divided by this. Therefore, f of x can also be equivalently written as x divided by root x plus 1 plus root x. Now you go back to our previous example where we have computed the value of x plus 1 plus root x. Now what happens? f of 1 lakh using 6 significant digit rounding the same idea you follow and now calculate the value of f using this expression at the point x equal to 1 lakh using the same 6 digit rounding calculation. Now you will get the value 158.114. I will again repeat you do the 6 digit rounding calculation just like what we did in the previous class. Now instead of the previous expression now you use this equivalent expression for f. Mathematically this expression and the expression that we have taken initially that is this expression these two are one and the same right mathematically. But if I use 6 digit rounding and perform the calculation and find the value of f of 1 lakh using this expression then I get the value 158.114 which is pretty close to the exact value which is 158.113. Why it is happening? You can clearly see that there is no scope of losing significant digits in this expression unlike in the previous expression. Therefore, this loss of significant digits is very important in numerical analysis even if you are working with a very good method mathematically that can lead to very bad answers because of the loss of significant digits in your calculation somewhere and therefore, one has to be careful especially when you are implementing your method on a computer. In fact, there are many disasters that happened in practical situations. You can read one such disaster in this website and this disaster is due to the rounding error in a software. Next, let us pause on to the next topic of propagation of error in the four arithmetic operations. In this let us understand how the error from the initial number gets into the calculation when we use addition or subtraction or multiplication or division. Let us take as a first case the addition of two numbers assume that you have two values x t and y t instead of using x t and y t we use their approximations x a and y a where x t is equal to x a plus epsilon and y t equal to y a plus eta. Now our interest is to find x t plus y t or x t minus y t instead of that we performed x a plus y a or x a minus y a. Now the question is what is the relative error in this approximately computed value when compared to the value that is computed using true values. Therefore, let us take the definition of the relative error. The relative error is nothing but the true value minus approximate value divided by the true value. Now we will eliminate this x a plus or minus y a by the true value using these expressions that will happen to be the true value minus instead of x a I am putting x t minus epsilon and instead of y a I am putting y t minus eta divided by this true value. Now we can just simplify this expression to get epsilon plus or minus eta divided by the true value. Therefore, the relative error in some or difference between two values which are approximately taken when compared to the corresponding true value is given by this expression. If x t and y t are positive then addition will not make the relative error to grow drastically whereas, the subtraction can make this when the true values are very close to each other. Therefore, subtraction is very dangerous when x t and y t are very close to each other whereas, addition is not going to be dangerous at all when both x t and y t are positive numbers. Let us try to see the propagation of relative error in multiplication again what is our interest? Our interest is to find x t into y t instead of this we have performed x a into y a where x a is an approximation to x t and y a is an approximation to y t. Now our interest is to see what is the relative error in this approximate value when compared to the true value the definition is obviously this. Now as we did in the previous case we will replace x a by x t minus epsilon and y a by y t minus eta and that gives us this expression and again you go to simplify this to get this expression. Now you can write this as epsilon divided by x t this is nothing but the relative error in x a when compared to x t and this is the relative error in y a when compared to y t I am just splitting this sum and writing them in individual terms and then you have this right. So, that gives a nice expression for the relative error in the product of two numbers as sum of the relative errors minus this you can see that if e r of x a and e r of y a are very small numbers which may be true in practical then the product of those two small numbers will be much more smaller. Therefore the relative error in product will actually amplify the error only by the sum of the relative errors in their initial data. Therefore in this way multiplication is also not so dangerous. Let us go on to division and see how division amplifies the relative error. Here you can see that the relative error definition is this and again you replace x a by x t minus epsilon and similarly y a and you will get this expression. Again one has to simplify this to get this expression and now you can further simplify it to get this expression. These are very simple ideas therefore you can just understand how I am simplifying from one step to the other step and now finally you can write this expression as y t divided by y t minus eta into the difference between the relative errors in x a and y a. You can write it as 1 by 1 minus relative error in y a into this. What I am doing? I am just taking y t outside and therefore I am getting 1 minus eta by y t that is the relative error in y a. So, y t comes out and gets cancelled with the numerator therefore 1 by 1 minus relative error in y a into this. Now what this expression tells us is that if you make a error in y a which is 100 percent error then this relative error will be infinity that is what it says. It means if you make 100 percent error in y a then the division will be a disaster that is what this expression says that is quite acceptable because in any circumstances we do not intend to make 100 percent error if you make 100 percent error then our answer has to be bad. So, given that we do not make such a big error division can be regarded as a nice operation. Now from this 4 analysis what we understand is only subtracting 2 positive numbers is going to be very dangerous in any calculation on a computer especially whereas, other 3 arithmetic operations are relatively peaceful when compared to the subtraction and our previous examples shows that subtracting 2 very close numbers will lead to loss of significance and that loss of significance is in general dangerous in the sense that they can amplify the error drastically. We will continue our discussion in the next class with condition number of a function and we will try to understand what kind of functions can be more nice to be evaluated on a computer based on that condition numbers. Thanks for your attention.