Recall Toy System Characterized Following Parameter Values B 2 P 2 E 1 0 1 2 3 Embellish S Q43885738
1a and 1b are solved. Need help with 2a and 2bPython Coding. Please help me
Recall that the “toy” system was characterized by the following parameter values: B = 2, p = 2, e € -1,0, 1, 2, 3. Here we embellish slightly by adding 1 digit of precision to get: B = 2, p = 3, e € -1,0,1,2,3 1a) Write a function (by completing the template below) that computes the represented number corresponding to a specific set of parameter values: def params_to_num( sign_bit, digits, exponent, base=2): compute the numerical value corresponding to floating point parameter values Args : sign_bit: 0 for positive, 1 for negative digits: list of integer digits in range[0, base] exponent: integer exponent value Named args: base: default value 2 Returns: float value of represented number #insert code here return x 1b) Test your implementation by checking that params_to_num(1, [1,0,1), 3) returns the value -10.0. -10.0 == params_to_num(1, [1,0,1), 3) > E:extrapython 8 X IPython console Console 1/A % 1 File “E:/extra/python/paramtonum.py”, line 6 if((temp < len(digits)): SyntaxError: invalid syntax Ditor – E:extrapythonparamtonum.py 7 paramtonum.py* % 1 def params_to_num( sign_bit, digits, exponent, base =2): temp = 0 sum = 0.0 #decrementing the value of exponent upto for i in range (exponent, -1, -1): bit = 0 #iterating through digits for each value of i if temp < len(digits): bit – digits[temp] sum += bit * 2**i temp += 1 #if sign_bit is one, multiply with -1 if sign_bit == 1: return sum* – 1 return sum In [6]: 000 In [6]: runfile(‘E:/extra/python/paramtonum.py’, wdir=’E:/extra/ python) -10 In [7]: runfile(‘E:/extra/python/paramtonum.py’, wdir=’E:/extra/ python) – 10 16 17 print (params_to_num(1, (1, 0, 1), 3)) In [8]: runfile(‘E:/extra/python/paramtonum.py’, wdir=’s:/extra/ python) -10 In [9]: runfile(‘E:/extra/python/paramtonum.py’, wdir=’E:/extra/ python) – 11 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. In [ ]: 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. In [ ]: 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 #insert code here vals = np. sort(vals) #sort the array return vals Show transcribed image text Recall that the “toy” system was characterized by the following parameter values: B = 2, p = 2, e € -1,0, 1, 2, 3. Here we embellish slightly by adding 1 digit of precision to get: B = 2, p = 3, e € -1,0,1,2,3 1a) Write a function (by completing the template below) that computes the represented number corresponding to a specific set of parameter values: def params_to_num( sign_bit, digits, exponent, base=2): compute the numerical value corresponding to floating point parameter values Args : sign_bit: 0 for positive, 1 for negative digits: list of integer digits in range[0, base] exponent: integer exponent value Named args: base: default value 2 Returns: float value of represented number #insert code here return x 1b) Test your implementation by checking that params_to_num(1, [1,0,1), 3) returns the value -10.0. -10.0 == params_to_num(1, [1,0,1), 3)
> E:extrapython 8 X IPython console Console 1/A % 1 File “E:/extra/python/paramtonum.py”, line 6 if((temp
Expert Answer
Answer to Recall that the “toy” system was characterized by the following parameter values: B = 2, p = 2, e € -1,0, 1, 2, 3. Her…
OR