| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 45952 |
\[\begin{array}{l}
t_0 := \sqrt{x} + \sqrt{x + 1}\\
\frac{\frac{-1}{\mathsf{hypot}\left(x, \sqrt{x}\right)} \cdot t_0}{-{t_0}^{2}}
\end{array}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 0.0)
(/ (* (sqrt x) (/ 0.5 x)) (+ x 1.0))
(* (/ 1.0 (+ (sqrt x) t_0)) (pow (fma x x x) -0.5)))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 0.0) {
tmp = (sqrt(x) * (0.5 / x)) / (x + 1.0);
} else {
tmp = (1.0 / (sqrt(x) + t_0)) * pow(fma(x, x, x), -0.5);
}
return tmp;
}
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 0.0) tmp = Float64(Float64(sqrt(x) * Float64(0.5 / x)) / Float64(x + 1.0)); else tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) * (fma(x, x, x) ^ -0.5)); 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_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[(N[Sqrt[x], $MachinePrecision] * N[(0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] * N[Power[N[(x * x + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 0:\\
\;\;\;\;\frac{\sqrt{x} \cdot \frac{0.5}{x}}{x + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x} + t_0} \cdot {\left(\mathsf{fma}\left(x, x, x\right)\right)}^{-0.5}\\
\end{array}
| Original | 19.8 |
|---|---|
| Target | 0.6 |
| Herbie | 0.2 |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 40.8
Applied egg-rr40.8
Simplified40.8
[Start]40.8 | \[ \left(\frac{1}{x} + \frac{-1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
|---|---|
associate-*r/ [=>]40.8 | \[ \color{blue}{\frac{\left(\frac{1}{x} + \frac{-1}{1 + x}\right) \cdot 1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}}
\] |
*-rgt-identity [=>]40.8 | \[ \frac{\color{blue}{\frac{1}{x} + \frac{-1}{1 + x}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
Taylor expanded in x around inf 40.8
Applied egg-rr21.9
Simplified16.7
[Start]21.9 | \[ \frac{\left(1 + \left(x - x\right)\right) \cdot \left(0.5 \cdot \sqrt{x}\right)}{x \cdot \left(1 - x \cdot x\right)} \cdot \left(1 - x\right)
\] |
|---|---|
+-commutative [=>]21.9 | \[ \frac{\color{blue}{\left(\left(x - x\right) + 1\right)} \cdot \left(0.5 \cdot \sqrt{x}\right)}{x \cdot \left(1 - x \cdot x\right)} \cdot \left(1 - x\right)
\] |
+-inverses [=>]21.9 | \[ \frac{\left(\color{blue}{0} + 1\right) \cdot \left(0.5 \cdot \sqrt{x}\right)}{x \cdot \left(1 - x \cdot x\right)} \cdot \left(1 - x\right)
\] |
metadata-eval [=>]21.9 | \[ \frac{\color{blue}{1} \cdot \left(0.5 \cdot \sqrt{x}\right)}{x \cdot \left(1 - x \cdot x\right)} \cdot \left(1 - x\right)
\] |
*-lft-identity [=>]21.9 | \[ \frac{\color{blue}{0.5 \cdot \sqrt{x}}}{x \cdot \left(1 - x \cdot x\right)} \cdot \left(1 - x\right)
\] |
times-frac [=>]16.7 | \[ \color{blue}{\left(\frac{0.5}{x} \cdot \frac{\sqrt{x}}{1 - x \cdot x}\right)} \cdot \left(1 - x\right)
\] |
Applied egg-rr0.3
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 1.3
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ \frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
|---|---|
+-commutative [=>]0.3 | \[ \frac{\color{blue}{\left(x - x\right) + 1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
+-inverses [=>]0.3 | \[ \frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
metadata-eval [=>]0.3 | \[ \frac{\color{blue}{1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
+-commutative [=>]0.3 | \[ \frac{1}{\sqrt{x + x \cdot x} \cdot \color{blue}{\left(\sqrt{1 + x} + \sqrt{x}\right)}}
\] |
Applied egg-rr0.1
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 45952 |
| Alternative 2 | |
|---|---|
| Error | 0.3 |
| Cost | 26948 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 26756 |
| Alternative 4 | |
|---|---|
| Error | 0.7 |
| Cost | 26432 |
| Alternative 5 | |
|---|---|
| Error | 0.7 |
| Cost | 26368 |
| Alternative 6 | |
|---|---|
| Error | 0.3 |
| Cost | 20164 |
| Alternative 7 | |
|---|---|
| Error | 0.4 |
| Cost | 13380 |
| Alternative 8 | |
|---|---|
| Error | 1.3 |
| Cost | 7108 |
| Alternative 9 | |
|---|---|
| Error | 1.0 |
| Cost | 7108 |
| Alternative 10 | |
|---|---|
| Error | 20.6 |
| Cost | 7044 |
| Alternative 11 | |
|---|---|
| Error | 21.1 |
| Cost | 6916 |
| Alternative 12 | |
|---|---|
| Error | 21.1 |
| Cost | 6916 |
| Alternative 13 | |
|---|---|
| Error | 29.5 |
| Cost | 6788 |
| Alternative 14 | |
|---|---|
| Error | 59.3 |
| Cost | 320 |
| Alternative 15 | |
|---|---|
| Error | 62.8 |
| Cost | 64 |
| Alternative 16 | |
|---|---|
| Error | 60.3 |
| Cost | 64 |
herbie shell --seed 2023073
(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)))))