Chapter 4: Problem 21
Because of round-off errors, it could happen that a mathematical rule like \((a b)^{3}=a^{3} b^{3}\) does not hold (exactly) on a computer. The idea of this exercise is to check such identities for a large number of random numbers. We can make random numbers using the random module in Python: import random \(\mathrm{a}=\) random. uniform \((A, B)\) \(b=\) random. uniform \((A, B)\) Here, a and b will be random numbers which are always larger than or equal to A and smaller than \(B\). Make a program that reads the number of tests to be performed from the command line. Set \(A\) and \(B\) to fixed values (say - 100 and 100\()\). Perform the test in a loop. Inside the loop, draw random numbers a and b and test if the two mathematical expressions (a*b)**3 and a**3*b**3 are equivalent. Count the number of failures of equivalence and write out the percentage of failures at the end of the program. Duplicate the code segment outlined above to also compare the expressions \(a / b\) and \(1 /(b / a)\). Name of program file: math_identities_failures.py.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.