| Alternative 1 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 66372 |

(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(if (<= (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ 1.0 x)))) 5e-8)
(+
(* 0.3125 (sqrt (/ 1.0 (pow x 7.0))))
(+
(* 0.5 (sqrt (/ 1.0 (pow x 3.0))))
(+
(* -0.2734375 (sqrt (/ 1.0 (pow x 9.0))))
(* -0.375 (sqrt (/ 1.0 (pow x 5.0)))))))
(- (pow x -0.5) (/ (pow (+ 1.0 x) -0.16666666666666666) (cbrt (+ 1.0 x))))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) - (1.0 / sqrt((1.0 + x)))) <= 5e-8) {
tmp = (0.3125 * sqrt((1.0 / pow(x, 7.0)))) + ((0.5 * sqrt((1.0 / pow(x, 3.0)))) + ((-0.2734375 * sqrt((1.0 / pow(x, 9.0)))) + (-0.375 * sqrt((1.0 / pow(x, 5.0))))));
} else {
tmp = pow(x, -0.5) - (pow((1.0 + x), -0.16666666666666666) / cbrt((1.0 + x)));
}
return tmp;
}
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((1.0 + x)))) <= 5e-8) {
tmp = (0.3125 * Math.sqrt((1.0 / Math.pow(x, 7.0)))) + ((0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)))) + ((-0.2734375 * Math.sqrt((1.0 / Math.pow(x, 9.0)))) + (-0.375 * Math.sqrt((1.0 / Math.pow(x, 5.0))))));
} else {
tmp = Math.pow(x, -0.5) - (Math.pow((1.0 + x), -0.16666666666666666) / Math.cbrt((1.0 + x)));
}
return tmp;
}
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(1.0 + x)))) <= 5e-8) tmp = Float64(Float64(0.3125 * sqrt(Float64(1.0 / (x ^ 7.0)))) + Float64(Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))) + Float64(Float64(-0.2734375 * sqrt(Float64(1.0 / (x ^ 9.0)))) + Float64(-0.375 * sqrt(Float64(1.0 / (x ^ 5.0))))))); else tmp = Float64((x ^ -0.5) - Float64((Float64(1.0 + x) ^ -0.16666666666666666) / cbrt(Float64(1.0 + x)))); end return tmp end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-8], N[(N[(0.3125 * N[Sqrt[N[(1.0 / N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.2734375 * N[Sqrt[N[(1.0 / N[Power[x, 9.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[Sqrt[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[(N[Power[N[(1.0 + x), $MachinePrecision], -0.16666666666666666], $MachinePrecision] / N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-8}:\\
\;\;\;\;0.3125 \cdot \sqrt{\frac{1}{{x}^{7}}} + \left(0.5 \cdot \sqrt{\frac{1}{{x}^{3}}} + \left(-0.2734375 \cdot \sqrt{\frac{1}{{x}^{9}}} + -0.375 \cdot \sqrt{\frac{1}{{x}^{5}}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - \frac{{\left(1 + x\right)}^{-0.16666666666666666}}{\sqrt[3]{1 + x}}\\
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 69.0% |
|---|---|
| Target | 99.0% |
| Herbie | 83.7% |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999998e-8Initial program 40.1%
Applied egg-rr40.1%
[Start]40.1% | \[ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\] |
|---|---|
*-un-lft-identity [=>]40.1% | \[ \color{blue}{1 \cdot \frac{1}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}}
\] |
clear-num [=>]40.1% | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\frac{\sqrt{x + 1}}{1}}}
\] |
associate-/r/ [=>]40.1% | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\sqrt{x + 1}} \cdot 1}
\] |
prod-diff [=>]40.1% | \[ \color{blue}{\mathsf{fma}\left(1, \frac{1}{\sqrt{x}}, -1 \cdot \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)}
\] |
*-un-lft-identity [<=]40.1% | \[ \mathsf{fma}\left(1, \frac{1}{\sqrt{x}}, -\color{blue}{\frac{1}{\sqrt{x + 1}}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
fma-neg [<=]40.1% | \[ \color{blue}{\left(1 \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)} + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
*-un-lft-identity [<=]40.1% | \[ \left(\color{blue}{\frac{1}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
inv-pow [=>]40.1% | \[ \left(\color{blue}{{\left(\sqrt{x}\right)}^{-1}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
sqrt-pow2 [=>]32.2% | \[ \left(\color{blue}{{x}^{\left(\frac{-1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
metadata-eval [=>]32.2% | \[ \left({x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
pow1/2 [=>]32.2% | \[ \left({x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
pow-flip [=>]40.1% | \[ \left({x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
+-commutative [=>]40.1% | \[ \left({x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
metadata-eval [=>]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
Simplified40.1%
[Start]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \mathsf{fma}\left(-1, {\left(1 + x\right)}^{-0.5}, {\left(1 + x\right)}^{-0.5}\right)
\] |
|---|---|
fma-udef [=>]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\left(-1 \cdot {\left(1 + x\right)}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\] |
distribute-lft1-in [=>]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\left(-1 + 1\right) \cdot {\left(1 + x\right)}^{-0.5}}
\] |
metadata-eval [=>]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0} \cdot {\left(1 + x\right)}^{-0.5}
\] |
mul0-lft [=>]40.1% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0}
\] |
+-rgt-identity [=>]40.1% | \[ \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}
\] |
Taylor expanded in x around inf 64.8%
if 4.9999999999999998e-8 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.5%
Applied egg-rr100.0%
[Start]99.5% | \[ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\] |
|---|---|
*-un-lft-identity [=>]99.5% | \[ \color{blue}{1 \cdot \frac{1}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}}
\] |
clear-num [=>]99.5% | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\frac{\sqrt{x + 1}}{1}}}
\] |
associate-/r/ [=>]99.5% | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\sqrt{x + 1}} \cdot 1}
\] |
prod-diff [=>]99.5% | \[ \color{blue}{\mathsf{fma}\left(1, \frac{1}{\sqrt{x}}, -1 \cdot \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)}
\] |
*-un-lft-identity [<=]99.5% | \[ \mathsf{fma}\left(1, \frac{1}{\sqrt{x}}, -\color{blue}{\frac{1}{\sqrt{x + 1}}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
fma-neg [<=]99.5% | \[ \color{blue}{\left(1 \cdot \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\right)} + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
*-un-lft-identity [<=]99.5% | \[ \left(\color{blue}{\frac{1}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
inv-pow [=>]99.5% | \[ \left(\color{blue}{{\left(\sqrt{x}\right)}^{-1}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
sqrt-pow2 [=>]99.9% | \[ \left(\color{blue}{{x}^{\left(\frac{-1}{2}\right)}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
metadata-eval [=>]99.9% | \[ \left({x}^{\color{blue}{-0.5}} - \frac{1}{\sqrt{x + 1}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
pow1/2 [=>]99.9% | \[ \left({x}^{-0.5} - \frac{1}{\color{blue}{{\left(x + 1\right)}^{0.5}}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
pow-flip [=>]100.0% | \[ \left({x}^{-0.5} - \color{blue}{{\left(x + 1\right)}^{\left(-0.5\right)}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
+-commutative [=>]100.0% | \[ \left({x}^{-0.5} - {\color{blue}{\left(1 + x\right)}}^{\left(-0.5\right)}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
metadata-eval [=>]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{\color{blue}{-0.5}}\right) + \mathsf{fma}\left(-1, \frac{1}{\sqrt{x + 1}}, 1 \cdot \frac{1}{\sqrt{x + 1}}\right)
\] |
Simplified100.0%
[Start]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \mathsf{fma}\left(-1, {\left(1 + x\right)}^{-0.5}, {\left(1 + x\right)}^{-0.5}\right)
\] |
|---|---|
fma-udef [=>]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\left(-1 \cdot {\left(1 + x\right)}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\] |
distribute-lft1-in [=>]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{\left(-1 + 1\right) \cdot {\left(1 + x\right)}^{-0.5}}
\] |
metadata-eval [=>]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0} \cdot {\left(1 + x\right)}^{-0.5}
\] |
mul0-lft [=>]100.0% | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0}
\] |
+-rgt-identity [=>]100.0% | \[ \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ {x}^{-0.5} - {\left(1 + x\right)}^{-0.5}
\] |
|---|---|
add-cube-cbrt [=>]99.9% | \[ {x}^{-0.5} - \color{blue}{\left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right) \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}}
\] |
associate-*l* [=>]99.9% | \[ {x}^{-0.5} - \color{blue}{\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right)}
\] |
pow1/3 [=>]99.9% | \[ {x}^{-0.5} - \color{blue}{{\left({\left(1 + x\right)}^{-0.5}\right)}^{0.3333333333333333}} \cdot \left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right)
\] |
pow-pow [=>]99.9% | \[ {x}^{-0.5} - \color{blue}{{\left(1 + x\right)}^{\left(-0.5 \cdot 0.3333333333333333\right)}} \cdot \left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right)
\] |
+-commutative [=>]99.9% | \[ {x}^{-0.5} - {\color{blue}{\left(x + 1\right)}}^{\left(-0.5 \cdot 0.3333333333333333\right)} \cdot \left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right)
\] |
metadata-eval [=>]99.9% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{\color{blue}{-0.16666666666666666}} \cdot \left(\sqrt[3]{{\left(1 + x\right)}^{-0.5}} \cdot \sqrt[3]{{\left(1 + x\right)}^{-0.5}}\right)
\] |
cbrt-unprod [=>]99.9% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \color{blue}{\sqrt[3]{{\left(1 + x\right)}^{-0.5} \cdot {\left(1 + x\right)}^{-0.5}}}
\] |
pow-prod-up [=>]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \sqrt[3]{\color{blue}{{\left(1 + x\right)}^{\left(-0.5 + -0.5\right)}}}
\] |
metadata-eval [=>]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \sqrt[3]{{\left(1 + x\right)}^{\color{blue}{-1}}}
\] |
inv-pow [<=]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \sqrt[3]{\color{blue}{\frac{1}{1 + x}}}
\] |
cbrt-div [=>]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \color{blue}{\frac{\sqrt[3]{1}}{\sqrt[3]{1 + x}}}
\] |
metadata-eval [=>]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \frac{\color{blue}{1}}{\sqrt[3]{1 + x}}
\] |
+-commutative [=>]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \frac{1}{\sqrt[3]{\color{blue}{x + 1}}}
\] |
Simplified100.0%
[Start]100.0% | \[ {x}^{-0.5} - {\left(x + 1\right)}^{-0.16666666666666666} \cdot \frac{1}{\sqrt[3]{x + 1}}
\] |
|---|---|
associate-*r/ [=>]100.0% | \[ {x}^{-0.5} - \color{blue}{\frac{{\left(x + 1\right)}^{-0.16666666666666666} \cdot 1}{\sqrt[3]{x + 1}}}
\] |
*-rgt-identity [=>]100.0% | \[ {x}^{-0.5} - \frac{\color{blue}{{\left(x + 1\right)}^{-0.16666666666666666}}}{\sqrt[3]{x + 1}}
\] |
Final simplification83.8%
| Alternative 1 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 66372 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.7% |
| Cost | 53124 |
| Alternative 3 | |
|---|---|
| Accuracy | 83.3% |
| Cost | 39876 |
| Alternative 4 | |
|---|---|
| Accuracy | 83.2% |
| Cost | 39812 |
| Alternative 5 | |
|---|---|
| Accuracy | 83.3% |
| Cost | 26756 |
| Alternative 6 | |
|---|---|
| Accuracy | 83.3% |
| Cost | 13380 |
| Alternative 7 | |
|---|---|
| Accuracy | 82.3% |
| Cost | 13316 |
| Alternative 8 | |
|---|---|
| Accuracy | 51.7% |
| Cost | 13056 |
| Alternative 9 | |
|---|---|
| Accuracy | 51.4% |
| Cost | 6912 |
| Alternative 10 | |
|---|---|
| Accuracy | 50.6% |
| Cost | 6656 |
| Alternative 11 | |
|---|---|
| Accuracy | 50.8% |
| Cost | 6528 |
| Alternative 12 | |
|---|---|
| Accuracy | 1.9% |
| Cost | 64 |
herbie shell --seed 2023277
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))