| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13376 |
\[\frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(1, x\right)}
\]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x)
:precision binary64
(if (<= x -2e+47)
(/ 1.0 x)
(if (<= x 1000.0)
(/ x (+ 1.0 (* x x)))
(* (/ 1.0 (hypot 1.0 x)) (+ 1.0 (/ -0.5 (* x x)))))))double code(double x) {
return x / ((x * x) + 1.0);
}
double code(double x) {
double tmp;
if (x <= -2e+47) {
tmp = 1.0 / x;
} else if (x <= 1000.0) {
tmp = x / (1.0 + (x * x));
} else {
tmp = (1.0 / hypot(1.0, x)) * (1.0 + (-0.5 / (x * x)));
}
return tmp;
}
public static double code(double x) {
return x / ((x * x) + 1.0);
}
public static double code(double x) {
double tmp;
if (x <= -2e+47) {
tmp = 1.0 / x;
} else if (x <= 1000.0) {
tmp = x / (1.0 + (x * x));
} else {
tmp = (1.0 / Math.hypot(1.0, x)) * (1.0 + (-0.5 / (x * x)));
}
return tmp;
}
def code(x): return x / ((x * x) + 1.0)
def code(x): tmp = 0 if x <= -2e+47: tmp = 1.0 / x elif x <= 1000.0: tmp = x / (1.0 + (x * x)) else: tmp = (1.0 / math.hypot(1.0, x)) * (1.0 + (-0.5 / (x * x))) return tmp
function code(x) return Float64(x / Float64(Float64(x * x) + 1.0)) end
function code(x) tmp = 0.0 if (x <= -2e+47) tmp = Float64(1.0 / x); elseif (x <= 1000.0) tmp = Float64(x / Float64(1.0 + Float64(x * x))); else tmp = Float64(Float64(1.0 / hypot(1.0, x)) * Float64(1.0 + Float64(-0.5 / Float64(x * x)))); end return tmp end
function tmp = code(x) tmp = x / ((x * x) + 1.0); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -2e+47) tmp = 1.0 / x; elseif (x <= 1000.0) tmp = x / (1.0 + (x * x)); else tmp = (1.0 / hypot(1.0, x)) * (1.0 + (-0.5 / (x * x))); end tmp_2 = tmp; end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -2e+47], N[(1.0 / x), $MachinePrecision], If[LessEqual[x, 1000.0], N[(x / N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{x}{x \cdot x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+47}:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{elif}\;x \leq 1000:\\
\;\;\;\;\frac{x}{1 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \left(1 + \frac{-0.5}{x \cdot x}\right)\\
\end{array}
Results
| Original | 77.1% |
|---|---|
| Target | 99.8% |
| Herbie | 100.0% |
if x < -2.0000000000000001e47Initial program 44.0%
Taylor expanded in x around inf 100.0%
if -2.0000000000000001e47 < x < 1e3Initial program 100.0%
if 1e3 < x Initial program 54.5%
Applied egg-rr100.0%
[Start]54.5 | \[ \frac{x}{x \cdot x + 1}
\] |
|---|---|
*-un-lft-identity [=>]54.5 | \[ \frac{\color{blue}{1 \cdot x}}{x \cdot x + 1}
\] |
add-sqr-sqrt [=>]54.5 | \[ \frac{1 \cdot x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}
\] |
times-frac [=>]54.7 | \[ \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}
\] |
+-commutative [=>]54.7 | \[ \frac{1}{\sqrt{\color{blue}{1 + x \cdot x}}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}
\] |
hypot-1-def [=>]54.7 | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right)}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}
\] |
+-commutative [=>]54.7 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\sqrt{\color{blue}{1 + x \cdot x}}}
\] |
hypot-1-def [=>]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\color{blue}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around inf 100.0%
Simplified100.0%
[Start]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \left(1 - 0.5 \cdot \frac{1}{{x}^{2}}\right)
\] |
|---|---|
associate-*r/ [=>]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \left(1 - \color{blue}{\frac{0.5 \cdot 1}{{x}^{2}}}\right)
\] |
metadata-eval [=>]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \left(1 - \frac{\color{blue}{0.5}}{{x}^{2}}\right)
\] |
unpow2 [=>]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \left(1 - \frac{0.5}{\color{blue}{x \cdot x}}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 13376 |
| Alternative 2 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 456 |
| Alternative 4 | |
|---|---|
| Accuracy | 51.6% |
| Cost | 64 |
herbie shell --seed 2023126
(FPCore (x)
:name "x / (x^2 + 1)"
:precision binary64
:herbie-target
(/ 1.0 (+ x (/ 1.0 x)))
(/ x (+ (* x x) 1.0)))