Think Real Numbers Algorithm Approximate Computing Purposes Floating Point Numbers Form 1 Q43907656
PYTHON
What we think of as real numbers in an algorithm, we approximate for computing purposes as floating-point numbers of the form: (-1)S (do d1d2… dp-1 Be where s E 0,1 indicates the sign p is the number of digits or precision each digit di € [0, 1,…,B – 1] B is the base and e is the exponent. While we, as humans, tend toward base B = 10 , computers almost universally use a binary representation with B= 2. The floating-point representation corresponds to a unique real number: x = (-1)$(do + 8 + … B + 4 “Alpe Some real numbers have an exact (but not unique) floating-point representation; e.g. x = 0.5 has the following representations: * = (-1)0 (1.0) 2-1=(-1)0(1 + ) 2-1= Ż and i =(-1)º (0.1) 2° = (-1 For uniqueness, choose the normalized (first) version with do + 0. A floating point number system is defined by base B, precision (number of digits) p, and range of exponents [eminemax. . Let’s take a look at an example: B = 2, p = 2, e € (-2,3] Positive normalized numbers: x = (-1)(1.0) 2-2 = 1 ă = (-1)º (1.1) 2-2 1 # =(-1)º(1.0) 2-1= 1 * =(-1)º (1.1) 2-1= 3 x = (-1) (1.0) 20 = 1 * =(-1)° (1.1) 20 = Ž # =(-1)º (1.0) 2+ = 2 =(-1)º (1.1) 21 x= (-1)^(1.0) 22 = 4 x = (-10 (1.1) 22 = 6 = (-1)º (1.0) 23 = 8 À = (-1)º (1.1) 23 = 12 ४। ४। xe X = {{1/4, 3/8, 1/2, 3/4, 1, 3/2, 2, 3, 4, 6, 8, 12} Here we embellish slightly by adding 1 digit of precision to get: ß = 2, p = 3, e € -1,0,1,2,3 2a) Write a function (by completing the template below) to compute the number of entries in the array of all normalized representable values in a floating point system. Remember that the first digit in a normalized number must be non-zero. The other digits are integers satisfying 0 < d < B. def gamut_size(p, e_min, e_max, base=2): compute the number of representable values for a floating point system Args : p: number of digits of precision e_min: smallest integer exponent value e_min: largest integer exponent value Named args: base: default value 2 Returns: integer number of representable values #insert code here return n 2b) Write a function (by completing the template below) to produce a numpy array containing the sorted array of normalized representable numbers for a floating point system with p = 3 digits of precision. Hints: Remember to import numpy to have access to array capabilities. Start by computing the number of elements in the gamut so you can create an array of the appropriate size. Use numpy.sort() so you do not have to write your own sorting function. [ ]: import numpy as np def gamut (e_min, e_max, base=2): compute the representable values for a floating point system Args : p: number of digits of precision e_min: smallest integer exponent value e min: largest integer exponent value Named args: base: default value 2 Returns: numpy array of representable values vals = np.sort(vals) #sort the array return vals Show transcribed image text What we think of as real numbers in an algorithm, we approximate for computing purposes as floating-point numbers of the form: (-1)S (do d1d2… dp-1 Be where s E 0,1 indicates the sign p is the number of digits or precision each digit di € [0, 1,…,B – 1] B is the base and e is the exponent. While we, as humans, tend toward base B = 10 , computers almost universally use a binary representation with B= 2. The floating-point representation corresponds to a unique real number: x = (-1)$(do + 8 + … B + 4 “Alpe Some real numbers have an exact (but not unique) floating-point representation; e.g. x = 0.5 has the following representations: * = (-1)0 (1.0) 2-1=(-1)0(1 + ) 2-1= Ż and i =(-1)º (0.1) 2° = (-1 For uniqueness, choose the normalized (first) version with do + 0. A floating point number system is defined by base B, precision (number of digits) p, and range of exponents [eminemax. . Let’s take a look at an example: B = 2, p = 2, e € (-2,3] Positive normalized numbers: x = (-1)(1.0) 2-2 = 1 ă = (-1)º (1.1) 2-2 1 # =(-1)º(1.0) 2-1= 1 * =(-1)º (1.1) 2-1= 3 x = (-1) (1.0) 20 = 1 * =(-1)° (1.1) 20 = Ž # =(-1)º (1.0) 2+ = 2 =(-1)º (1.1) 21 x= (-1)^(1.0) 22 = 4 x = (-10 (1.1) 22 = 6 = (-1)º (1.0) 23 = 8 À = (-1)º (1.1) 23 = 12 ४। ४। xe X = {{1/4, 3/8, 1/2, 3/4, 1, 3/2, 2, 3, 4, 6, 8, 12}
Here we embellish slightly by adding 1 digit of precision to get: ß = 2, p = 3, e € -1,0,1,2,3
2a) Write a function (by completing the template below) to compute the number of entries in the array of all normalized representable values in a floating point system. Remember that the first digit in a normalized number must be non-zero. The other digits are integers satisfying 0
Expert Answer
Answer to What we think of as real numbers in an algorithm, we approximate for computing purposes as floating-point numbers of the…
OR