(a) A fundamental property of real numbers is given by the distributive law (x + y)2 = x2 + y2. (2) In this question, yo
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
(a) A fundamental property of real numbers is given by the distributive law (x + y)2 = x2 + y2. (2) In this question, yo
question, you are going to check whether floating point numbers obey this law. To do this, you are going to write a Python program that runs through a loop 10,000 times and each time draws three random numbers in the interval (0,1) and then checks whether the law holds (whether the two sides of Equation 2 are equal) for these numbers. Count down how many times the law fails, and at the end, print percentage of times that it failed. Print also a set of three numbers for which the law failed. 2 (b) Repeat (a), but test the associative law (x + y) + 2 = 1 +(y+z) instead. (c) Repeat (a), but test the commutative law 1 + y = y + r instead. (d) Repeat (a) and (b), but test the associative and commutative laws for multiplication instead
(a) A fundamental property of real numbers is given by the distributive law (x + y)2 = x2 + y2. (2) In this