<jupyter_start><jupyter_text>Inf, NaN and Numerics<jupyter_code>from numpy import exp, finfo, log<jupyter_output><empty_output><jupyter_text>Exercise 1Obviously 1000 is the correct answer<jupyter_code>log(exp(1000))<jupyter_output><empty_output><jupyter_text>Exercise 2<jupyter_code>eps = finfo(float).eps
0 == eps / 10<jupyter_output><empty_output><jupyter_text>Exercise 3<jupyter_code>x = (1 + eps / 10) - 1
x == 0<jupyter_output><empty_output><jupyter_text>Exercise 4<jupyter_code>0.1 == (0.1 + eps / 10)<jupyter_output><empty_output><jupyter_text>Exercise 5<jupyter_code>x = 1.0 * 10 ** 120
y = 1.0 * 10 ** 120 + 1 * 10 ** 102
print("type(x):")
print(type(x))
print("type(y):")
print(type(y))
x == y<jupyter_output><empty_output><jupyter_text>Exercise 6This problem and the previous are different since x and y are integers herewhich have arbitrary precision in Python<jupyter_code>x = 10 ** 120
y = 10 ** 120 + 10 ** 102
print("type(x):")
print(type(x))
print("type(y):")
print(type(y))
x == y<jupyter_output><empty_output><jupyter_text>Exercise 6_Note_: This solution uses a loop which is introduced in a later chapter.<jupyter_code>x = 2.0
count = 0
while x != 1.0:
    count += 1
    x = 1.0 + (x - 1.0) / 2.0
    print(count, x)
print("count:")
print(count)
print("x:")
print(x)
print("2**(-count+1):")
print(2 ** (-count + 1))
print("eps:")
print(eps)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16534867002156722, 'fraction_numerical': 0.05751258087706686, 'mean_word_length': 6.44385026737968, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '186926', 'license': 'CC0-1.0', 'n_tokens_mistral': 632, 'n_tokens_neox': 557, 'n_words': 118, 'path': 'solutions/chapter09/inf_nan_and_numerics_solutions.ipynb', 'repo_name': 'bashtage/python-for-econometrics-statistics-data-analysis', 'size': '1391'}