Concepts:
https://docs.python.org/3/library/math.html
| power and logarithmic | efficient computation, data analysis |
| trigonometric | physics, machine learning, time series |
| hyperbolic | physics, machine learning, time series |
| special functions | statistics, machine learning |
Example: sin and cos, in Go.
var _cos = [...]float64{
-1.13585365213876817300e-11, // 0xbda8fa49a0861a9b
2.08757008419747316778e-9, // 0x3e21ee9d7b4e3f05
-2.75573141792967388112e-7, // 0xbe927e4f7eac4bc6
2.48015872888517045348e-5, // 0x3efa01a019c844f5
-1.38888888888730564116e-3, // 0xbf56c16c16c14f91
4.16666666666665929218e-2, // 0x3fa555555555554b
}
func Cos(x float64) float64 {
const (
PI4A = 7.85398125648498535156e-1 // 0x3fe921fb40000000, Pi/4 split into three parts
PI4B = 3.77489470793079817668e-8 // 0x3e64442d00000000,
PI4C = 2.69515142907905952645e-15 // 0x3ce8469898cc5170,
)
// special cases
switch {
case IsNaN(x) || IsInf(x, 0):
return NaN()
}
// make argument positive
sign := false
x = Abs(x)
var j uint64
var y, z float64
if x >= reduceThreshold {
j, z = trigReduce(x)
} else {
j = uint64(x * (4 / Pi)) // integer part of x/(Pi/4), as integer for tests on the phase angle
y = float64(j) // integer part of x/(Pi/4), as float
// map zeros to origin
if j&1 == 1 {
j++
y++
}
j &= 7 // octant modulo 2Pi radians (360 degrees)
z = ((x - y*PI4A) - y*PI4B) - y*PI4C // Extended precision modular arithmetic
}
if j > 3 {
j -= 4
sign = !sign
}
if j > 1 {
sign = !sign
}
zz := z * z
if j == 1 || j == 2 {
y = z + z*zz*((((((_sin[0]*zz)+_sin[1])*zz+_sin[2])*zz+_sin[3])*zz+_sin[4])*zz+_sin[5])
} else {
y = 1.0 - 0.5*zz + zz*zz*((((((_cos[0]*zz)+_cos[1])*zz+_cos[2])*zz+_cos[3])*zz+_cos[4])*zz+_cos[5])
}
if sign {
y = -y
}
return y
}
def poly(x, aa):
xi, v = 1, 0
for a in aa:
v += a*xi
xi *= x
return v
Function $f(x)$ is analytic if for any $x_0 \in D$: $$f(x) = \sum_{i=0}^\infty a_i (x-x_0)^i$$.
These are Taylor series!
If $f(x)$ is infinitely differentiable, then $$\mathrm{Taylor}(f(x), a) = \sum_{i=0}^\infty \frac {f^{(i)}(a)} {i!} (x-a)^i$$ at point $a$.