Kimikazu Kato
October 15, 2022
420

# Python 3.11: What changed in math?

Introduces what's new in the math module in Python 3.11.

October 15, 2022

## Transcript

1. ### Kimikazu Kato Python 3.11 What changed in math? PyCon JP

2022 LT in party

3. ### About our service Axross Recipe Leaning site for machine learning

and data analysis User create contents, but high quality (created by professional data scientists) ݸਓͰ΋๏ਓͰ΋ར༻Ͱ͖·͢ʂ https://axross-recipe.com/

5. ### math.exp2(): return 2 raised to the power of x. math.cbrt():

return the cube root of x. Do we really need them? They can be computed using existing functions. 2x 3 x
6. ### Reasons • Implemented in C99 • Also implemented in numpy

• For better accuracy
7. ### Accuracy >>> 5**(1/3) 1.7099759466766968 >>> pow(5,1/3) 1.7099759466766968 >>> math.cbrt(5) 1.709975946676697

Di ff erent results!
8. ### Performance >>> timeit.timeit("2**1.2", "import math") 0.013247291004518047 >>> timeit.timeit("math.exp2(1.2)", "import math")

0.04908258400973864 >>> timeit.timeit("5**(1/3)","import math") 0.012019957997836173 >>> timeit.timeit("math.cbrt(5)","import math") 0.06318095800816081 Slower! (I don't know why)
9. ### Mathematically is not de fi ned, but lim x→−∞ ax

= lim x→∞ 1 ax = ∞ for 0−∞ |a| < 1, a ≠ 0 Thus this is reasonable.
10. ### ax a > 0 x can be de fi ned

for an arbitrary if a < 0 ax For , is only de fi ned if is integer x 0x = 0 if unde fi ned if unde fi ned also for but it is sometimes convenient to de fi ne x < 0 x > 0 x = 0 00 = 1 Mathematical de fi nition of power operation ax (Caution: sometimes di ff erent from computer implementation)

12. ### The math.nan is already implemented in the past, but has

not been available for all the environments (??) Before 3.11, the common way to get nan is float("nan")
13. ### Conclusion • The math module is still improving! • Don't

forget about math! Numpy is not everything!