chebax 0.1.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chebax/__init__.py +11 -0
- chebax/_src/__init__.py +0 -0
- chebax/_src/algorithms.py +74 -0
- chebax/_src/generate.py +106 -0
- chebax/_src/recipes/__init__.py +0 -0
- chebax/_src/recipes/besselj.py +138 -0
- chebax/_src/recipes/besselj_gen.py +76 -0
- chebax/_src/recipes/besselj_table.py +37 -0
- chebax/_src/series.py +195 -0
- chebax-0.1.0.dev0.dist-info/METADATA +35 -0
- chebax-0.1.0.dev0.dist-info/RECORD +14 -0
- chebax-0.1.0.dev0.dist-info/WHEEL +5 -0
- chebax-0.1.0.dev0.dist-info/licenses/LICENSE +28 -0
- chebax-0.1.0.dev0.dist-info/top_level.txt +1 -0
chebax/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""chebax: differentiable Chebyshev approximants for special functions.
|
|
2
|
+
|
|
3
|
+
Full float64 accuracy needs jax's x64 mode (jax.config.update("jax_enable_x64", True)).
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from chebax._src.generate import fit
|
|
7
|
+
from chebax._src.recipes.besselj import besselj, besselj_dnu
|
|
8
|
+
from chebax._src.series import ChebSeries, PiecewiseCheb
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0.dev0"
|
|
11
|
+
__all__ = ["ChebSeries", "PiecewiseCheb", "besselj", "besselj_dnu", "fit", "__version__"]
|
chebax/_src/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""The textbook algorithms, in plain numpy, on [-1, 1].
|
|
2
|
+
|
|
3
|
+
Coefficient convention is numpy.polynomial's: plain c[0], lowest order first,
|
|
4
|
+
p(t) = sum(c[k] * T_k(t)). These are the reference implementations; the jax
|
|
5
|
+
runtime in series.py must agree with them (tested against numpy.polynomial).
|
|
6
|
+
Domain handling lives in the series classes, not here.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def chebpts(n):
|
|
13
|
+
"""First-kind Chebyshev points cos(pi*(2i+1)/(2n)), decreasing from ~1 to ~-1."""
|
|
14
|
+
i = np.arange(n)
|
|
15
|
+
return np.cos(np.pi * (2 * i + 1) / (2 * n))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def chebfit_dct(samples):
|
|
19
|
+
"""Interpolation coefficients from samples taken at chebpts(len(samples)).
|
|
20
|
+
|
|
21
|
+
Discrete orthogonality of cosines on the first-kind points; O(n^2), which
|
|
22
|
+
is fine at generator degrees.
|
|
23
|
+
"""
|
|
24
|
+
n = len(samples)
|
|
25
|
+
i = np.arange(n)
|
|
26
|
+
j = np.arange(n)[:, None]
|
|
27
|
+
# reduce the angle with exact integer arithmetic; the raw product reaches
|
|
28
|
+
# hundreds of radians at large n and costs ~angle*eps of cosine accuracy
|
|
29
|
+
weights = np.cos(np.pi * ((j * (2 * i + 1)) % (4 * n)) / (2 * n))
|
|
30
|
+
c = (2.0 / n) * (weights @ np.asarray(samples, dtype=float))
|
|
31
|
+
c[0] /= 2
|
|
32
|
+
return c
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def chebval(t, c):
|
|
36
|
+
"""Clenshaw evaluation of a plain Chebyshev series."""
|
|
37
|
+
t = np.asarray(t, dtype=float)
|
|
38
|
+
b1 = np.zeros_like(t)
|
|
39
|
+
b2 = np.zeros_like(t)
|
|
40
|
+
for ck in np.asarray(c, dtype=float)[:0:-1]:
|
|
41
|
+
b1, b2 = 2 * t * b1 - b2 + ck, b1
|
|
42
|
+
return t * b1 - b2 + c[0]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def chebder(c):
|
|
46
|
+
"""Coefficients of the derivative (numpy.polynomial's exact recurrence)."""
|
|
47
|
+
c = np.array(c, dtype=float)
|
|
48
|
+
n = c.size - 1
|
|
49
|
+
if n == 0:
|
|
50
|
+
return np.zeros(1)
|
|
51
|
+
der = np.zeros(n)
|
|
52
|
+
for j in range(n, 2, -1):
|
|
53
|
+
der[j - 1] = 2 * j * c[j]
|
|
54
|
+
c[j - 2] += j * c[j] / (j - 2)
|
|
55
|
+
if n > 1:
|
|
56
|
+
der[1] = 4 * c[2]
|
|
57
|
+
der[0] = c[1]
|
|
58
|
+
return der
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def chebint(c):
|
|
62
|
+
"""Coefficients of the antiderivative that vanishes at t=0
|
|
63
|
+
(numpy.polynomial's k=0, lbnd=0 convention)."""
|
|
64
|
+
c = np.asarray(c, dtype=float)
|
|
65
|
+
n = c.size
|
|
66
|
+
out = np.zeros(n + 1)
|
|
67
|
+
out[1] = c[0]
|
|
68
|
+
if n > 1:
|
|
69
|
+
out[2] = c[1] / 4
|
|
70
|
+
for j in range(2, n):
|
|
71
|
+
out[j + 1] = c[j] / (2 * (j + 1))
|
|
72
|
+
out[j - 1] -= c[j] / (2 * (j - 1))
|
|
73
|
+
out[0] -= chebval(0.0, out)
|
|
74
|
+
return out
|
chebax/_src/generate.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Build-time fitting: sample at Chebyshev points, DCT to coefficients.
|
|
2
|
+
|
|
3
|
+
The float64 path uses numpy. Passing dps switches sampling and the DCT to
|
|
4
|
+
mpmath at that precision; mpmath is imported inside that branch only (the
|
|
5
|
+
runtime-imports rule in CLAUDE.md). Adaptive fitting doubles the node count
|
|
6
|
+
until the last two coefficients fall below tol relative to the largest, then
|
|
7
|
+
truncates the converged tail.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from chebax._src import algorithms
|
|
13
|
+
from chebax._src.series import ChebSeries, PiecewiseCheb
|
|
14
|
+
|
|
15
|
+
# ~2*eps: the practical floor of the float64 build path. Use dps= to go below.
|
|
16
|
+
_DEFAULT_TOL = 5e-16
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def fit(f, domain=(-1.0, 1.0), *, deg=None, tol=None, breaks=None, dps=None, max_deg=256):
|
|
20
|
+
"""Chebyshev interpolant of f, as a ChebSeries (or PiecewiseCheb if breaks given).
|
|
21
|
+
|
|
22
|
+
f: callable on the domain. Vectorized over numpy arrays if possible;
|
|
23
|
+
with dps set it must accept mpmath floats instead.
|
|
24
|
+
domain: (a, b). Ignored when breaks is given.
|
|
25
|
+
deg: fixed degree; otherwise the degree adapts until tol is met.
|
|
26
|
+
tol: target for the relative coefficient tail (default 5e-16).
|
|
27
|
+
breaks: strictly increasing knots, endpoints included; one series per
|
|
28
|
+
segment, each fit independently, padded to a common degree.
|
|
29
|
+
dps: mpmath working precision for sampling and the DCT. Derivatives of
|
|
30
|
+
a float64-built fit sit at a ~deg^2 * eps floor (differentiation
|
|
31
|
+
amplifies sample noise); build with dps when that matters.
|
|
32
|
+
max_deg: adaptive-path cap; exceeded means f is not smooth enough on the
|
|
33
|
+
interval (split the domain) or genuinely needs a higher degree.
|
|
34
|
+
"""
|
|
35
|
+
if tol is None:
|
|
36
|
+
tol = _DEFAULT_TOL
|
|
37
|
+
if breaks is not None:
|
|
38
|
+
br = [float(t) for t in breaks]
|
|
39
|
+
cs = [_fit_interval(f, br[i], br[i + 1], deg, tol, max_deg, dps)
|
|
40
|
+
for i in range(len(br) - 1)]
|
|
41
|
+
n = max(c.size for c in cs)
|
|
42
|
+
coef = np.zeros((len(cs), n))
|
|
43
|
+
for i, c in enumerate(cs):
|
|
44
|
+
coef[i, : c.size] = c
|
|
45
|
+
return PiecewiseCheb(coef, br)
|
|
46
|
+
a, b = float(domain[0]), float(domain[1])
|
|
47
|
+
return ChebSeries(_fit_interval(f, a, b, deg, tol, max_deg, dps), (a, b))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _fit_interval(f, a, b, deg, tol, max_deg, dps):
|
|
51
|
+
dct = _dct_mp(f, a, b, dps) if dps is not None else _dct_np(f, a, b)
|
|
52
|
+
if deg is not None:
|
|
53
|
+
return dct(deg + 1)
|
|
54
|
+
return _adaptive(dct, tol, max_deg, (a, b))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _adaptive(dct, tol, max_deg, interval):
|
|
58
|
+
n = 17
|
|
59
|
+
while True:
|
|
60
|
+
c = dct(n)
|
|
61
|
+
scale = np.max(np.abs(c))
|
|
62
|
+
if scale == 0.0:
|
|
63
|
+
return np.zeros(1)
|
|
64
|
+
if np.max(np.abs(c[-2:])) <= tol * scale:
|
|
65
|
+
keep = np.nonzero(np.abs(c) > tol * scale)[0]
|
|
66
|
+
return c[: keep[-1] + 1] if keep.size else c[:1]
|
|
67
|
+
if n > max_deg:
|
|
68
|
+
raise ValueError(
|
|
69
|
+
f"no convergence to tol={tol:g} by degree {max_deg} on {interval}; "
|
|
70
|
+
"f may not be smooth there (split the domain) or needs a higher max_deg")
|
|
71
|
+
n = 2 * n - 1
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _dct_np(f, a, b):
|
|
75
|
+
def dct(n):
|
|
76
|
+
xk = a + (b - a) * (algorithms.chebpts(n) + 1) / 2
|
|
77
|
+
return algorithms.chebfit_dct(_sample(f, xk))
|
|
78
|
+
return dct
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _sample(f, xk):
|
|
82
|
+
# scalar-only callables (wrapped special functions) are common; fall back.
|
|
83
|
+
try:
|
|
84
|
+
y = np.asarray(f(xk), dtype=float)
|
|
85
|
+
if y.shape == xk.shape:
|
|
86
|
+
return y
|
|
87
|
+
except (TypeError, ValueError):
|
|
88
|
+
pass
|
|
89
|
+
return np.array([float(f(x)) for x in xk])
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _dct_mp(f, a, b, dps):
|
|
93
|
+
import mpmath as mp
|
|
94
|
+
|
|
95
|
+
def dct(n):
|
|
96
|
+
with mp.workdps(dps):
|
|
97
|
+
mid = (mp.mpf(b) + mp.mpf(a)) / 2
|
|
98
|
+
half = (mp.mpf(b) - mp.mpf(a)) / 2
|
|
99
|
+
fk = [f(mid + half * mp.cos(mp.pi * (2 * i + 1) / (2 * n))) for i in range(n)]
|
|
100
|
+
c = []
|
|
101
|
+
for j in range(n):
|
|
102
|
+
s = mp.fsum(fk[i] * mp.cos(mp.pi * j * (2 * i + 1) / (2 * n)) for i in range(n))
|
|
103
|
+
c.append(2 * s / n)
|
|
104
|
+
c[0] /= 2
|
|
105
|
+
return np.array([float(x) for x in c])
|
|
106
|
+
return dct
|
|
File without changes
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""J_v for real v in [0, 10] on x in [0, 8], from the baked nu-table.
|
|
2
|
+
|
|
3
|
+
J_v(x) = (x/2)^v / Gamma(v+1) * g_v(x^2), where g_v(z) = 0F1(; v+1; -z/4) is
|
|
4
|
+
entire, so g_v is one short Chebyshev series in z (the ../../bessel evidence,
|
|
5
|
+
PROJECT.md section 2). The baked table stores each z-coefficient as a
|
|
6
|
+
Chebyshev series in v; instantiation is 25 numpy Clenshaws, once per order,
|
|
7
|
+
cached. dJ/dx comes from jax.grad through the series custom_jvp; dJ/dv comes
|
|
8
|
+
from chebder along the v axis of the table (besselj_dnu).
|
|
9
|
+
|
|
10
|
+
Out of range is the caller's problem in v1: x > 8 evaluates the polynomial
|
|
11
|
+
outside its interval and diverges (tails are milestone M3); v outside [0, 10]
|
|
12
|
+
raises at instantiation.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import functools
|
|
16
|
+
import math
|
|
17
|
+
|
|
18
|
+
import jax
|
|
19
|
+
import jax.numpy as jnp
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from chebax._src import algorithms
|
|
23
|
+
from chebax._src.recipes import besselj_table as _tab
|
|
24
|
+
from chebax._src.series import ChebSeries
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _digamma(z):
|
|
28
|
+
"""float64 psi(z) for z >= 1: recurrence up to z >= 15, then the Bernoulli
|
|
29
|
+
series through z^-12 (A&S 6.3.5 / 6.3.18). Truncation < 1e-16 there."""
|
|
30
|
+
acc = 0.0
|
|
31
|
+
while z < 15.0:
|
|
32
|
+
acc -= 1.0 / z
|
|
33
|
+
z += 1.0
|
|
34
|
+
zi = 1.0 / (z * z)
|
|
35
|
+
tail = 1 / 12 - zi * (1 / 120 - zi * (1 / 252 - zi * (1 / 240 - zi * (1 / 132 - zi * (691 / 32760)))))
|
|
36
|
+
return acc + math.log(z) - 0.5 / z - zi * tail
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _coef_at(v):
|
|
40
|
+
"""The z-coefficient vector at order v: Clenshaw in v across table rows."""
|
|
41
|
+
t = 2.0 * v / _tab.VMAX - 1.0
|
|
42
|
+
return np.array([algorithms.chebval(t, row) for row in _tab.TABLE])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _check_order(v):
|
|
46
|
+
v = float(v)
|
|
47
|
+
if not 0.0 <= v <= _tab.VMAX:
|
|
48
|
+
raise ValueError(f"besselj table covers v in [0, {_tab.VMAX}], got {v}")
|
|
49
|
+
return v
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@jax.tree_util.register_pytree_node_class
|
|
53
|
+
class BesselJ:
|
|
54
|
+
"""Callable J_v on [0, 8]. Build with besselj(v)."""
|
|
55
|
+
|
|
56
|
+
def __init__(self, v, g):
|
|
57
|
+
self.v = float(v)
|
|
58
|
+
self.g = g
|
|
59
|
+
self._inv_gamma = 1.0 / math.gamma(self.v + 1.0)
|
|
60
|
+
|
|
61
|
+
def __call__(self, x):
|
|
62
|
+
x = jnp.asarray(x)
|
|
63
|
+
return self._inv_gamma * jnp.power(x / 2, self.v) * self.g(x * x)
|
|
64
|
+
|
|
65
|
+
def astype(self, dtype):
|
|
66
|
+
return BesselJ(self.v, self.g.astype(dtype))
|
|
67
|
+
|
|
68
|
+
def __repr__(self):
|
|
69
|
+
return f"BesselJ(v={self.v}, dtype={self.g.coef.dtype})"
|
|
70
|
+
|
|
71
|
+
def tree_flatten(self):
|
|
72
|
+
return (self.g,), self.v
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def tree_unflatten(cls, v, children):
|
|
76
|
+
obj = object.__new__(cls)
|
|
77
|
+
obj.v = v
|
|
78
|
+
obj.g = children[0]
|
|
79
|
+
obj._inv_gamma = 1.0 / math.gamma(v + 1.0)
|
|
80
|
+
return obj
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@jax.tree_util.register_pytree_node_class
|
|
84
|
+
class BesselJdnu:
|
|
85
|
+
"""Callable dJ_v/dv on (0, 8]. Build with besselj_dnu(v).
|
|
86
|
+
|
|
87
|
+
dJ/dv = pref * [(log(x/2) - psi(v+1)) g(z) + g_v(z)], g_v from chebder
|
|
88
|
+
along the v axis. The log makes x = 0 nan; for v = 0 that singularity
|
|
89
|
+
is real."""
|
|
90
|
+
|
|
91
|
+
def __init__(self, v, g, gnu):
|
|
92
|
+
self.v = float(v)
|
|
93
|
+
self.g = g
|
|
94
|
+
self.gnu = gnu
|
|
95
|
+
self._inv_gamma = 1.0 / math.gamma(self.v + 1.0)
|
|
96
|
+
self._psi = _digamma(self.v + 1.0)
|
|
97
|
+
|
|
98
|
+
def __call__(self, x):
|
|
99
|
+
x = jnp.asarray(x)
|
|
100
|
+
z = x * x
|
|
101
|
+
pref = self._inv_gamma * jnp.power(x / 2, self.v)
|
|
102
|
+
return pref * ((jnp.log(x / 2) - self._psi) * self.g(z) + self.gnu(z))
|
|
103
|
+
|
|
104
|
+
def astype(self, dtype):
|
|
105
|
+
return BesselJdnu(self.v, self.g.astype(dtype), self.gnu.astype(dtype))
|
|
106
|
+
|
|
107
|
+
def __repr__(self):
|
|
108
|
+
return f"BesselJdnu(v={self.v}, dtype={self.g.coef.dtype})"
|
|
109
|
+
|
|
110
|
+
def tree_flatten(self):
|
|
111
|
+
return (self.g, self.gnu), self.v
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def tree_unflatten(cls, v, children):
|
|
115
|
+
obj = object.__new__(cls)
|
|
116
|
+
obj.v = v
|
|
117
|
+
obj.g, obj.gnu = children
|
|
118
|
+
obj._inv_gamma = 1.0 / math.gamma(v + 1.0)
|
|
119
|
+
obj._psi = _digamma(v + 1.0)
|
|
120
|
+
return obj
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@functools.lru_cache(maxsize=None)
|
|
124
|
+
def besselj(v):
|
|
125
|
+
"""J_v on [0, 8] for real v in [0, 10]. Cached per order; no mpmath."""
|
|
126
|
+
v = _check_order(v)
|
|
127
|
+
return BesselJ(v, ChebSeries(_coef_at(v), (0.0, _tab.ZMAX)))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@functools.lru_cache(maxsize=None)
|
|
131
|
+
def besselj_dnu(v):
|
|
132
|
+
"""dJ_v/dv on (0, 8] for real v in [0, 10] (the order gradient)."""
|
|
133
|
+
v = _check_order(v)
|
|
134
|
+
t = 2.0 * v / _tab.VMAX - 1.0
|
|
135
|
+
gnu = np.array([algorithms.chebval(t, algorithms.chebder(row)) for row in _tab.TABLE])
|
|
136
|
+
gnu *= 2.0 / _tab.VMAX
|
|
137
|
+
return BesselJdnu(v, ChebSeries(_coef_at(v), (0.0, _tab.ZMAX)),
|
|
138
|
+
ChebSeries(gnu, (0.0, _tab.ZMAX)))
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Generator for the besselj nu-table. Build-time only; imports mpmath inside.
|
|
2
|
+
|
|
3
|
+
The table is the construction measured in experiments/02: fit the degree-24
|
|
4
|
+
Chebyshev coefficients of g_v(z) = 0F1(; v+1; -z/4) on z in [0, 64] at 64
|
|
5
|
+
Chebyshev nodes in v over [0, 10], then fit each coefficient as a Chebyshev
|
|
6
|
+
series in v. BOTH stages stay in mpmath and round to float64 only at the end:
|
|
7
|
+
rounding between the stages would put eps-level sample noise under the second
|
|
8
|
+
fit, and differentiation along v would amplify it by ~deg_v^2 (the M1 floor).
|
|
9
|
+
|
|
10
|
+
Regenerate with: python -m chebax._src.recipes.besselj_gen
|
|
11
|
+
The output must reproduce the checked-in table bit for bit (tested).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import numpy as np
|
|
15
|
+
|
|
16
|
+
NZ = 25 # z-degree 24, covers the worst case (v=0) with margin
|
|
17
|
+
NV = 64 # v-nodes
|
|
18
|
+
ZMAX = 64.0 # z = x^2, x in [0, 8]
|
|
19
|
+
VMAX = 10.0
|
|
20
|
+
DPS = 40
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def generate_table():
|
|
24
|
+
import mpmath as mp
|
|
25
|
+
|
|
26
|
+
with mp.workdps(DPS):
|
|
27
|
+
zmax = mp.mpf(ZMAX)
|
|
28
|
+
vmax = mp.mpf(VMAX)
|
|
29
|
+
|
|
30
|
+
def dct(samples):
|
|
31
|
+
n = len(samples)
|
|
32
|
+
c = []
|
|
33
|
+
for j in range(n):
|
|
34
|
+
s = mp.fsum(samples[i] * mp.cos(mp.pi * j * (2 * i + 1) / (2 * n))
|
|
35
|
+
for i in range(n))
|
|
36
|
+
c.append(2 * s / n)
|
|
37
|
+
c[0] /= 2
|
|
38
|
+
return c
|
|
39
|
+
|
|
40
|
+
tz = [mp.cos(mp.pi * (2 * i + 1) / (2 * NZ)) for i in range(NZ)]
|
|
41
|
+
vnodes = [(mp.cos(mp.pi * (2 * i + 1) / (2 * NV)) + 1) / 2 * vmax for i in range(NV)]
|
|
42
|
+
rows = [dct([mp.hyp0f1(v + 1, -((t + 1) / 2 * zmax) / 4) for t in tz]) for v in vnodes]
|
|
43
|
+
table = [dct([rows[i][k] for i in range(NV)]) for k in range(NZ)]
|
|
44
|
+
return np.array([[float(x) for x in row] for row in table])
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main():
|
|
48
|
+
import pathlib
|
|
49
|
+
|
|
50
|
+
import mpmath
|
|
51
|
+
|
|
52
|
+
table = generate_table()
|
|
53
|
+
lines = [
|
|
54
|
+
'"""Baked besselj nu-table. Generated by chebax._src.recipes.besselj_gen;',
|
|
55
|
+
'do not edit. Regenerate with: python -m chebax._src.recipes.besselj_gen',
|
|
56
|
+
'"""',
|
|
57
|
+
"",
|
|
58
|
+
"import numpy as np",
|
|
59
|
+
"",
|
|
60
|
+
f"META = {{'nz': {NZ}, 'nv': {NV}, 'zmax': {ZMAX!r}, 'vmax': {VMAX!r}, "
|
|
61
|
+
f"'dps': {DPS}, 'mpmath': {mpmath.__version__!r}}}",
|
|
62
|
+
f"ZMAX = {ZMAX!r}",
|
|
63
|
+
f"VMAX = {VMAX!r}",
|
|
64
|
+
"",
|
|
65
|
+
"TABLE = np.array([",
|
|
66
|
+
]
|
|
67
|
+
for row in table:
|
|
68
|
+
lines.append(" [" + ", ".join(repr(x) for x in row) + "],")
|
|
69
|
+
lines.append("])")
|
|
70
|
+
out = pathlib.Path(__file__).with_name("besselj_table.py")
|
|
71
|
+
out.write_text("\n".join(lines) + "\n")
|
|
72
|
+
print(f"wrote {out} ({table.shape[0]}x{table.shape[1]})")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Baked besselj nu-table. Generated by chebax._src.recipes.besselj_gen;
|
|
2
|
+
do not edit. Regenerate with: python -m chebax._src.recipes.besselj_gen
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
META = {'nz': 25, 'nv': 64, 'zmax': 64.0, 'vmax': 10.0, 'dps': 40, 'mpmath': '1.4.0'}
|
|
8
|
+
ZMAX = 64.0
|
|
9
|
+
VMAX = 10.0
|
|
10
|
+
|
|
11
|
+
TABLE = np.array([
|
|
12
|
+
[np.float64(0.3472316049235684), np.float64(0.20720848881772033), np.float64(-0.009396033994909556), np.float64(-0.012807849745354835), np.float64(0.008498663563727726), np.float64(-0.0038718580229806696), np.float64(0.0014745831630515842), np.float64(-0.0004689757458182797), np.float64(0.00010230159988173848), np.float64(1.0175341704064214e-05), np.float64(-3.2961364372376345e-05), np.float64(2.9131613650508137e-05), np.float64(-2.035877742827867e-05), np.float64(1.2870666269727138e-05), np.float64(-7.707226734199128e-06), np.float64(4.4655184091080755e-06), np.float64(-2.532257759004389e-06), np.float64(1.4150530342550788e-06), np.float64(-7.82618111481341e-07), np.float64(4.2962749583131126e-07), np.float64(-2.345639705080128e-07), np.float64(1.2754592234436162e-07), np.float64(-6.9142790243786e-08), np.float64(3.739588888596302e-08), np.float64(-2.018998753190061e-08), np.float64(1.0885849063045356e-08), np.float64(-5.863241558376156e-09), np.float64(3.1554791018305487e-09), np.float64(-1.697162858026686e-09), np.float64(9.123738658634458e-10), np.float64(-4.902976841216041e-10), np.float64(2.634028974686074e-10), np.float64(-1.414760301481393e-10), np.float64(7.597460720311407e-11), np.float64(-4.079380312439558e-11), np.float64(2.1901465858058404e-11), np.float64(-1.1757518012780338e-11), np.float64(6.311456347476991e-12), np.float64(-3.3878268110105655e-12), np.float64(1.8184249026263132e-12), np.float64(-9.760136513484117e-13), np.float64(5.238485390468316e-13), np.float64(-2.811559170928882e-13), np.float64(1.508975475344413e-13), np.float64(-8.098638593602279e-14), np.float64(4.3464816624318874e-14), np.float64(-2.332708921173419e-14), np.float64(1.2519321582100685e-14), np.float64(-6.718914569584727e-15), np.float64(3.60591875785447e-15), np.float64(-1.9352254794953177e-15), np.float64(1.038595094177753e-15), np.float64(-5.573912761163496e-16), np.float64(2.9913914880882207e-16), np.float64(-1.6054065584839236e-16), np.float64(8.615757426734226e-17), np.float64(-4.623716482603899e-17), np.float64(2.48114710674498e-17), np.float64(-1.3310302602605188e-17), np.float64(7.133228651036784e-18), np.float64(-3.809435014528638e-18), np.float64(2.009410704308605e-18), np.float64(-1.0131487183969746e-18), np.float64(4.221454185688748e-19)],
|
|
13
|
+
[np.float64(-0.35951080550020226), np.float64(-0.10993517564892244), np.float64(0.12828317520407462), np.float64(-0.06727211863790784), np.float64(0.02888483594978499), np.float64(-0.011156827117820452), np.float64(0.003935993426140997), np.float64(-0.0012270633972598227), np.float64(0.0002918978170821283), np.float64(-7.751000840748687e-06), np.float64(-5.5799749242161456e-05), np.float64(5.4029234610582617e-05), np.float64(-3.8677118005247395e-05), np.float64(2.4659076656973736e-05), np.float64(-1.4812350078470264e-05), np.float64(8.590465157045744e-06), np.float64(-4.871677025851566e-06), np.float64(2.721497359928708e-06), np.float64(-1.504506922561602e-06), np.float64(8.255407273089358e-07), np.float64(-4.5053064085641674e-07), np.float64(2.448887362639938e-07), np.float64(-1.3271275135415133e-07), np.float64(7.17589613084803e-08), np.float64(-3.873426459489578e-08), np.float64(2.0880749226456104e-08), np.float64(-1.1245033012078744e-08), np.float64(6.051172438960396e-09), np.float64(-3.2543096238927447e-09), np.float64(1.7493523314838905e-09), np.float64(-9.4002584505079e-10), np.float64(5.049880706026049e-10), np.float64(-2.712240083542699e-10), np.float64(1.45647038649702e-10), np.float64(-7.820200437954491e-11), np.float64(4.1984539264500465e-11), np.float64(-2.2538550396551682e-11), np.float64(1.2098604766441812e-11), np.float64(-6.494164406025384e-12), np.float64(3.4857368747660956e-12), np.float64(-1.8709099654856985e-12), np.float64(1.0041555219142151e-12), np.float64(-5.389408433754435e-13), np.float64(2.892510699105425e-13), np.float64(-1.5524011905385897e-13), np.float64(8.331613951016408e-14), np.float64(-4.4714802693483305e-14), np.float64(2.399778497314974e-14), np.float64(-1.2879208184704404e-14), np.float64(6.912031884344903e-15), np.float64(-3.709549522492538e-15), np.float64(1.990837047384409e-15), np.float64(-1.0684384152371041e-15), np.float64(5.734063355277588e-16), np.float64(-3.0773308668477996e-16), np.float64(1.6515151642179737e-16), np.float64(-8.862989887398692e-17), np.float64(4.755996613225916e-17), np.float64(-2.5513904398476898e-17), np.float64(1.3673355915863094e-17), np.float64(-7.302129419476395e-18), np.float64(3.851746134050904e-18), np.float64(-1.9420577229887513e-18), np.float64(8.091909359431358e-19)],
|
|
14
|
+
[np.float64(0.17493458997773245), np.float64(-0.13253057762059978), np.float64(0.020046721982906003), np.float64(0.013541703830843776), np.float64(-0.017005943806565716), np.float64(0.012746904629490116), np.float64(-0.008134429482334395), np.float64(0.004817110567615993), np.float64(-0.0027405772016556333), np.float64(0.0015237105598056595), np.float64(-0.0008356180714999071), np.float64(0.00045445569192335), np.float64(-0.0002458938834877242), np.float64(0.00013262522628759563), np.float64(-7.139223507320439e-05), np.float64(3.8383783282334266e-05), np.float64(-2.0621456546942925e-05), np.float64(1.1073682360302575e-05), np.float64(-5.944900727446621e-06), np.float64(3.1909920347015742e-06), np.float64(-1.7126373855806046e-06), np.float64(9.191407372364673e-07), np.float64(-4.932720598333328e-07), np.float64(2.6471918488446107e-07), np.float64(-1.420634734282566e-07), np.float64(7.623941898869778e-08), np.float64(-4.0914559579114945e-08), np.float64(2.1957240817891176e-08), np.float64(-1.178363626835784e-08), np.float64(6.323863578803849e-09), np.float64(-3.3938066485092345e-09), np.float64(1.8213480613433235e-09), np.float64(-9.77461939111963e-10), np.float64(5.245750633320443e-10), np.float64(-2.8152446966103703e-10), np.float64(1.5108635463431792e-10), np.float64(-8.108393373451389e-11), np.float64(4.3515578085083115e-11), np.float64(-2.3353662959543634e-11), np.float64(1.2533301891772357e-11), np.float64(-6.726299251777416e-12), np.float64(3.6098322562939646e-12), np.float64(-1.9373049030496233e-12), np.float64(1.039702357138009e-12), np.float64(-5.579819549596914e-13), np.float64(2.9945484110851925e-13), np.float64(-1.607098770749822e-13), np.float64(8.624895374502763e-14), np.float64(-4.628764975302285e-14), np.float64(2.4841421588931714e-14), np.float64(-1.3331768762075968e-14), np.float64(7.154826259343846e-15), np.float64(-3.839815446160314e-15), np.float64(2.0607313101210046e-15), np.float64(-1.1059399078169935e-15), np.float64(5.935245568000208e-16), np.float64(-3.185190655655259e-16), np.float64(1.7092121613706022e-16), np.float64(-9.169185971220959e-17), np.float64(4.913924992474557e-17), np.float64(-2.6242341263889748e-17), np.float64(1.3842369594346134e-17), np.float64(-6.97934596576309e-18), np.float64(2.908060806685867e-18)],
|
|
15
|
+
[np.float64(-0.08587799623640216), np.float64(0.12799729652324027), np.float64(-0.07604566186699718), np.float64(0.04051255844328909), np.float64(-0.020388186707383158), np.float64(0.009963749199746364), np.float64(-0.004805940552425734), np.float64(0.002311294355432297), np.float64(-0.0011154778325831467), np.float64(0.0005424209179406646), np.float64(-0.0002663582718268773), np.float64(0.00013221613823324912), np.float64(-6.634848780418864e-05), np.float64(3.3641660517215025e-05), np.float64(-1.721988096759028e-05), np.float64(8.888156892864288e-06), np.float64(-4.620833919501569e-06), np.float64(2.4169647467108065e-06), np.float64(-1.2706208703064759e-06), np.float64(6.707549965008845e-07), np.float64(-3.5528455033084093e-07), np.float64(1.8869885191799007e-07), np.float64(-1.0044026504765022e-07), np.float64(5.3555022294123164e-08), np.float64(-2.8595061008725996e-08), np.float64(1.5284652504852348e-08), np.float64(-8.17700359277463e-09), np.float64(4.3775150629995094e-09), np.float64(-2.3447317265467832e-09), np.float64(1.2564380894874824e-09), np.float64(-6.734917956184773e-10), np.float64(3.6110706585182053e-10), np.float64(-1.936546303119482e-10), np.float64(1.0386972050131279e-10), np.float64(-5.571912249175793e-11), np.float64(2.989248848456021e-11), np.float64(-1.6038109366000474e-11), np.float64(8.605386010648744e-12), np.float64(-4.617511382750228e-12), np.float64(2.4777734614033474e-12), np.float64(-1.3296206556233975e-12), np.float64(7.135160145557488e-13), np.float64(-3.829017785422217e-13), np.float64(2.0548355054916601e-13), np.float64(-1.1027357447483375e-13), np.float64(5.917926050304952e-14), np.float64(-3.1759269565743015e-14), np.float64(1.7044086895622824e-14), np.float64(-9.147001392251379e-15), np.float64(4.9089107512759685e-15), np.float64(-2.6344660586167327e-15), np.float64(1.4138420980903284e-15), np.float64(-7.587693934306406e-16), np.float64(4.072105040634307e-16), np.float64(-2.1853836188201092e-16), np.float64(1.1728263410741865e-16), np.float64(-6.294040944843031e-17), np.float64(3.3774537438803605e-17), np.float64(-1.8118559768254597e-17), np.float64(9.710039353053611e-18), np.float64(-5.185548690074643e-18), np.float64(2.7352833858906287e-18), np.float64(-1.3791338968079604e-18), np.float64(5.746389737708413e-19)],
|
|
16
|
+
[np.float64(0.02664997615543401), np.float64(-0.04607081009091971), np.float64(0.03329979958358112), np.float64(-0.021621313151958185), np.float64(0.013135383098642754), np.float64(-0.007648645094817189), np.float64(0.004332691674818518), np.float64(-0.0024102636895916925), np.float64(0.0013248494073225137), np.float64(-0.0007224571826930927), np.float64(0.0003918843705914111), np.float64(-0.000211822386596804), np.float64(0.00011422586942973025), np.float64(-6.150006430144133e-05), np.float64(3.307739597633335e-05), np.float64(-1.7777974632417388e-05), np.float64(9.550559099039305e-06), np.float64(-5.129059672456268e-06), np.float64(2.753935892460258e-06), np.float64(-1.4784509507113612e-06), np.float64(7.936282174112329e-07), np.float64(-4.2598850058054524e-07), np.float64(2.286432463509122e-07), np.float64(-1.2271702232953576e-07), np.float64(6.586298392216243e-08), np.float64(-3.534850626608474e-08), np.float64(1.8971244003400692e-08), np.float64(-1.0181623455195738e-08), np.float64(5.464314813829526e-09), np.float64(-2.9325980736138453e-09), np.float64(1.5738669778702437e-09), np.float64(-8.446611158873731e-10), np.float64(4.533109784672141e-10), np.float64(-2.4328168568937627e-10), np.float64(1.3056361831503393e-10), np.float64(-7.007040400556016e-11), np.float64(3.760510669815e-11), np.float64(-2.0181751081869436e-11), np.float64(1.0831054092341491e-11), np.float64(-5.8127613936952e-12), np.float64(3.1195660412113247e-12), np.float64(-1.6741941022132644e-12), np.float64(8.984985517841637e-13), np.float64(-4.82201899194368e-13), np.float64(2.5878578774563926e-13), np.float64(-1.3888389997837278e-13), np.float64(7.453553393378052e-14), np.float64(-4.000136543295361e-14), np.float64(2.146773638741104e-14), np.float64(-1.152119908021666e-14), np.float64(6.1831402237566066e-15), np.float64(-3.3183369611627655e-15), np.float64(1.7808682750367747e-15), np.float64(-9.557468116193857e-16), np.float64(5.129240361967787e-16), np.float64(-2.752708598628823e-16), np.float64(1.477260210113144e-16), np.float64(-7.927158785001395e-17), np.float64(4.2525788688688736e-17), np.float64(-2.279030452398354e-17), np.float64(1.2170941967745598e-17), np.float64(-6.419956114181353e-18), np.float64(3.2369526709826298e-18), np.float64(-1.3487302817262479e-18)],
|
|
17
|
+
[np.float64(-0.005087135154882115), np.float64(0.009231319871598372), np.float64(-0.007214742736723321), np.float64(0.005079333242792772), np.float64(-0.003324538800590909), np.float64(0.0020665492910572677), np.float64(-0.0012377770976329772), np.float64(0.0007215754806467639), np.float64(-0.00041232731676896445), np.float64(0.00023213077420045745), np.float64(-0.00012922936749154925), np.float64(7.133637354076514e-05), np.float64(-3.9125669506117025e-05), np.float64(2.135367673727717e-05), np.float64(-1.161023671099612e-05), np.float64(6.294258137358318e-06), np.float64(-3.4046391309286148e-06), np.float64(1.8384055101586473e-06), np.float64(-9.913451048002063e-07), np.float64(5.340139195038857e-07), np.float64(-2.8742570889405e-07), np.float64(1.5460458342243153e-07), np.float64(-8.311964954202854e-08), np.float64(4.467010281656685e-08), np.float64(-2.3999321036020276e-08), np.float64(1.2890757177898164e-08), np.float64(-6.922735959986884e-09), np.float64(3.7171874144042226e-09), np.float64(-1.995731694001275e-09), np.float64(1.0713997147460945e-09), np.float64(-5.751364797290803e-10), np.float64(3.087214758453297e-10), np.float64(-1.6570835573495207e-10), np.float64(8.894214607109217e-11), np.float64(-4.7737486976589604e-11), np.float64(2.5621390593370092e-11), np.float64(-1.3751147786224555e-11), np.float64(7.380228469091434e-12), np.float64(-3.960923361601902e-12), np.float64(2.1257870923407283e-12), np.float64(-1.1408814084421404e-12), np.float64(6.122928857896239e-13), np.float64(-3.286066415899361e-13), np.float64(1.7635680321878023e-13), np.float64(-9.464705955247418e-14), np.float64(5.079503601774928e-14), np.float64(-2.726056311933158e-14), np.float64(1.46301205916765e-14), np.float64(-7.851644413090116e-15), np.float64(4.2137915904097855e-15), np.float64(-2.2614409450138036e-15), np.float64(1.2136606019646734e-15), np.float64(-6.513419466923985e-16), np.float64(3.4955899731492454e-16), np.float64(-1.8759919607690832e-16), np.float64(1.0067888384765225e-16), np.float64(-5.403004556168253e-17), np.float64(2.899319205398206e-17), np.float64(-1.555360131363475e-17), np.float64(8.335445193244637e-18), np.float64(-4.451464668990943e-18), np.float64(2.3480689705746716e-18), np.float64(-1.1839004246233666e-18), np.float64(4.932918701381847e-19)],
|
|
18
|
+
[np.float64(0.0006454768915704566), np.float64(-0.001196557823052477), np.float64(0.0009743792976015991), np.float64(-0.0007182723791055646), np.float64(0.0004913855618565048), np.float64(-0.00031785851300131137), np.float64(0.00019709451445398056), np.float64(-0.00011833795186386364), np.float64(6.931649199948305e-05), np.float64(-3.983425136617894e-05), np.float64(2.2554822579444065e-05), np.float64(-1.2624233932137905e-05), np.float64(7.002427393753256e-06), np.float64(-3.856731957576026e-06), np.float64(2.1124147148702638e-06), np.float64(-1.1519800786585705e-06), np.float64(6.26068821784011e-07), np.float64(-3.393349881021513e-07), np.float64(1.8353322425944934e-07), np.float64(-9.910073759775523e-08), np.float64(5.344043026280049e-08), np.float64(-2.878827403830849e-08), np.float64(1.549564787604991e-08), np.float64(-8.335423128964618e-09), np.float64(4.481554107734462e-09), np.float64(-2.408570311231296e-09), np.float64(1.2940657360740398e-09), np.float64(-6.951018675452154e-10), np.float64(3.7330025505393243e-10), np.float64(-2.0044885585396323e-10), np.float64(1.0762130948125615e-10), np.float64(-5.7776774042196446e-11), np.float64(3.10153873484607e-11), np.float64(-1.6648563139761596e-11), np.float64(8.93628903798372e-12), np.float64(-4.796480606989915e-12), np.float64(2.5744025370921635e-12), np.float64(-1.3817231450284998e-12), np.float64(7.415806955501312e-13), np.float64(-3.980064996926552e-13), np.float64(2.136079929317948e-13), np.float64(-1.146413727328362e-13), np.float64(6.1526547952793e-14), np.float64(-3.302034452137726e-14), np.float64(1.7721439289116274e-14), np.float64(-9.510756925884227e-15), np.float64(5.104229051614507e-15), np.float64(-2.7393304846997964e-15), np.float64(1.4701379256651749e-15), np.float64(-7.8898953283560215e-16), np.float64(4.234323289793327e-16), np.float64(-2.272461135499193e-16), np.float64(1.219575269888295e-16), np.float64(-6.545160809586843e-17), np.float64(3.5126188254535527e-17), np.float64(-1.885118312605212e-17), np.float64(1.0116625787870063e-17), np.float64(-5.428708066260295e-18), np.float64(2.912269075540812e-18), np.float64(-1.5607358259924936e-18), np.float64(8.334961131628966e-19), np.float64(-4.396545123564983e-19), np.float64(2.216745770977177e-19), np.float64(-9.236441561551737e-20)],
|
|
19
|
+
[np.float64(-5.8263640583020745e-05), np.float64(0.00010925923075492961), np.float64(-9.123741251078639e-05), np.float64(6.931608487892682e-05), np.float64(-4.8882525993969596e-05), np.float64(3.2526497383165673e-05), np.float64(-2.068363439126073e-05), np.float64(1.2693912222264529e-05), np.float64(-7.576019411099099e-06), np.float64(4.423051483063637e-06), np.float64(-2.5376705001100126e-06), np.float64(1.4359806658326162e-06), np.float64(-8.037090772498739e-07), np.float64(4.459286486345224e-07), np.float64(-2.45711547878236e-07), np.float64(1.3464732915327152e-07), np.float64(-7.346391092308619e-08), np.float64(3.994351780315994e-08), np.float64(-2.1658403636405718e-08), np.float64(1.1718244890457482e-08), np.float64(-6.3292450645482494e-09), np.float64(3.413902150089093e-09), np.float64(-1.8394341690281483e-09), np.float64(9.902614090709034e-10), np.float64(-5.327528146098352e-10), np.float64(2.8646627140552237e-10), np.float64(-1.5397197663253353e-10), np.float64(8.273107402482365e-11), np.float64(-4.444108415437361e-11), np.float64(2.3867857143269338e-11), np.float64(-1.2816626909983403e-11), np.float64(6.88145554445073e-12), np.float64(-3.694406694790904e-12), np.float64(1.983243391337467e-12), np.float64(-1.0645875592330342e-12), np.float64(5.714344486755375e-13), np.float64(-3.067153460636525e-13), np.float64(1.6462360122961657e-13), np.float64(-8.835658012313857e-14), np.float64(4.7421799044222216e-14), np.float64(-2.545136872757527e-14), np.float64(1.3659649358525406e-14), np.float64(-7.331017752544793e-15), np.float64(3.934468767929941e-15), np.float64(-2.111570911079779e-15), np.float64(1.1332441003346509e-15), np.float64(-6.081908404156161e-16), np.float64(3.2640379286346643e-16), np.float64(-1.7517400791248512e-16), np.float64(9.401203818027454e-17), np.float64(-5.0454132358403696e-17), np.float64(2.7077563733731896e-17), np.float64(-1.4531887917395646e-17), np.float64(7.798911510599094e-18), np.float64(-4.185476277643659e-18), np.float64(2.2462217098795033e-18), np.float64(-1.2054516886831321e-18), np.float64(6.468606043765875e-19), np.float64(-3.470130312503041e-19), np.float64(1.859703636383252e-19), np.float64(-9.931571250152056e-20), np.float64(5.2387292210130713e-20), np.float64(-2.641376614960953e-20), np.float64(1.1005737275632698e-20)],
|
|
20
|
+
[np.float64(3.935847969419735e-06), np.float64(-7.433881003177129e-06), np.float64(6.314114479412722e-06), np.float64(-4.901387053355243e-06), np.float64(3.535274491680246e-06), np.float64(-2.4037567306895095e-06), np.float64(1.5590311751673978e-06), np.float64(-9.737063768912605e-07), np.float64(5.900412080376554e-07), np.float64(-3.4899723926250594e-07), np.float64(2.0245333043394305e-07), np.float64(-1.1562570667312025e-07), np.float64(6.521468634815601e-08), np.float64(-3.6414274704812005e-08), np.float64(2.0169622843671146e-08), np.float64(-1.109993120832778e-08), np.float64(6.077153191597591e-09), np.float64(-3.3135148327829746e-09), np.float64(1.8007330719043295e-09), np.float64(-9.760512747510242e-10), np.float64(5.279491077321003e-10), np.float64(-2.850979816152915e-10), np.float64(1.5375446699962987e-10), np.float64(-8.283453602861427e-11), np.float64(4.459021290082801e-11), np.float64(-2.398760587048307e-11), np.float64(1.2897717181051754e-11), np.float64(-6.932092290264462e-12), np.float64(3.724590025905736e-12), np.float64(-2.0007119512547552e-12), np.float64(1.074498245437665e-12), np.float64(-5.769791374166761e-13), np.float64(3.097862176881213e-13), np.float64(-1.6631174746160116e-13), np.float64(8.927944312345977e-14), np.float64(-4.7924179905418415e-14), np.float64(2.5723972894131825e-14), np.float64(-1.380720658290714e-14), np.float64(7.410736886080131e-15), np.float64(-3.9774744400440834e-15), np.float64(2.134744498463106e-15), np.float64(-1.1457201041236475e-15), np.float64(6.149029294835923e-16), np.float64(-3.3001295198909894e-16), np.float64(1.7711387446062008e-16), np.float64(-9.505434425738515e-17), np.float64(5.101402893872972e-17), np.float64(-2.7378264900102814e-17), np.float64(1.4693361211893217e-17), np.float64(-7.885614737177926e-18), np.float64(4.2320354566587584e-18), np.float64(-2.271237285464429e-18), np.float64(1.2189201298527662e-18), np.float64(-6.541651855633563e-19), np.float64(3.510738611178167e-19), np.float64(-1.8841104973281002e-19), np.float64(1.0111222483215186e-19), np.float64(-5.4258107738749e-20), np.float64(2.9107157209290003e-20), np.float64(-1.5599037404785643e-20), np.float64(8.330519050619816e-21), np.float64(-4.3942026435427916e-21), np.float64(2.2155649207855827e-21), np.float64(-9.231521948897386e-22)],
|
|
21
|
+
[np.float64(-2.066773130456935e-07), np.float64(3.922900445677778e-07), np.float64(-3.373268628322731e-07), np.float64(2.661412580128811e-07), np.float64(-1.953648792664808e-07), np.float64(1.3515228385562235e-07), np.float64(-8.908336427750861e-08), np.float64(5.645434791338712e-08), np.float64(-3.465259057964316e-08), np.float64(2.0726289990857152e-08), np.float64(-1.2138810244333745e-08), np.float64(6.989154272517958e-09), np.float64(-3.968914744448334e-09), np.float64(2.2287530873587615e-09), np.float64(-1.240302397659498e-09), np.float64(6.852165650963067e-10), np.float64(-3.7633986907255745e-10), np.float64(2.057245182664736e-10), np.float64(-1.1203444276008558e-10), np.float64(6.082822579800853e-11), np.float64(-3.2946680711187e-11), np.float64(1.7810829689764437e-11), np.float64(-9.613765855913988e-12), np.float64(5.182945731401315e-12), np.float64(-2.7915330662408695e-12), np.float64(1.5023770723415316e-12), np.float64(-8.080800854935325e-13), np.float64(4.344342884813923e-13), np.float64(-2.334702563613698e-13), np.float64(1.25432836788431e-13), np.float64(-6.737369447204443e-14), np.float64(3.618181852489746e-14), np.float64(-1.942800729610653e-14), np.float64(1.043079224260111e-14), np.float64(-5.599741692817673e-15), np.float64(3.005997420250989e-15), np.float64(-1.61356180878918e-15), np.float64(8.660921319541102e-16), np.float64(-4.648662985875928e-16), np.float64(2.495058024230174e-16), np.float64(-1.33913486360369e-16), np.float64(7.187220894856479e-17), np.float64(-3.857377927968413e-17), np.float64(2.0702323833471116e-17), np.float64(-1.111073123350492e-17), np.float64(5.962982751739445e-18), np.float64(-3.2002389092665953e-18), np.float64(1.717511419873389e-18), np.float64(-9.217552073463666e-19), np.float64(4.946870864420069e-19), np.float64(-2.654879201103163e-19), np.float64(1.4248145074145205e-19), np.float64(-7.646652321255015e-20), np.float64(4.103776857048703e-20), np.float64(-2.2023937968218123e-20), np.float64(1.181960548843363e-20), np.float64(-6.343082819589929e-21), np.float64(3.403779669997966e-21), np.float64(-1.825982669863739e-21), np.float64(9.78576334715906e-22), np.float64(-5.225995238412465e-22), np.float64(2.7566209859118827e-22), np.float64(-1.3898933545360154e-22), np.float64(5.79122339077916e-23)],
|
|
22
|
+
[np.float64(8.686503590764639e-09), np.float64(-1.65473383773328e-08), np.float64(1.436297104024318e-08), np.float64(-1.1477650061935758e-08), np.float64(8.545735734449281e-09), np.float64(-5.996895398705995e-09), np.float64(4.006769217225344e-09), np.float64(-2.5709942873109855e-09), np.float64(1.5957903137197333e-09), np.float64(-9.638514964105788e-10), np.float64(5.693034083832903e-10), np.float64(-3.3017290333152663e-10), np.float64(1.8865033340673577e-10), np.float64(-1.0648549423310168e-10), np.float64(5.951496734516843e-11), np.float64(-3.299706105855277e-11), np.float64(1.8176169950047973e-11), np.float64(-9.959820041291788e-12), np.float64(5.434586636259126e-12), np.float64(-2.955348188377066e-12), np.float64(1.6027689647939799e-12), np.float64(-8.673418310650257e-13), np.float64(4.685520234722645e-13), np.float64(-2.52770908395652e-13), np.float64(1.3621383779622755e-13), np.float64(-7.333962383515107e-14), np.float64(3.946007898357147e-14), np.float64(-2.121981181620983e-14), np.float64(1.1406148867425603e-14), np.float64(-6.1290026846446705e-15), np.float64(3.292493998913348e-15), np.float64(-1.7683538979350812e-15), np.float64(9.49602414668502e-16), np.float64(-5.098685027437213e-16), np.float64(2.7373502339253325e-16), np.float64(-1.4694941187717948e-16), np.float64(7.888203458470995e-17), np.float64(-4.234157301715805e-17), np.float64(2.2726843116453342e-17), np.float64(-1.21982659739002e-17), np.float64(6.547066935972056e-18), np.float64(-3.513883743466329e-18), np.float64(1.8859130620734142e-18), np.float64(-1.0121642406073693e-18), np.float64(5.432208443677431e-19), np.float64(-2.915404497323382e-19), np.float64(1.5646558511988773e-19), np.float64(-8.397247820010338e-20), np.float64(4.506648114324224e-20), np.float64(-2.4186285811956072e-20), np.float64(1.2980272483168877e-20), np.float64(-6.966228485649673e-21), np.float64(3.73861718923897e-21), np.float64(-2.0064281031012134e-21), np.float64(1.0767998928777274e-21), np.float64(-5.778872839668759e-22), np.float64(3.1012775820143866e-22), np.float64(-1.6641856652296907e-22), np.float64(8.927647822442783e-23), np.float64(-4.7844845392442827e-23), np.float64(2.5551093650505325e-23), np.float64(-1.347775540767547e-23), np.float64(6.795509304866681e-24), np.float64(-2.8314628209420286e-24)],
|
|
23
|
+
[np.float64(-2.990345478876676e-10), np.float64(5.71233848719464e-10), np.float64(-4.995187719435948e-10), np.float64(4.033291211769605e-10), np.float64(-3.038540338668844e-10), np.float64(2.1581425812477414e-10), np.float64(-1.4588437413085387e-10), np.float64(9.462846621897066e-11), np.float64(-5.931417889974814e-11), np.float64(3.613911353904689e-11), np.float64(-2.1509025881667172e-11), np.float64(1.2556725207741481e-11), np.float64(-7.214967848464867e-12), np.float64(4.091987343575556e-12), np.float64(-2.2961768375541066e-12), np.float64(1.2773220937382121e-12), np.float64(-7.055445195435752e-13), np.float64(3.8748789857515953e-13), np.float64(-2.1182569107340982e-13), np.float64(1.1536560517811403e-13), np.float64(-6.264259666797539e-14), np.float64(3.3932639840954545e-14), np.float64(-1.8345503084699946e-14), np.float64(9.90318393977599e-15), np.float64(-5.339362356133946e-15), np.float64(2.8759572609812404e-15), np.float64(-1.5478941101289816e-15), np.float64(8.325982729921944e-16), np.float64(-4.476314988820801e-16), np.float64(2.405695638739485e-16), np.float64(-1.2924999605685865e-16), np.float64(6.942531210609342e-17), np.float64(-3.728416512376491e-17), np.float64(2.0020158802573773e-17), np.float64(-1.0748818108929984e-17), np.float64(5.770516821981004e-18), np.float64(-3.0976898450311078e-18), np.float64(1.6627884451454886e-18), np.float64(-8.925182660909434e-19), np.float64(4.790516771180387e-19), np.float64(-2.571200609613425e-19), np.float64(1.3800042488821573e-19), np.float64(-7.406580097419567e-20), np.float64(3.975112392023773e-20), np.float64(-2.1334216787945772e-20), np.float64(1.144986985810027e-20), np.float64(-6.144997325473445e-21), np.float64(3.297924673542651e-21), np.float64(-1.7699382273013215e-21), np.float64(9.498919083003859e-22), np.float64(-5.0978757394367295e-22), np.float64(2.7359205813718107e-22), np.float64(-1.4683075534683792e-22), np.float64(7.880065774295856e-23), np.float64(-4.22903622505459e-23), np.float64(2.2696017935564084e-23), np.float64(-1.2179999386546807e-23), np.float64(6.5359463822771706e-24), np.float64(-3.506257555217285e-24), np.float64(1.879065709443117e-24), np.float64(-1.0034976093571413e-24), np.float64(5.293274873249532e-25), np.float64(-2.6688791443824415e-25), np.float64(1.112033248388646e-25)],
|
|
24
|
+
[np.float64(8.590913565501381e-12), np.float64(-1.644747244344771e-11), np.float64(1.4469771653023546e-11), np.float64(-1.17844033378004e-11), np.float64(8.96677770680088e-12), np.float64(-6.435116137299384e-12), np.float64(4.394394784525721e-12), np.float64(-2.8778475636047527e-12), np.float64(1.8197393664590925e-12), np.float64(-1.1174802489107638e-12), np.float64(6.697195285079766e-13), np.float64(-3.9334057611250915e-13), np.float64(2.2718618553574766e-13), np.float64(-1.2942068908024125e-13), np.float64(7.289509240807865e-14), np.float64(-4.0677477416306326e-14), np.float64(2.252734993914674e-14), np.float64(-1.23987980370397e-14), np.float64(6.789986471957273e-15), np.float64(-3.703350837544549e-15), np.float64(2.0132562053050933e-15), np.float64(-1.091592054367329e-15), np.float64(5.90616535804845e-16), np.float64(-3.190204156187325e-16), np.float64(1.7208669323732956e-16), np.float64(-9.272809664110933e-17), np.float64(4.9923649294176413e-17), np.float64(-2.6860168721642793e-17), np.float64(1.444373823973649e-17), np.float64(-7.763677770407289e-18), np.float64(4.171679860813903e-18), np.float64(-2.2409934260347286e-18), np.float64(1.2035953798137423e-18), np.float64(-6.46323380469939e-19), np.float64(3.4702736500696527e-19), np.float64(-1.8630905515037655e-19), np.float64(1.0001610706674565e-19), np.float64(-5.3688223611849094e-20), np.float64(2.8818210992911103e-20), np.float64(-1.546815236298492e-20), np.float64(8.302270523196498e-21), np.float64(-4.4559995494906615e-21), np.float64(2.391582765028338e-21), np.float64(-1.2835696409529957e-21), np.float64(6.88887899681626e-22), np.float64(-3.697207587406423e-22), np.float64(1.9842487064595156e-22), np.float64(-1.0649176346859133e-22), np.float64(5.715234902318239e-23), np.float64(-3.067260793736177e-23), np.float64(1.6461377830941049e-23), np.float64(-8.834475186724073e-24), np.float64(4.74126861622721e-24), np.float64(-2.5445299877659388e-24), np.float64(1.3655867527694875e-24), np.float64(-7.328712422035599e-25), np.float64(3.9330129668053335e-25), np.float64(-2.1105063778619116e-25), np.float64(1.132197162729119e-25), np.float64(-6.067646371141272e-26), np.float64(3.240370522569741e-26), np.float64(-1.70923904495467e-26), np.float64(8.618015798273004e-27), np.float64(-3.5908408939843676e-27)],
|
|
25
|
+
[np.float64(-2.0917254877820944e-13), np.float64(4.0119923996513445e-13), np.float64(-3.54740772706991e-13), np.float64(2.9102066080556357e-13), np.float64(-2.233428263991212e-13), np.float64(1.6174167092080764e-13), np.float64(-1.114456861221764e-13), np.float64(7.361103948580295e-14), np.float64(-4.691539004850211e-14), np.float64(2.90168229731649e-14), np.float64(-1.750101775108679e-14), np.float64(1.033617173760745e-14), np.float64(-5.998883534475675e-15), np.float64(3.4315549237745648e-15), np.float64(-1.9396071153036413e-15), np.float64(1.0855680321354046e-15), np.float64(-6.026839976939976e-16), np.float64(3.3239382481927193e-16), np.float64(-1.823390285035146e-16), np.float64(9.958876368355027e-17), np.float64(-5.420107292565327e-17), np.float64(2.9415059140008093e-17), np.float64(-1.5927172971077508e-17), np.float64(8.608197174057999e-18), np.float64(-4.6456887603566085e-18), np.float64(2.504271314126552e-18), np.float64(-1.3486824394693845e-18), np.float64(7.258020503301345e-19), np.float64(-3.903671477306522e-19), np.float64(2.0985912561042288e-19), np.float64(-1.1277792203800966e-19), np.float64(6.058922050070497e-20), np.float64(-3.254379240454546e-20), np.float64(1.747686017900872e-20), np.float64(-9.384208597045561e-21), np.float64(5.038298888968273e-21), np.float64(-2.704783533930433e-21), np.float64(1.4519494695311658e-21), np.float64(-7.793764122411127e-22), np.float64(4.1833556023327908e-22), np.float64(-2.245370478042823e-22), np.float64(1.2051469884720668e-22), np.float64(-6.46819701844077e-23), np.float64(3.471519177019611e-23), np.float64(-1.8631614803556507e-23), np.float64(9.999474866371489e-24), np.float64(-5.366616649775894e-24), np.float64(2.8801914484827184e-24), np.float64(-1.5457530220275515e-24), np.float64(8.295780575244021e-25), np.float64(-4.4521845091616415e-25), np.float64(2.389395567778271e-25), np.float64(-1.2823368301292542e-25), np.float64(6.882010473777031e-26), np.float64(-3.693407342011202e-26), np.float64(1.982146347575685e-26), np.float64(-1.0637351514473825e-26), np.float64(5.708143427674616e-27), np.float64(-3.0621772765051276e-27), np.float64(1.6410755497614014e-27), np.float64(-8.764013176832831e-28), np.float64(4.622864684014418e-28), np.float64(-2.3308572781915197e-28), np.float64(9.711908241723077e-29)],
|
|
26
|
+
[np.float64(4.37271797638155e-15), np.float64(-8.399934282987266e-15), np.float64(7.45909871906253e-15), np.float64(-6.157789084734837e-15), np.float64(4.7612000842121434e-15), np.float64(-3.475643388042952e-15), np.float64(2.414102348741187e-15), np.float64(-1.6068661533418328e-15), np.float64(1.0315055309059747e-15), np.float64(-6.42171285654316e-16), np.float64(3.895945520715493e-16), np.float64(-2.3129129548980095e-16), np.float64(1.3484407147327527e-16), np.float64(-7.743627752648789e-17), np.float64(4.391496954891062e-17), np.float64(-2.4647880130848035e-17), np.float64(1.371639556438039e-17), np.float64(-7.579843507525494e-18), np.float64(4.164823640259028e-18), np.float64(-2.277778148928511e-18), np.float64(1.2410434616395257e-18), np.float64(-6.741212742092268e-19), np.float64(3.6527706331932163e-19), np.float64(-1.9753789693479664e-19), np.float64(1.0665787658002077e-19), np.float64(-5.75159268878208e-20), np.float64(3.0984706010117974e-20), np.float64(-1.6678622190725495e-20), np.float64(8.972183261562506e-21), np.float64(-4.824124150843235e-21), np.float64(2.5927864673295993e-21), np.float64(-1.3930899717983376e-21), np.float64(7.483149694945755e-22), np.float64(-4.0188822720625393e-22), np.float64(2.158040983778784e-22), np.float64(-1.1586755136645104e-22), np.float64(6.220465573985535e-23), np.float64(-3.3392711305857547e-23), np.float64(1.7924833798266255e-23), np.float64(-9.621409665660362e-24), np.float64(5.164243060744281e-24), np.float64(-2.7718032931355025e-24), np.float64(1.4876766405790612e-24), np.float64(-7.984489605732115e-25), np.float64(4.285286679165083e-25), np.float64(-2.2998948576335345e-25), np.float64(1.2343333515634984e-25), np.float64(-6.624515326989634e-26), np.float64(3.555277731678655e-26), np.float64(-1.90805642789767e-26), np.float64(1.0240178491260118e-26), np.float64(-5.495696628632166e-27), np.float64(2.9494230325443997e-27), np.float64(-1.5828890689717295e-27), np.float64(8.494983015680867e-28), np.float64(-4.55901630506514e-28), np.float64(2.44663416188043e-28), np.float64(-1.312896457363867e-28), np.float64(7.043134587327039e-29), np.float64(-3.7745421439485837e-29), np.float64(2.0157597128585743e-29), np.float64(-1.0632782926923721e-29), np.float64(5.361069872887366e-30), np.float64(-2.2337798461361527e-30)],
|
|
27
|
+
[np.float64(-7.935632040439955e-17), np.float64(1.526435903155495e-16), np.float64(-1.3604843303401677e-16), np.float64(1.1293000975009147e-16), np.float64(-8.789449844174412e-17), np.float64(6.462084903445617e-17), np.float64(-4.5208992116843394e-17), np.float64(3.030302158471025e-17), np.float64(-1.9580938562461715e-17), np.float64(1.2264115230578804e-17), np.float64(-7.481079654960666e-18), np.float64(4.462853130372727e-18), np.float64(-2.6129341200320116e-18), np.float64(1.5060501134781304e-18), np.float64(-8.568002493182415e-19), np.float64(4.821849247014204e-19), np.float64(-2.6894191263237196e-19), np.float64(1.4890276489917927e-19), np.float64(-8.194530070723535e-20), np.float64(4.487499939979815e-20), np.float64(-2.4476218068321635e-20), np.float64(1.3306824079081323e-20), np.float64(-7.215504984579717e-21), np.float64(3.904305646239164e-21), np.float64(-2.1090502616211055e-21), np.float64(1.137740269070055e-21), np.float64(-6.130998292528465e-22), np.float64(3.3010092311470984e-22), np.float64(-1.7760961115210712e-22), np.float64(9.551063126678094e-23), np.float64(-5.133947530771461e-23), np.float64(2.758700335617055e-23), np.float64(-1.4819786004566229e-23), np.float64(7.959543050764641e-24), np.float64(-4.2742755593561686e-24), np.float64(2.294987822029945e-24), np.float64(-1.2321223007102458e-24), np.float64(6.614428622328464e-25), np.float64(-3.550613729748472e-25), np.float64(1.9058687774991901e-25), np.float64(-1.0229765323901798e-25), np.float64(5.490666882937583e-26), np.float64(-2.94695924674207e-26), np.float64(1.5816668683248306e-26), np.float64(-8.488862888137602e-27), np.float64(4.555950698189287e-27), np.float64(-2.445144845065232e-27), np.float64(1.3122817625196163e-27), np.float64(-7.042829715656596e-28), np.float64(3.779770188395352e-28), np.float64(-2.028533199098862e-28), np.float64(1.0886735377813066e-28), np.float64(-5.84268181556023e-29), np.float64(3.135637476121578e-29), np.float64(-1.6828214390558695e-29), np.float64(9.031227618805109e-30), np.float64(-4.846684761072936e-30), np.float64(2.6007960005002855e-30), np.float64(-1.3952173165083745e-30), np.float64(7.477220613917413e-31), np.float64(-3.993141612107969e-31), np.float64(2.1063130844374033e-31), np.float64(-1.0620072092601593e-31), np.float64(4.4250316110806344e-32)],
|
|
28
|
+
[np.float64(1.2622270804228821e-18), np.float64(-2.4307027824061497e-18), np.float64(2.1734483110712334e-18), np.float64(-1.8128503773390334e-18), np.float64(1.4192597872602558e-18), np.float64(-1.0501528845020997e-18), np.float64(7.395107712452798e-19), np.float64(-4.988634930502404e-19), np.float64(3.2430882944998793e-19), np.float64(-2.0426470611144622e-19), np.float64(1.252357502373818e-19), np.float64(-7.504961490056292e-20), np.float64(4.411668061171623e-20), np.float64(-2.55169521852711e-20), np.float64(1.456047426702165e-20), np.float64(-8.215343943826839e-21), np.float64(4.592148640352777e-21), np.float64(-2.5471497203161706e-21), np.float64(1.4039066059953617e-21), np.float64(-7.697813883936654e-22), np.float64(4.2029968575875798e-22), np.float64(-2.286962300240691e-22), np.float64(1.2409448906147024e-22), np.float64(-6.718520942901782e-23), np.float64(3.630895916699866e-23), np.float64(-1.9594238226153695e-23), np.float64(1.056193158148494e-23), np.float64(-5.688008800706701e-24), np.float64(3.060981721387274e-24), np.float64(-1.6463045014635582e-24), np.float64(8.850356705033623e-25), np.float64(-4.756134975883518e-25), np.float64(2.555191327582551e-25), np.float64(-1.3724444245837776e-25), np.float64(7.370364524772181e-26), np.float64(-3.957513864611427e-26), np.float64(2.12475157834543e-26), np.float64(-1.1406603212146765e-26), np.float64(6.123151676067352e-27), np.float64(-3.286779312970819e-27), np.float64(1.7642003301825313e-27), np.float64(-9.469149981283258e-28), np.float64(5.082330567182625e-28), np.float64(-2.727759360910647e-28), np.float64(1.464004214060611e-28), np.float64(-7.857297758888237e-29), np.float64(4.216963812097017e-29), np.float64(-2.2632015334803788e-29), np.float64(1.2146299654247699e-29), np.float64(-6.51872592157271e-30), np.float64(3.4984837079398576e-30), np.float64(-1.877568211140763e-30), np.float64(1.007651937301147e-30), np.float64(-5.4078464471594105e-31), np.float64(2.9022625353042113e-31), np.float64(-1.5575628075938452e-31), np.float64(8.358794491813536e-32), np.float64(-4.485441917511448e-32), np.float64(2.4062506512830572e-32), np.float64(-1.289553149349858e-32), np.float64(6.886741776959089e-33), np.float64(-3.632637310533064e-33), np.float64(1.831582974032926e-33), np.float64(-7.631598644530059e-34)],
|
|
29
|
+
[np.float64(-1.7743158467838407e-20), np.float64(3.420286330609023e-20), np.float64(-3.067038856198645e-20), np.float64(2.5692067946168564e-20), np.float64(-2.0220258761728095e-20), np.float64(1.5048535999612423e-20), np.float64(-1.0660505956208897e-20), np.float64(7.233807472613522e-21), np.float64(-4.729087457809713e-21), np.float64(2.9941690271643058e-21), np.float64(-1.844497586884073e-21), np.float64(1.1100811575400281e-21), np.float64(-6.55019261284426e-22), np.float64(3.8011959234326146e-22), np.float64(-2.1752764753389963e-22), np.float64(1.230367272016543e-22), np.float64(-6.891832160315404e-23), np.float64(3.829484382625652e-23), np.float64(-2.1138098977440058e-23), np.float64(1.1604554503665097e-23), np.float64(-6.342499632918669e-24), np.float64(3.453995333182322e-24), np.float64(-1.8754702535932605e-24), np.float64(1.0159466678814138e-24), np.float64(-5.492938351871759e-25), np.float64(2.9653454173023227e-25), np.float64(-1.598878323093271e-25), np.float64(8.612563371224175e-26), np.float64(-4.635672504787648e-26), np.float64(2.4935937048847458e-26), np.float64(-1.3406849096620568e-26), np.float64(7.205432637858599e-27), np.float64(-3.871336388707621e-27), np.float64(2.079491760995103e-27), np.float64(-1.1167888926000866e-27), np.float64(5.996806978826498e-28), np.float64(-3.219719164551738e-28), np.float64(1.7285254083244931e-28), np.float64(-9.279017573101752e-29), np.float64(4.980849881429162e-29), np.float64(-2.673532458943502e-29), np.float64(1.435001021642128e-29), np.float64(-7.702061635916391e-30), np.float64(4.133827812150164e-30), np.float64(-2.2186582805402808e-30), np.float64(1.1907557380407787e-30), np.float64(-6.390729393609863e-31), np.float64(3.4298460842736933e-31), np.float64(-1.8407552954236103e-31), np.float64(9.879052872286356e-32), np.float64(-5.301916111511764e-32), np.float64(2.845437425198371e-32), np.float64(-1.5270881608348352e-32), np.float64(8.19555017661304e-33), np.float64(-4.3983583620869714e-33), np.float64(2.3604760813140595e-33), np.float64(-1.2667700234169104e-33), np.float64(6.797660034629898e-34), np.float64(-3.6466587595951325e-34), np.float64(1.954310443866262e-34), np.float64(-1.0436818717017954e-34), np.float64(5.505241903922718e-35), np.float64(-2.775754065542364e-35), np.float64(1.1565646663364855e-35)],
|
|
30
|
+
[np.float64(2.220440354026113e-22), np.float64(-4.284093072889805e-22), np.float64(3.851422684995113e-22), np.float64(-3.2387495080890593e-22), np.float64(2.561145353060588e-22), np.float64(-1.916175294174983e-22), np.float64(1.3648882435598838e-22), np.float64(-9.31201457290597e-23), np.float64(6.11949815706122e-23), np.float64(-3.8934227043195247e-23), np.float64(2.4092156866684253e-23), np.float64(-1.4558134456978065e-23), np.float64(8.621164942549044e-24), np.float64(-5.018855765374548e-24), np.float64(2.8800015254792378e-24), np.float64(-1.6328301077394272e-24), np.float64(9.164695111930425e-25), np.float64(-5.101121673996131e-25), np.float64(2.8197733021376777e-25), np.float64(-1.549871939205536e-25), np.float64(8.479250515568508e-26), np.float64(-4.621385971161094e-26), np.float64(2.511018036644936e-26), np.float64(-1.3609616391133093e-26), np.float64(7.361567773875064e-27), np.float64(-3.975526311966163e-27), np.float64(2.144165518514979e-27), np.float64(-1.1552454554825247e-27), np.float64(6.219186607929203e-28), np.float64(-3.3458729584644458e-28), np.float64(1.7991213532983867e-28), np.float64(-9.670154852761602e-29), np.float64(5.195958101478797e-29), np.float64(-2.791172768548237e-29), np.float64(1.4990639500004403e-29), np.float64(-8.04979020509953e-30), np.float64(4.3220981459020486e-30), np.float64(-2.3203951635173078e-30), np.float64(1.2456490199337413e-30), np.float64(-6.686564627154231e-31), np.float64(3.5891341286459296e-31), np.float64(-1.9264603489051031e-31), np.float64(1.033993259885907e-31), np.float64(-5.549646740396038e-32), np.float64(2.978551603045632e-32), np.float64(-1.5985961789610935e-32), np.float64(8.579610942948494e-33), np.float64(-4.604607777055709e-33), np.float64(2.471238902634209e-33), np.float64(-1.3262778062255814e-33), np.float64(7.117909317734511e-34), np.float64(-3.820049205903705e-34), np.float64(2.050143576475669e-34), np.float64(-1.1002679831327113e-34), np.float64(5.904880647227472e-35), np.float64(-3.1689854089648865e-35), np.float64(1.7006639764667074e-35), np.float64(-9.125995109166033e-36), np.float64(4.895713300396078e-36), np.float64(-2.623701693228091e-36), np.float64(1.401164344231653e-36), np.float64(-7.390900500592235e-37), np.float64(3.726507600783862e-37), np.float64(-1.5527126046793397e-37)],
|
|
31
|
+
[np.float64(-2.4898866187092057e-24), np.float64(4.8078089519029016e-24), np.float64(-4.332150486133127e-24), np.float64(3.65574346440805e-24), np.float64(-2.9034615224020295e-24), np.float64(2.182823558967432e-24), np.float64(-1.562693507608604e-24), np.float64(1.0715381851569129e-24), np.float64(-7.076039827310665e-25), np.float64(4.5226363517836645e-25), np.float64(-2.8103917274529997e-25), np.float64(1.7047376034719912e-25), np.float64(-1.0129839068486468e-25), np.float64(5.914967115488602e-26), np.float64(-3.403180832568896e-26), np.float64(1.9338491746287164e-26), np.float64(-1.0875434331469607e-26), np.float64(6.06335712371769e-27), np.float64(-3.356347359375836e-27), np.float64(1.8469464035866093e-27), np.float64(-1.0114296404842306e-27), np.float64(5.516918469830958e-28), np.float64(-2.9995623642257626e-28), np.float64(1.6266170131891608e-28), np.float64(-8.802326616416963e-29), np.float64(4.7552512369222433e-29), np.float64(-2.565424220893397e-29), np.float64(1.3825250728054222e-29), np.float64(-7.444071940258095e-30), np.float64(4.005426574840928e-30), np.float64(-2.154018195146306e-30), np.float64(1.1578750028117504e-30), np.float64(-6.2219289181967085e-31), np.float64(3.3424949321824504e-31), np.float64(-1.7952446748169191e-31), np.float64(9.640584942587675e-32), np.float64(-5.176372597785765e-32), np.float64(2.779088420559582e-32), np.float64(-1.4919132844162697e-32), np.float64(8.008603879573938e-33), np.float64(-4.2988082200352053e-33), np.float64(2.3073957061311328e-33), np.float64(-1.2384616323885246e-33), np.float64(6.647103155689095e-34), np.float64(-3.567581945605956e-34), np.float64(1.9147362996352241e-34), np.float64(-1.0276349561617865e-34), np.float64(5.515244367145052e-35), np.float64(-2.959971377052536e-35), np.float64(1.5885752561170446e-35), np.float64(-8.525623372734316e-36), np.float64(4.575546536917628e-36), np.float64(-2.455605447224785e-36), np.float64(1.3178709986548752e-36), np.float64(-7.072706883203856e-37), np.float64(3.795725240388029e-37), np.float64(-2.037010716031168e-37), np.float64(1.0930858307220684e-37), np.float64(-5.863957669383695e-38), np.float64(3.142609810917475e-38), np.float64(-1.6782704020285772e-38), np.float64(8.852602731892978e-39), np.float64(-4.463537253521267e-39), np.float64(1.8599737513253373e-39)],
|
|
32
|
+
[np.float64(2.5163348323717328e-26), np.float64(-4.8623931866788436e-26), np.float64(4.3904251071448363e-26), np.float64(-3.716707706785965e-26), np.float64(2.963622267839849e-26), np.float64(-2.2380029530254343e-26), np.float64(1.6097092886374927e-26), np.float64(-1.1089670551578083e-26), np.float64(7.356603890555823e-27), np.float64(-4.7222306209254274e-27), np.float64(2.9461395954783243e-27), np.float64(-1.7935796996388216e-27), np.float64(1.0692547496595266e-27), np.float64(-6.261605370480257e-28), np.float64(3.611752054234792e-28), np.float64(-2.0568805287010388e-28), np.float64(1.158916493469814e-28), np.float64(-6.471664394171452e-29), np.float64(3.587224035123187e-29), np.float64(-1.976237799078799e-29), np.float64(1.0832557065197134e-29), np.float64(-5.913315630573359e-30), np.float64(3.21714790324172e-30), np.float64(-1.745524998526197e-30), np.float64(9.449814152858455e-31), np.float64(-5.106801339904001e-31), np.float64(2.7558483902201826e-31), np.float64(-1.485477219675856e-31), np.float64(7.999835182529335e-32), np.float64(-4.305078608663631e-32), np.float64(2.3154258960950717e-32), np.float64(-1.2447503836543606e-32), np.float64(6.689237237154279e-33), np.float64(-3.593741255413533e-33), np.float64(1.9302743660938274e-33), np.float64(-1.036606780500056e-33), np.float64(5.566064278029638e-34), np.float64(-2.9883710557114616e-34), np.float64(1.6042911476089225e-34), np.float64(-8.61196531537633e-35), np.float64(4.622725790058559e-35), np.float64(-2.481279870752339e-35), np.float64(1.3318001576209487e-35), np.float64(-7.148108632172917e-36), np.float64(3.836493318193483e-36), np.float64(-2.0590686689564007e-36), np.float64(1.1051004476947904e-36), np.float64(-5.9310066388082915e-37), np.float64(3.1831106179568515e-37), np.float64(-1.7083313664471296e-37), np.float64(9.168343723499573e-38), np.float64(-4.920494899718123e-38), np.float64(2.6407519989862766e-38), np.float64(-1.4172014183588892e-38), np.float64(7.605844552351107e-39), np.float64(-4.08212800537476e-39), np.float64(2.190548320342365e-39), np.float64(-1.1751134515718221e-39), np.float64(6.307162859069174e-40), np.float64(-3.3805552042081823e-40), np.float64(1.8030515185447593e-40), np.float64(-9.528394975537816e-41), np.float64(4.800178908179549e-41), np.float64(-2.0040578395599972e-41)],
|
|
33
|
+
[np.float64(-2.3039162295045917e-28), np.float64(4.4548561644608075e-28), np.float64(-4.030049705379764e-28), np.float64(3.4215655521745766e-28), np.float64(-2.7382642454279363e-28), np.float64(2.076362509824024e-28), np.float64(-1.4999584410160358e-28), np.float64(1.037898196734664e-28), np.float64(-6.914640167853199e-29), np.float64(4.4565873095634185e-29), np.float64(-2.790929814325887e-29), np.float64(1.7049693207752094e-29), np.float64(-1.0195985884832378e-29), np.float64(5.987378150281066e-30), np.float64(-3.461997694829631e-30), np.float64(1.975778889663319e-30), np.float64(-1.1152557651433727e-30), np.float64(6.237570417798332e-31), np.float64(-3.4620335847158534e-31), np.float64(1.9093852489370272e-31), np.float64(-1.0475793881504456e-31), np.float64(5.722946130679766e-32), np.float64(-3.1155407180938453e-32), np.float64(1.6912685466472032e-32), np.float64(-9.159931384329944e-33), np.float64(4.951830438319712e-33), np.float64(-2.672953591751783e-33), np.float64(1.4411128189620413e-33), np.float64(-7.762289489882217e-34), np.float64(4.177834420086499e-34), np.float64(-2.2472421954047727e-34), np.float64(1.2082034851385438e-34), np.float64(-6.493295949833683e-35), np.float64(3.4886690385243327e-35), np.float64(-1.873920920177088e-35), np.float64(1.0063787551275328e-35), np.float64(-5.403903647619717e-36), np.float64(2.901371368500479e-36), np.float64(-1.5576127438409848e-36), np.float64(8.361503811564656e-37), np.float64(-4.488331844034851e-37), np.float64(2.4091647313040135e-37), np.float64(-1.2930981350969868e-37), np.float64(6.940444894140826e-38), np.float64(-3.725045666430735e-38), np.float64(1.9992478203269394e-38), np.float64(-1.073024512134337e-38), np.float64(5.758675031092922e-39), np.float64(-3.090445049083221e-39), np.float64(1.6585738209074663e-39), np.float64(-8.90286473679398e-40), np.float64(4.7779769345748295e-40), np.float64(-2.5643084276302838e-40), np.float64(1.375994719647321e-40), np.float64(-7.356505010928658e-41), np.float64(3.9721636986774256e-41), np.float64(-2.1530281969161777e-41), np.float64(1.1008561858716536e-41), np.float64(-6.179567286233701e-42), np.float64(3.571850271765166e-42), np.float64(-1.558318033583675e-42), np.float64(1.000851064156167e-42), np.float64(-4.520424498600341e-43), np.float64(1.198442877609194e-43)],
|
|
34
|
+
[np.float64(1.920071671140516e-30), np.float64(-3.714884153679332e-30), np.float64(3.3664601000125984e-30), np.float64(-2.865822195887202e-30), np.float64(2.3012581716345456e-30), np.float64(-1.7516827745379046e-30), np.float64(1.2705583369755341e-30), np.float64(-8.827867076543274e-31), np.float64(5.904986611092253e-31), np.float64(-3.82049389949628e-31), np.float64(2.4011763424403077e-31), np.float64(-1.471709886000766e-31), np.float64(8.827319049249059e-32), np.float64(-5.197463829196592e-32), np.float64(3.012317607943603e-32), np.float64(-1.7226692503047024e-32), np.float64(9.741072742151314e-33), np.float64(-5.4563973803200004e-33), np.float64(3.03235858165363e-33), np.float64(-1.6742232101681503e-33), np.float64(9.19390484807342e-34), np.float64(-5.026424267808094e-34), np.float64(2.7380547827168267e-34), np.float64(-1.4871062671314106e-34), np.float64(8.057524879204305e-35), np.float64(-4.3573383028597396e-35), np.float64(2.3526913168898699e-35), np.float64(-1.268722027041269e-35), np.float64(6.834936950164844e-36), np.float64(-3.6792285111791394e-36), np.float64(1.979264805658882e-36), np.float64(-1.0642234356083949e-36), np.float64(5.719901052264712e-37), np.float64(-3.073318189805369e-37), np.float64(1.650887675428633e-37), np.float64(-8.866298557329596e-38), np.float64(4.76101757897262e-38), np.float64(-2.556266925647616e-38), np.float64(1.3723820867023308e-38), np.float64(-7.367372155594241e-39), np.float64(3.9546502270123034e-39), np.float64(-2.1227462209521985e-39), np.float64(1.1392299716664255e-39), np.float64(-6.116415690807875e-40), np.float64(3.2827483513720865e-40), np.float64(-1.7599101332831905e-40), np.float64(9.46737559726821e-41), np.float64(-5.097930060255915e-41), np.float64(2.6870630131937604e-41), np.float64(-1.4657705287218863e-41), np.float64(7.781199041280875e-42), np.float64(-4.220087252625221e-42), np.float64(2.2258027364840935e-42), np.float64(-1.2089872594585966e-42), np.float64(4.1227309829771716e-43), np.float64(-5.098067461249564e-43), np.float64(3.019808402126974e-43), np.float64(-6.196751855064298e-44), np.float64(1.0530840159013826e-43), np.float64(2.4971742363649453e-43), np.float64(2.003855188771927e-43), np.float64(-4.445263964441535e-43), np.float64(5.829179837909701e-44), np.float64(1.1222931918135973e-43)],
|
|
35
|
+
[np.float64(-1.4627704846251397e-32), np.float64(2.831676774997611e-32), np.float64(-2.5701812726138254e-32), np.float64(2.1933727161899244e-32), np.float64(-1.766803795592527e-32), np.float64(1.3496703017019418e-32), np.float64(-9.826922272076901e-33), np.float64(6.854217219548874e-33), np.float64(-4.60226905291296e-33), np.float64(2.9885042750040527e-33), np.float64(-1.8846961305046318e-33), np.float64(1.1587932378186544e-33), np.float64(-6.970322664187511e-34), np.float64(4.114589189819142e-34), np.float64(-2.3901161533769367e-34), np.float64(1.3695594917721695e-34), np.float64(-7.757677776863584e-35), np.float64(4.3518243180931164e-35), np.float64(-2.421536000168178e-35), np.float64(1.338393335375388e-35), np.float64(-7.356237510951628e-36), np.float64(4.02471759687906e-36), np.float64(-2.1937302646306843e-36), np.float64(1.1920669287243695e-36), np.float64(-6.461569077052656e-37), np.float64(3.495440091905975e-37), np.float64(-1.887826797532628e-37), np.float64(1.0182575970772986e-37), np.float64(-5.486596736880453e-38), np.float64(2.953838383821007e-38), np.float64(-1.589196899020225e-38), np.float64(8.545715757295949e-39), np.float64(-4.593447372770047e-39), np.float64(2.468132891446256e-39), np.float64(-1.3259269423320973e-39), np.float64(7.1166932841988e-40), np.float64(-3.822231078783727e-40), np.float64(2.0506004345985726e-40), np.float64(-1.1038901551459538e-40), np.float64(5.922642819344176e-41), np.float64(-3.1987884348747365e-41), np.float64(1.6698296325729472e-41), np.float64(-9.385130509196511e-42), np.float64(4.7860700150506506e-42), np.float64(-2.7614277963080914e-42), np.float64(1.1631454570568529e-42), np.float64(-9.956131908903346e-43), np.float64(3.1623367533503366e-43), np.float64(-1.2823022466266157e-43), np.float64(1.4540240986950343e-45), np.float64(-2.837709307569982e-44), np.float64(-2.7656852637152316e-43), np.float64(-2.6375410159495027e-43), np.float64(1.3407590695180913e-43), np.float64(-1.2338716201634958e-43), np.float64(-4.2403972505012315e-43), np.float64(-1.1432552786600802e-43), np.float64(-6.907165113413791e-44), np.float64(-1.2021626549206828e-43), np.float64(-1.6964271961843138e-43), np.float64(-3.27313112068647e-44), np.float64(6.972267482373026e-44), np.float64(-1.343471406468362e-44), np.float64(-2.0382270102184443e-43)],
|
|
36
|
+
[np.float64(1.0226308004562628e-34), np.float64(-1.9806502199303824e-34), np.float64(1.8003942745282216e-34), np.float64(-1.5399672329708754e-34), np.float64(1.244094828150271e-34), np.float64(-9.535454116736428e-35), np.float64(6.967565428706013e-35), np.float64(-4.877580825416555e-35), np.float64(3.286860684746725e-35), np.float64(-2.1417339271005783e-35), np.float64(1.355086241917144e-35), np.float64(-8.356779575965551e-36), np.float64(5.0405329755787365e-36), np.float64(-2.9827705529031454e-36), np.float64(1.7364486886105617e-36), np.float64(-9.969137747781492e-37), np.float64(5.656303511608179e-37), np.float64(-3.1775766550090603e-37), np.float64(1.7703044451577096e-37), np.float64(-9.794677254406567e-38), np.float64(5.388164740161099e-38), np.float64(-2.950078704549593e-38), np.float64(1.6089705901551178e-38), np.float64(-8.747400018636538e-39), np.float64(4.7433728224101326e-39), np.float64(-2.5668390473469682e-39), np.float64(1.3864892062971537e-39), np.float64(-7.483486835523648e-40), np.float64(4.029147514162724e-40), np.float64(-2.1717401993838258e-40), np.float64(1.1681334793301566e-40), np.float64(-6.280591519546902e-41), np.float64(3.3879801069938614e-41), np.float64(-1.8008639537847828e-41), np.float64(9.918608260676095e-42), np.float64(-4.911377393016602e-42), np.float64(2.744808562754028e-42), np.float64(-1.4281305294140673e-42), np.float64(9.44599572346965e-43), np.float64(-5.733291211029036e-43), np.float64(3.1732384496461817e-43), np.float64(-4.754497253427022e-44), np.float64(2.4494264735431823e-43), np.float64(-9.338872255746089e-44), np.float64(1.2840626134721953e-43), np.float64(2.618437056294341e-43), np.float64(1.2175329192450237e-43), np.float64(-7.928885810552037e-44), np.float64(2.279641714986866e-44), np.float64(9.051965735610348e-44), np.float64(5.041747598734484e-44), np.float64(-6.578704878574725e-44), np.float64(1.7788972623692624e-44), np.float64(-1.9907179201441002e-44), np.float64(1.0471345915891166e-44), np.float64(1.4263283064039205e-43), np.float64(2.8347486435717912e-43), np.float64(1.4771379269524987e-43), np.float64(-8.339188567067874e-44), np.float64(-7.774719623048242e-44), np.float64(-1.9764544187863247e-43), np.float64(-1.6055891608010742e-43), np.float64(-1.0288461140146938e-44), np.float64(1.5741197673474639e-43)],
|
|
37
|
+
])
|
chebax/_src/series.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""Runtime evaluation in jax: single and segmented Chebyshev series.
|
|
2
|
+
|
|
3
|
+
Only two algorithms run per call: Clenshaw, and (for gradients) one more
|
|
4
|
+
Clenshaw on the derivative coefficients. Differentiation and integration act
|
|
5
|
+
on coefficients through matrices built from the numpy references in
|
|
6
|
+
algorithms.py, so they work on traced values and agree with the references
|
|
7
|
+
exactly. Gradients come from a custom_jvp bound to the derivative series:
|
|
8
|
+
jax.grad(p)(x) and p.deriv()(x) are the same computation.
|
|
9
|
+
|
|
10
|
+
Series are pytrees: coefficients are leaves, domains and breakpoints are
|
|
11
|
+
static. Full float64 accuracy needs jax's x64 mode.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import functools
|
|
15
|
+
|
|
16
|
+
import jax
|
|
17
|
+
import jax.numpy as jnp
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
from chebax._src import algorithms
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@functools.lru_cache(maxsize=None)
|
|
24
|
+
def _der_matrix(n):
|
|
25
|
+
"""chebder as an (n-1, n) matrix (n=1: zero map), for traced coefficients."""
|
|
26
|
+
if n == 1:
|
|
27
|
+
return np.zeros((1, 1))
|
|
28
|
+
return np.array([algorithms.chebder(e) for e in np.eye(n)]).T
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@functools.lru_cache(maxsize=None)
|
|
32
|
+
def _int_matrix(n):
|
|
33
|
+
"""chebint as an (n+1, n) matrix, for traced coefficients."""
|
|
34
|
+
return np.array([algorithms.chebint(e) for e in np.eye(n)]).T
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _clenshaw(t, coef, coef_last_axis=False):
|
|
38
|
+
"""Clenshaw with static degree. coef_last_axis: per-element coefficient
|
|
39
|
+
vectors of shape t.shape + (n,), used by the segmented series."""
|
|
40
|
+
n = coef.shape[-1] if coef_last_axis else coef.shape[0]
|
|
41
|
+
ck = (lambda k: coef[..., k]) if coef_last_axis else (lambda k: coef[k])
|
|
42
|
+
b1 = jnp.zeros(jnp.shape(t), jnp.result_type(t, coef))
|
|
43
|
+
b2 = b1
|
|
44
|
+
two_t = 2 * t
|
|
45
|
+
for k in range(n - 1, 0, -1):
|
|
46
|
+
b1, b2 = two_t * b1 - b2 + ck(k), b1
|
|
47
|
+
return t * b1 - b2 + ck(0)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _dcoef(coef, domain):
|
|
51
|
+
a, b = domain
|
|
52
|
+
d = jnp.asarray(_der_matrix(coef.shape[0]), dtype=coef.dtype)
|
|
53
|
+
return (2.0 / (b - a)) * (d @ coef)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _chebval_impl(x, coef, domain):
|
|
57
|
+
a, b = domain
|
|
58
|
+
t = (2 * x - (b + a)) / (b - a)
|
|
59
|
+
return _clenshaw(t, coef)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# The jvp rule calls the plain impl so the tangent computation is made of
|
|
63
|
+
# ordinary transposable primitives (reverse mode works), and so the value
|
|
64
|
+
# path and the deriv() path are literally the same ops.
|
|
65
|
+
_chebval = jax.custom_jvp(_chebval_impl, nondiff_argnums=(2,))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@_chebval.defjvp
|
|
69
|
+
def _chebval_jvp(domain, primals, tangents):
|
|
70
|
+
x, coef = primals
|
|
71
|
+
xdot, cdot = tangents
|
|
72
|
+
y = _chebval_impl(x, coef, domain)
|
|
73
|
+
dy = _chebval_impl(x, _dcoef(coef, domain), domain) * xdot + _chebval_impl(x, cdot, domain)
|
|
74
|
+
return y, dy
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
@jax.tree_util.register_pytree_node_class
|
|
78
|
+
class ChebSeries:
|
|
79
|
+
"""sum(c[k] T_k(t)), t the affine image of x taking [a, b] to [-1, 1].
|
|
80
|
+
|
|
81
|
+
Plain-c0, lowest-first coefficients (the numpy.polynomial convention).
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
def __init__(self, coef, domain=(-1.0, 1.0)):
|
|
85
|
+
self.coef = jnp.asarray(coef)
|
|
86
|
+
self.domain = (float(domain[0]), float(domain[1]))
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def degree(self):
|
|
90
|
+
return self.coef.shape[0] - 1
|
|
91
|
+
|
|
92
|
+
def __call__(self, x):
|
|
93
|
+
return _chebval(jnp.asarray(x), self.coef, self.domain)
|
|
94
|
+
|
|
95
|
+
def deriv(self):
|
|
96
|
+
return ChebSeries(_dcoef(self.coef, self.domain), self.domain)
|
|
97
|
+
|
|
98
|
+
def integ(self):
|
|
99
|
+
"""Antiderivative vanishing at the domain midpoint."""
|
|
100
|
+
a, b = self.domain
|
|
101
|
+
m = jnp.asarray(_int_matrix(self.coef.shape[0]), dtype=self.coef.dtype)
|
|
102
|
+
return ChebSeries(((b - a) / 2.0) * (m @ self.coef), self.domain)
|
|
103
|
+
|
|
104
|
+
def astype(self, dtype):
|
|
105
|
+
"""Round the coefficients; error floor grows to ~eps(dtype)*sum|c|."""
|
|
106
|
+
return ChebSeries(self.coef.astype(dtype), self.domain)
|
|
107
|
+
|
|
108
|
+
def __repr__(self):
|
|
109
|
+
return f"ChebSeries(degree={self.degree}, domain={self.domain}, dtype={self.coef.dtype})"
|
|
110
|
+
|
|
111
|
+
def tree_flatten(self):
|
|
112
|
+
return (self.coef,), self.domain
|
|
113
|
+
|
|
114
|
+
@classmethod
|
|
115
|
+
def tree_unflatten(cls, domain, children):
|
|
116
|
+
obj = object.__new__(cls)
|
|
117
|
+
obj.coef = children[0]
|
|
118
|
+
obj.domain = domain
|
|
119
|
+
return obj
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _pw_dcoef(coef, breaks):
|
|
123
|
+
d = jnp.asarray(_der_matrix(coef.shape[1]), dtype=coef.dtype)
|
|
124
|
+
widths = np.diff(np.asarray(breaks))
|
|
125
|
+
return (coef @ d.T) * jnp.asarray(2.0 / widths, dtype=coef.dtype)[:, None]
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _pw_chebval_impl(x, coef, breaks):
|
|
129
|
+
dtype = jnp.result_type(x, coef)
|
|
130
|
+
br = np.asarray(breaks)
|
|
131
|
+
idx = jnp.clip(jnp.searchsorted(jnp.asarray(br), x, side="right") - 1, 0, len(breaks) - 2)
|
|
132
|
+
a = jnp.asarray(br[:-1], dtype)[idx]
|
|
133
|
+
b = jnp.asarray(br[1:], dtype)[idx]
|
|
134
|
+
t = (2 * x.astype(dtype) - (b + a)) / (b - a)
|
|
135
|
+
return _clenshaw(t, coef[idx], coef_last_axis=True)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
_pw_chebval = jax.custom_jvp(_pw_chebval_impl, nondiff_argnums=(2,))
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@_pw_chebval.defjvp
|
|
142
|
+
def _pw_chebval_jvp(breaks, primals, tangents):
|
|
143
|
+
x, coef = primals
|
|
144
|
+
xdot, cdot = tangents
|
|
145
|
+
y = _pw_chebval_impl(x, coef, breaks)
|
|
146
|
+
dy = (_pw_chebval_impl(x, _pw_dcoef(coef, breaks), breaks) * xdot
|
|
147
|
+
+ _pw_chebval_impl(x, cdot, breaks))
|
|
148
|
+
return y, dy
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@jax.tree_util.register_pytree_node_class
|
|
152
|
+
class PiecewiseCheb:
|
|
153
|
+
"""Segmented series: row i of coef is a ChebSeries on [breaks[i], breaks[i+1]],
|
|
154
|
+
all padded to one degree, evaluated by gather + one Clenshaw (no branches).
|
|
155
|
+
x outside [breaks[0], breaks[-1]] uses the nearest end segment's polynomial.
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
def __init__(self, coef, breaks):
|
|
159
|
+
self.coef = jnp.asarray(coef)
|
|
160
|
+
self.breaks = tuple(float(t) for t in breaks)
|
|
161
|
+
if self.coef.ndim != 2 or self.coef.shape[0] != len(self.breaks) - 1:
|
|
162
|
+
raise ValueError("coef must have shape (len(breaks) - 1, degree + 1)")
|
|
163
|
+
if not all(u < v for u, v in zip(self.breaks, self.breaks[1:])):
|
|
164
|
+
raise ValueError("breaks must be strictly increasing")
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def degree(self):
|
|
168
|
+
return self.coef.shape[1] - 1
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def domain(self):
|
|
172
|
+
return (self.breaks[0], self.breaks[-1])
|
|
173
|
+
|
|
174
|
+
def __call__(self, x):
|
|
175
|
+
return _pw_chebval(jnp.asarray(x), self.coef, self.breaks)
|
|
176
|
+
|
|
177
|
+
def deriv(self):
|
|
178
|
+
return PiecewiseCheb(_pw_dcoef(self.coef, self.breaks), self.breaks)
|
|
179
|
+
|
|
180
|
+
def astype(self, dtype):
|
|
181
|
+
return PiecewiseCheb(self.coef.astype(dtype), self.breaks)
|
|
182
|
+
|
|
183
|
+
def __repr__(self):
|
|
184
|
+
return (f"PiecewiseCheb(segments={len(self.breaks) - 1}, degree={self.degree}, "
|
|
185
|
+
f"domain={self.domain}, dtype={self.coef.dtype})")
|
|
186
|
+
|
|
187
|
+
def tree_flatten(self):
|
|
188
|
+
return (self.coef,), self.breaks
|
|
189
|
+
|
|
190
|
+
@classmethod
|
|
191
|
+
def tree_unflatten(cls, breaks, children):
|
|
192
|
+
obj = object.__new__(cls)
|
|
193
|
+
obj.coef = children[0]
|
|
194
|
+
obj.breaks = breaks
|
|
195
|
+
return obj
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chebax
|
|
3
|
+
Version: 0.1.0.dev0
|
|
4
|
+
Summary: Differentiable Chebyshev approximants for special functions, aimed at JAX and GPUs
|
|
5
|
+
Author-email: Andres Hernandez <andres.hernandez.deml@gmail.com>
|
|
6
|
+
License: BSD-3-Clause
|
|
7
|
+
Project-URL: Repository, https://github.com/andreshernandez-spec/chebax
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: jax>=0.4.30
|
|
12
|
+
Requires-Dist: numpy>=1.26
|
|
13
|
+
Provides-Extra: gen
|
|
14
|
+
Requires-Dist: mpmath>=1.3; extra == "gen"
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# chebax
|
|
20
|
+
|
|
21
|
+
Differentiable Chebyshev approximants for special functions, aimed at JAX and GPUs.
|
|
22
|
+
A build-time generator (mpmath precision) produces fixed-degree branchless polynomial
|
|
23
|
+
kernels with exact derivative series, including gradients with respect to function
|
|
24
|
+
parameters (e.g. the Bessel order). Prebuilt recipes give out-of-the-box special
|
|
25
|
+
functions; a bake step emits self-contained pure-JAX modules and xsf-style C++ headers.
|
|
26
|
+
|
|
27
|
+
Early development: the generic core (fit, jax evaluation, exact derivative series,
|
|
28
|
+
segmentation) and the first recipe are in — `besselj(v)` for any real order in
|
|
29
|
+
[0, 10] on x in [0, 8], with dJ/dx via jax.grad and the order gradient via
|
|
30
|
+
`besselj_dnu(v)`, no mpmath at use time. Tails (x > 8), more recipes, and bake
|
|
31
|
+
emitters are not yet. Read
|
|
32
|
+
`PROJECT.md` for the plan and evidence, `CLAUDE.md` for how to work here. Grown out
|
|
33
|
+
of a private research project (the `../bessel/` references in `PROJECT.md` point
|
|
34
|
+
there); the two load-bearing measurements are reproduced here in `experiments/`.
|
|
35
|
+
BSD-3-Clause.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
chebax/__init__.py,sha256=VqcRUk0Z8AIqOjyDjt-aDXkAX2FIYS1tlcV1J7ZggHQ,439
|
|
2
|
+
chebax/_src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
chebax/_src/algorithms.py,sha256=zXedVYHoOeEt-4sbJj7skGL3K8ufAJgseaP8ViNhKZI,2261
|
|
4
|
+
chebax/_src/generate.py,sha256=UTW2D-zNqdrTGCJvgnEp2pkvsdz4UD0VMxd0I3yBbUI,4070
|
|
5
|
+
chebax/_src/series.py,sha256=3CKnEjs54VmoHvDcPi0Hb6QBOJxDBKB6EgKM5ZCkcsA,6550
|
|
6
|
+
chebax/_src/recipes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
chebax/_src/recipes/besselj.py,sha256=9TUm4GSxoPYAsG48MN_Ue2XlClbz7m8VDj-0JhkH5cQ,4411
|
|
8
|
+
chebax/_src/recipes/besselj_gen.py,sha256=qVEBxBkcg9l6A-OV8R3B4uqcrxD2gvrph-nA3xfxMio,2595
|
|
9
|
+
chebax/_src/recipes/besselj_table.py,sha256=UHGvgde1RGjX2AXIZkJlp0uF0wVnjy5BxwqxwWvJH4E,57784
|
|
10
|
+
chebax-0.1.0.dev0.dist-info/licenses/LICENSE,sha256=iy1BeCaZsuO9-d8beVVU73ylzIH4isCFVCvVWsdZk94,1503
|
|
11
|
+
chebax-0.1.0.dev0.dist-info/METADATA,sha256=Hh9VGgtN71Wr5cyGGCld23fnj6ypUEPAr3EMaOgQMgs,1630
|
|
12
|
+
chebax-0.1.0.dev0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
13
|
+
chebax-0.1.0.dev0.dist-info/top_level.txt,sha256=sqcHOEHa4Axx8YQek95toY12wgM9Sbv_My__N4rcsxw,7
|
|
14
|
+
chebax-0.1.0.dev0.dist-info/RECORD,,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Andres Hernandez
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
chebax
|