| Alternative 1 | |
|---|---|
| Error | 0.02% |
| Cost | 7049 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -20000000 \lor \neg \left(x \leq 1000\right):\\
\;\;\;\;\frac{1}{x} - {x}^{-3}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 + x \cdot x}\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x) :precision binary64 (if (<= x -10000000000.0) (/ 1.0 x) (if (<= x 1000.0) (* x (/ 1.0 (fma x x 1.0))) (- (/ 1.0 x) (pow x -3.0)))))
double code(double x) {
return x / ((x * x) + 1.0);
}
double code(double x) {
double tmp;
if (x <= -10000000000.0) {
tmp = 1.0 / x;
} else if (x <= 1000.0) {
tmp = x * (1.0 / fma(x, x, 1.0));
} else {
tmp = (1.0 / x) - pow(x, -3.0);
}
return tmp;
}
function code(x) return Float64(x / Float64(Float64(x * x) + 1.0)) end
function code(x) tmp = 0.0 if (x <= -10000000000.0) tmp = Float64(1.0 / x); elseif (x <= 1000.0) tmp = Float64(x * Float64(1.0 / fma(x, x, 1.0))); else tmp = Float64(Float64(1.0 / x) - (x ^ -3.0)); end return tmp end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -10000000000.0], N[(1.0 / x), $MachinePrecision], If[LessEqual[x, 1000.0], N[(x * N[(1.0 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] - N[Power[x, -3.0], $MachinePrecision]), $MachinePrecision]]]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -10000000000:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{elif}\;x \leq 1000:\\
\;\;\;\;x \cdot \frac{1}{\mathsf{fma}\left(x, x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} - {x}^{-3}\\
\end{array}
| Original | 23.17% |
|---|---|
| Target | 0.14% |
| Herbie | 0.02% |
if x < -1e10Initial program 47.64
Taylor expanded in x around inf 0
if -1e10 < x < 1e3Initial program 0.02
Applied egg-rr0.03
if 1e3 < x Initial program 47.59
Taylor expanded in x around inf 0.04
Applied egg-rr0.27
Simplified0.04
[Start]0.27 | \[ \frac{1}{x} - \left(e^{\mathsf{log1p}\left({x}^{-3}\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]0.04 | \[ \frac{1}{x} - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{-3}\right)\right)}
\] |
expm1-log1p [=>]0.04 | \[ \frac{1}{x} - \color{blue}{{x}^{-3}}
\] |
Final simplification0.02
| Alternative 1 | |
|---|---|
| Error | 0.02% |
| Cost | 7049 |
| Alternative 2 | |
|---|---|
| Error | 0.75% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Error | 0.01% |
| Cost | 712 |
| Alternative 4 | |
|---|---|
| Error | 1.01% |
| Cost | 456 |
| Alternative 5 | |
|---|---|
| Error | 48.33% |
| Cost | 64 |
herbie shell --seed 2023089
(FPCore (x)
:name "x / (x^2 + 1)"
:precision binary64
:herbie-target
(/ 1.0 (+ x (/ 1.0 x)))
(/ x (+ (* x x) 1.0)))