u/Key_Bad_323

An Optimized e^(-x^2) Approximation via sech^2 (No Exponents, Error < 0.09%)

Hi everyone,

​

I wanted to share an approximation for the classic Gaussian function $e\^{-x\^2}$ that I've been working on. It completely avoids traditional exponential evaluations, replacing them with basic algebra and a hyperbolic secant.

​

\### The Idea

​

I started by taking the derivative of the well-known Vedjer (Winitzki) approximation for $\\text{erf}(x)$:

​

$$\\text{erf}(x) \\approx \\tanh\\left( \\frac{2}{\\sqrt{\\pi}} x + 0.147 x\^3 \\right)$$

​

Directly differentiating this baseline configuration and isolating $e\^{-x\^2}$ yields a maximum absolute error of 1.88% (peaking around $x \\approx 0.63$). The issue is that the parameter $k = 0.147$ was mathematically tuned for the integral, not the slope.

\### The Optimization

​

To fix this, I performed a non-linear parameter optimization specifically to fit the Gaussian curve.

​

By tuning the parameter to $k \\approx 0.10307$, the final proposed formula becomes:

​

$$e\^{-x\^2} \\approx \\left( 1 + 0.27403 x\^2 \\right) \\text{sech}\^2\\left( 1.12838 x + 0.10307 x\^3 \\right)$$

​

\### The Results

​

This single parameter shift causes the maximum absolute error to plummet to a staggering 0.00082 (0.082%) across the entire real line—marking a 20-fold precision increase compared to the baseline derivative!

​

Here is a quick look at the pointwise residual behavior:

​

\* x = 0.0: Exact = 1.00000 | Approx = 1.00000 | Error = 0.00000

​

\* x = 0.5: Exact = 0.77880 | Approx = 0.77953 | Error = 0.00073

​

\* x = 1.0: Exact = 0.36788 | Approx = 0.36735 | Error = 0.00053

​

\* x = 2.0: Exact = 0.01832 | Approx = 0.01844 | Error = 0.00012

​

I have made the full 2-page Research Note in LaTeX:

​

https://drive.google.com/file/d/18fcq9Zoz9BsOlhAVgMcctRnW1bnvn89A/view?usp=drivesdk

​

Would love to hear your thoughts on this!

reddit.com
u/Key_Bad_323 — 23 days ago