import%20marimo%0A%0A__generated_with%20%3D%20%220.18.4%22%0Aapp%20%3D%20marimo.App()%0A%0Awith%20app.setup%3A%0A%20%20%20%20import%20math%0A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20matplotlib%20as%20mpl%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20seaborn%20as%20sns%0A%0A%20%20%20%20from%20chebpy%20import%20chebfun%0A%20%20%20%20from%20chebpy.exceptions%20import%20CompactFunConstructionError%0A%20%20%20%20from%20chebpy.settings%20import%20_preferences%20as%20prefs%0A%0A%20%20%20%20sns.set(font_scale%3D1.5)%0A%20%20%20%20sns.set_style(%22whitegrid%22)%0A%20%20%20%20sns.set_palette(%22deep%22)%0A%20%20%20%20mpl.rc(%22figure%22%2C%20figsize%3D(9%2C%205)%2C%20dpi%3D100)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Infinite%20Intervals%0A%0A%20%20%20%20This%20notebook%20revisits%20%C2%A79.1%20of%20the%0A%20%20%20%20%5BChebfun%20guide%5D(https%3A%2F%2Fwww.chebfun.org%2Fdocs%2Fguide%2Fguide09.html)%2C%20adapted%20to%20ChebPy's%0A%20%20%20%20%60CompactFun%60%20machinery.%20%20In%20MATLAB%20Chebfun%2C%20functions%20on%20%24(-%5Cinfty%2C%20%5Cinfty)%24%20or%0A%20%20%20%20%24%5Ba%2C%20%5Cinfty)%24%20are%20represented%20via%20a%20rational%20change%20of%20variables%20that%20maps%20the%0A%20%20%20%20unbounded%20domain%20onto%20%24%5B-1%2C%201%5D%24.%0A%0A%20%20%20%20ChebPy%20takes%20a%20deliberately%20different%20route.%20%20A%20%60CompactFun%60%20is%20a%20%60Classicfun%60%0A%20%20%20%20on%20a%20finite%20*storage%20interval*%20%24%5Ba'%2C%20b'%5D%24%20where%20the%20function%20is%20**numerically%0A%20%20%20%20nonzero**%2C%20and%20is%20reported%20as%20identically%20zero%20outside%20that%20interval.%20%20The%0A%20%20%20%20user-facing%20logical%20interval%20may%20still%20extend%20to%20%24%5Cpm%5Cinfty%24.%20%20This%20approach%0A%20%20%20%20has%20two%20consequences%20for%20the%20examples%20below%3A%0A%0A%20%20%20%20-%20Functions%20that%20decay%20rapidly%20to%20zero%20(Gaussians%2C%20decaying%20exponentials)%20are%0A%20%20%20%20%20%20handled%20cleanly%20and%20accurately.%0A%20%20%20%20-%20Functions%20approaching%20a%20**non-zero%20asymptote**%20(%24%5Ctanh%24%2C%20logistic%0A%20%20%20%20%20%20sigmoids%2C%20%E2%80%A6)%20are%20also%20supported%3A%20the%20asymptotic%20limits%20are%20detected%0A%20%20%20%20%20%20automatically%20and%20stored%20as%20%60tail_left%60%20%2F%20%60tail_right%60%20metadata%20on%20the%0A%20%20%20%20%20%20%60CompactFun%60.%20%20Outside%20the%20storage%20interval%20the%20function%20evaluates%20to%0A%20%20%20%20%20%20its%20tail%20constants%20rather%20than%20to%20zero.%0A%20%20%20%20-%20Functions%20that%20genuinely%20fail%20the%20model%20%E2%80%94%20heavy%20algebraic%20tails%20like%0A%20%20%20%20%20%20%241%2F(1%2Bx%5E2)%24%2C%20slowly-decaying%20oscillations%2C%20or%20non-convergent%20tails%20%E2%80%94%20are%0A%20%20%20%20%20%20still%20explicitly%20refused%20with%20a%20%60CompactFunConstructionError%60.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20A%20decaying%20oscillation%20on%20%24%5B0%2C%20%5Cinfty)%24%0A%0A%20%20%20%20The%20Chebfun%20guide%20opens%20with%20%24f(x)%20%3D%200.75%20%2B%20%5Csin(10x)%2Fe%5Ex%24%20on%20%24%5B0%2C%20%5Cinfty)%24.%0A%20%20%20%20The%20function%20approaches%20the%20non-zero%20asymptote%20%240.75%24%20as%20%24x%20%5Cto%20%5Cinfty%24%2C%20so%0A%20%20%20%20the%20probe%20records%20%60tail_right%20%3D%200.75%60%20automatically%20%E2%80%94%20the%20whole%20expression%0A%20%20%20%20fits%20inside%20a%20single%20%60CompactFun%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20f_total%20%3D%20chebfun(lambda%20x%3A%200.75%20%2B%20np.sin(10%20*%20x)%20*%20np.exp(-x)%2C%20%5B0%2C%20np.inf%5D)%0A%20%20%20%20print(f_total)%0A%20%20%20%20print(%22%22)%0A%20%20%20%20print(f%22tail_right%20%3D%20%7Bf_total.funs%5B0%5D.tail_right%3A.15f%7D%20%20%20(expected%200.75)%22)%0A%20%20%20%20return%20(f_total%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(f_total)%3A%0A%20%20%20%20%23%20Find%20the%20maximum%20of%200.75%20%2B%20sin(10x)%2Fexp(x)%20on%20%5B0%2C%20%E2%88%9E)%20via%20critical%20points.%0A%20%20%20%20_crit%20%3D%20f_total.diff().roots()%0A%20%20%20%20_a%2C%20_b%20%3D%20f_total.funs%5B0%5D.numerical_support%0A%20%20%20%20_candidates%20%3D%20np.concatenate(%5B_crit%2C%20%5B_a%2C%20_b%5D%5D)%0A%20%20%20%20_values%20%3D%20f_total(_candidates)%0A%20%20%20%20_idx%20%3D%20int(np.argmax(_values))%0A%20%20%20%20print(f%22argmax%20(in%20storage%20window)%20%3D%20%7B_candidates%5B_idx%5D%3A.15f%7D%22)%0A%20%20%20%20print(f%22max%20value%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20%7B_values%5B_idx%5D%3A.15f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(f_total)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20with%20prefs%3A%0A%20%20%20%20%20%20%20%20prefs.N_plot%20%3D%2010001%0A%20%20%20%20%20%20%20%20f_total.plot(ax%3D_ax)%0A%20%20%20%20_ax.set_xlim(0.0%2C%208)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.set_title(r%22%24f(x)%20%3D%200.75%20%2B%20%5Csin(10x)%2Fe%5Ex%24%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20%241%2F%5CGamma(x%2B1)%24%20on%20%24%5B0%2C%20%5Cinfty)%24%0A%0A%20%20%20%20Reciprocal-factorial%20decays%20super-exponentially%2C%20so%20it%20is%20a%20textbook%0A%20%20%20%20%60CompactFun%60%20candidate%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20_rgamma%20%3D%20np.frompyfunc(lambda%20y%3A%20math.exp(-math.lgamma(y%20%2B%201.0))%2C%201%2C%201)%0A%20%20%20%20g%20%3D%20chebfun(lambda%20x%3A%20np.asarray(_rgamma(x)%2C%20dtype%3Dfloat)%2C%20%5B0%2C%20np.inf%5D)%0A%20%20%20%20print(g)%0A%20%20%20%20print(f%22sum(g)%20%3D%20%7Bg.sum()%3A.15f%7D%22)%0A%20%20%20%20return%20(g%2C)%0A%0A%0A%40app.cell%0Adef%20_(g)%3A%0A%20%20%20%20_b%20%3D%20float(g.funs%5B0%5D.numerical_support%5B1%5D)%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20g.plot(ax%3D_ax)%0A%20%20%20%20_ax.set_xlim(0.0%2C%20_b)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.set_title(r%22%24g(x)%20%3D%201%2F%5CGamma(x%2B1)%24%20on%20%24%5B0%2C%20%5Cinfty)%24%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20A%20doubly-infinite%20Gaussian%0A%0A%20%20%20%20The%20bread-and-butter%20case%20for%20%60CompactFun%60%3A%20the%20standard%20Gaussian%20on%0A%20%20%20%20%24(-%5Cinfty%2C%20%5Cinfty)%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20h%20%3D%20chebfun(lambda%20x%3A%20np.exp(-(x**2))%2C%20%5B-np.inf%2C%20np.inf%5D)%0A%20%20%20%20print(h)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22sum(h)%20%20%3D%20%7Bh.sum()%3A.15f%7D%22)%0A%20%20%20%20print(f%22%E2%88%9A%CF%80%20%20%20%20%20%20%3D%20%7Bnp.sqrt(np.pi)%3A.15f%7D%22)%0A%20%20%20%20return%20(h%2C)%0A%0A%0A%40app.cell%0Adef%20_(h)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20h.plot(ax%3D_ax)%0A%20%20%20%20_ax.set_xlim(-6.0%2C%206.0)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.set_title(r%22%24h(x)%20%3D%20e%5E%7B-x%5E2%7D%24%20on%20%24(-%5Cinfty%2C%20%5Cinfty)%24%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Convolution%3A%20density%20of%20the%20sum%20of%20two%20independent%20Gaussians%0A%0A%20%20%20%20Because%20each%20%60CompactFun%60%20lives%20on%20a%20finite%20storage%20interval%2C%20the%20existing%0A%20%20%20%20Hale%E2%80%93Townsend%20Legendre%20convolution%20machinery%20applies%20directly.%20%20Convolving%20the%0A%20%20%20%20standard%20Gaussian%20density%20with%20itself%20produces%20%24%5Cmathcal%7BN%7D(0%2C%202)%24%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20def%20_f(x)%3A%0A%20%20%20%20%20%20%20%20return%20np.exp(-(x**2)%20%2F%202.0)%20%2F%20np.sqrt(2.0%20*%20np.pi)%0A%0A%20%20%20%20pdf1%20%3D%20chebfun(_f%2C%20%5B-np.inf%2C%20np.inf%5D)%0A%20%20%20%20pdf2%20%3D%20pdf1.conv(pdf1)%0A%0A%20%20%20%20print(pdf1)%0A%20%20%20%20print()%0A%20%20%20%20print(pdf2)%0A%20%20%20%20return%20pdf1%2C%20pdf2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(pdf1%2C%20pdf2)%3A%0A%20%20%20%20print(f%22sum(pdf1)%20%20%20%20%20%20%20%20%3D%20%7Bpdf1.sum()%3A.15f%7D%20%20(expected%201)%22)%0A%20%20%20%20print(f%22sum(pdf1*pdf1)%20%20%20%3D%20%7Bpdf2.sum()%3A.15f%7D%20%20(expected%201)%22)%0A%20%20%20%20_expected%20%3D%201.0%20%2F%20np.sqrt(4.0%20*%20np.pi)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22(pdf1*pdf1)(0)%20%20%20%3D%20%7Bpdf2(0.0)%3A.15f%7D%22)%0A%20%20%20%20print(f%221%2Fsqrt(4*pi)%20%20%20%20%20%3D%20%7B_expected%3A.15f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pdf1%2C%20pdf2)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20pdf1.plot(ax%3D_ax%2C%20label%3Dr%22%24%5Cphi(x)%24%20%E2%80%94%20%24%5Cmathcal%7BN%7D(0%2C1)%24%22)%0A%20%20%20%20pdf2.plot(ax%3D_ax%2C%20label%3Dr%22%24%5Cphi%20%5Cstar%20%5Cphi%24%20%E2%80%94%20%24%5Cmathcal%7BN%7D(0%2C2)%24%22)%0A%20%20%20%20_ax.set_xlim(-6.0%2C%206.0)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.legend()%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Sum%20of%20two%20exponentials%3A%20Gamma%24(2%2C%201)%24%0A%0A%20%20%20%20Convolving%20%24e%5E%7B-x%7D%24%20on%20%24%5B0%2C%20%5Cinfty)%24%20with%20itself%20yields%20the%20%24%5Cmathrm%7BGamma%7D(2%2C1)%24%0A%20%20%20%20density%20%24x%20%5C%2C%20e%5E%7B-x%7D%24%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20expo%20%3D%20chebfun(lambda%20x%3A%20np.exp(-x)%2C%20%5B0%2C%20np.inf%5D)%0A%20%20%20%20gamma2%20%3D%20expo.conv(expo)%0A%20%20%20%20print(f%22sum(expo*expo)%20%20%20%20%20%20%20%20%3D%20%7Bgamma2.sum()%3A.15f%7D%20%20(expected%201)%22)%0A%20%20%20%20print(f%22(expo*expo)(1)%20%20%20%20%20%20%20%20%3D%20%7Bgamma2(1.0)%3A.15f%7D%22)%0A%20%20%20%20print(f%221*exp(-1)%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20%7Bnp.exp(-1.0)%3A.15f%7D%22)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22piece%20types%3A%20%7B%5Btype(_p).__name__%20for%20_p%20in%20gamma2.funs%5D%7D%22)%0A%20%20%20%20return%20expo%2C%20gamma2%0A%0A%0A%40app.cell%0Adef%20_(expo%2C%20gamma2)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20expo.plot(ax%3D_ax%2C%20label%3Dr%22%24e%5E%7B-x%7D%24%22)%0A%20%20%20%20gamma2.plot(ax%3D_ax%2C%20label%3Dr%22%24x%20%5C%2C%20e%5E%7B-x%7D%24%22)%0A%20%20%20%20_ax.set_xlim(0.0%2C%2012.0)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.legend()%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20What%20gets%20refused%0A%0A%20%20%20%20A%20central%20design%20choice%20of%20%60CompactFun%60%20is%20to%20**honestly%20refuse**%20inputs%20that%0A%20%20%20%20cannot%20be%20represented%20under%20the%20numerical-support%20model.%20%20These%20are%20exactly%0A%20%20%20%20the%20cases%20where%20MATLAB%20Chebfun's%20rational%20map%20silently%20produces%20a%20result%20of%0A%20%20%20%20questionable%20accuracy%3A%0A%0A%20%20%20%20-%20The%20Cauchy%20density%20%24%5Cdfrac%7B1%7D%7B%5Cpi(1%2Bx%5E2)%7D%24%20%E2%80%94%20heavy%20tails%2C%20only%20%24O(1%2Fx%5E2)%24%20decay.%0A%20%20%20%20-%20%24%5Cdfrac%7B1%7D%7B1%2B%7Cx%7C%7D%24%20%E2%80%94%20even%20heavier%20tails%2C%20%24O(1%2Fx)%24%20decay.%0A%20%20%20%20-%20%24%5Csin(x)%24%20%E2%80%94%20non-convergent%20oscillation%20at%20%24%5Cpm%5Cinfty%24.%0A%0A%20%20%20%20Each%20of%20the%20following%20raises%20a%20%60CompactFunConstructionError%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20_refused%20%3D%20%5B%5D%0A%20%20%20%20for%20_label%2C%20_f%20in%20%5B%0A%20%20%20%20%20%20%20%20(%22Cauchy%201%2F(%CF%80(1%2Bx%C2%B2))%22%2C%20lambda%20x%3A%201.0%20%2F%20(np.pi%20*%20(1.0%20%2B%20x%20*%20x)))%2C%0A%20%20%20%20%20%20%20%20(%221%2F(1%2B%7Cx%7C)%22%2C%20lambda%20x%3A%201.0%20%2F%20(1.0%20%2B%20np.abs(x)))%2C%0A%20%20%20%20%20%20%20%20(%22sin(x)%22%2C%20lambda%20x%3A%20np.sin(x))%2C%0A%20%20%20%20%5D%3A%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20chebfun(_f%2C%20%5B-np.inf%2C%20np.inf%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20_refused.append((_label%2C%20%22ACCEPTED%20(unexpected)%22))%0A%20%20%20%20%20%20%20%20except%20CompactFunConstructionError%20as%20_err%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_refused.append((_label%2C%20str(_err).split(%22%3B%22)%5B0%5D))%0A%20%20%20%20for%20_label%2C%20_message%20in%20_refused%3A%0A%20%20%20%20%20%20%20%20print(f%22%7B_label%3A25s%7D%20-%3E%20%7B_message%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Sigmoid-like%20inputs%3A%20non-zero%20tail%20constants%0A%0A%20%20%20%20Functions%20that%20approach%20**finite%2C%20non-zero**%20asymptotic%20limits%20at%20%24%5Cpm%5Cinfty%24%0A%20%20%20%20%E2%80%94%20%24%5Ctanh%24%2C%20the%20logistic%20sigmoid%2C%20smoothed%20step%20functions%20%E2%80%94%20are%20supported%20via%0A%20%20%20%20%60(tail_left%2C%20tail_right)%60%20metadata%20on%20the%20%60CompactFun%60.%20%20The%20constants%20are%0A%20%20%20%20detected%20automatically%20by%20the%20same%20probe%20that%20locates%20the%20numerical-support%0A%20%20%20%20window%2C%20so%20the%20user%20does%20not%20need%20to%20pass%20them%20explicitly.%0A%0A%20%20%20%20Outside%20the%20storage%20interval%20the%20function%20evaluates%20to%20its%20tail%20constants%0A%20%20%20%20rather%20than%20to%20zero%2C%20and%20arithmetic%20with%20scalars%20or%20other%20%60CompactFun%60s%0A%20%20%20%20propagates%20the%20tails%20(e.g.%20%24-f%24%20flips%20both%2C%20%24%5Calpha%20f%24%20scales%20them%2C%20and%0A%20%20%20%20%24f%20%2B%20c%24%20shifts%20them).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20tanh%20%3D%20chebfun(np.tanh%2C%20%5B-np.inf%2C%20np.inf%5D)%0A%20%20%20%20tanh%0A%20%20%20%20return%20(tanh%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(tanh)%3A%0A%20%20%20%20_piece%20%3D%20tanh.funs%5B0%5D%0A%20%20%20%20print(f%22%20%20tail_left%20%20%20%3D%20%20%7B_piece.tail_left%3A%2B.15f%7D%22)%0A%20%20%20%20print(f%22%20%20tail_right%20%20%3D%20%20%7B_piece.tail_right%3A%2B.15f%7D%22)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22tanh(-1e10)%20%20-%3E%20%20%7Btanh(-1e10)%3A%2B.15f%7D%20%20%20(returns%20tail_left)%22)%0A%20%20%20%20print(f%22tanh(0.0)%20%20%20%20-%3E%20%20%7Btanh(0.0)%3A%2B.15f%7D%22)%0A%20%20%20%20print(f%22tanh(%2B1e10)%20%20-%3E%20%20%7Btanh(%2B1e10)%3A%2B.15f%7D%20%20%20(returns%20tail_right)%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Algebraic%20operations%20that%20would%20diverge%20on%20an%20unbounded%20domain%20are%20still%0A%20%20%20%20refused%20%E2%80%94%20but%20now%20with%20a%20%60DivergentIntegralError%60%20that%20names%20the%20offending%0A%20%20%20%20operation%2C%20rather%20than%20silently%20returning%20a%20wrong%20number%3A%0A%0A%20%20%20%20-%20%60f.sum()%60%20on%20a%20function%20with%20a%20non-zero%20tail%20on%20an%20infinite%20side.%0A%20%20%20%20-%20%60f.cumsum()%60%20on%20the%20same%20(the%20antiderivative%20is%20unbounded).%0A%20%20%20%20-%20%60f.conv(g)%60%20whenever%20either%20operand%20has%20a%20non-zero%20tail.%0A%0A%20%20%20%20These%20errors%20point%20users%20at%20the%20natural%20escape%20hatch%3A%20subtract%20a%20matched%0A%20%20%20%20sigmoid%20first%20so%20the%20residual%20has%20zero%20tails%2C%20operate%20on%20the%20residual%2C%20then%0A%20%20%20%20re-add%20the%20sigmoid%20analytically.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(tanh)%3A%0A%20%20%20%20from%20chebpy.exceptions%20import%20DivergentIntegralError%0A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20tanh.sum()%0A%20%20%20%20except%20DivergentIntegralError%20as%20_err%3A%0A%20%20%20%20%20%20%20%20print(f%22t.sum()%20refused%3A%20%7B_err%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Mixed%20piecewise%3A%20finite%20breakpoints%20with%20infinite%20endpoints%0A%0A%20%20%20%20%60chebfun(f%2C%20%5B-inf%2C%20a%E2%82%81%2C%20%E2%80%A6%2C%20a_k%2C%20%2Binf%5D)%60%20produces%20a%20%60Chebfun%60%20whose%20two%20outer%0A%20%20%20%20pieces%20are%20%60CompactFun%60%20and%20whose%20interior%20pieces%20are%20ordinary%20%60Bndfun%60s%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20p%20%3D%20chebfun(lambda%20x%3A%20np.exp(-(x**2))%2C%20%5B-np.inf%2C%20-2.0%2C%200.0%2C%203.0%2C%20np.inf%5D)%0A%20%20%20%20print(p)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22piece%20types%3A%20%7B%5Btype(_piece).__name__%20for%20_piece%20in%20p.funs%5D%7D%22)%0A%20%20%20%20print()%0A%20%20%20%20print(f%22sum(p)%20%20%3D%20%7Bp.sum()%3A.15f%7D%22)%0A%20%20%20%20print(f%22%E2%88%9A%CF%80%20%20%20%20%20%20%3D%20%7Bnp.sqrt(np.pi)%3A.15f%7D%22)%0A%20%20%20%20return%20(p%2C)%0A%0A%0A%40app.cell%0Adef%20_(p)%3A%0A%20%20%20%20_fig%2C%20_ax%20%3D%20plt.subplots()%0A%20%20%20%20p.plot(ax%3D_ax)%0A%20%20%20%20for%20_bp%20in%20p.breakpoints%5B1%3A-1%5D%3A%0A%20%20%20%20%20%20%20%20_ax.axvline(float(_bp)%2C%20color%3D%22grey%22%2C%20linestyle%3D%22--%22%2C%20linewidth%3D0.8)%0A%20%20%20%20_ax.set_xlim(-6.0%2C%206.0)%0A%20%20%20%20_ax.set_xlabel(%22x%22)%0A%20%20%20%20_ax.set_title(%22Piecewise%20Gaussian%20on%20%24%5B-%5C%5Cinfty%2C%20-2%2C%200%2C%203%2C%20%2B%5C%5Cinfty%5D%24%22)%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
00c93de6fdc6e46f4cba4db81901e52c