| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 26692 |
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (* (/ (pow x -0.5) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))) (/ (pow x -0.5) (+ x 1.0))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
return (pow(x, -0.5) / (pow(x, -0.5) + pow((x + 1.0), -0.5))) * (pow(x, -0.5) / (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
real(8) function code(x)
real(8), intent (in) :: x
code = ((x ** (-0.5d0)) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))) * ((x ** (-0.5d0)) / (x + 1.0d0))
end function
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) {
return (Math.pow(x, -0.5) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))) * (Math.pow(x, -0.5) / (x + 1.0));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): return (math.pow(x, -0.5) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))) * (math.pow(x, -0.5) / (x + 1.0))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) return Float64(Float64((x ^ -0.5) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))) * Float64((x ^ -0.5) / Float64(x + 1.0))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp = code(x) tmp = ((x ^ -0.5) / ((x ^ -0.5) + ((x + 1.0) ^ -0.5))) * ((x ^ -0.5) / (x + 1.0)); 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_] := N[(N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{{x}^{-0.5}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{{x}^{-0.5}}{x + 1}
Results
| Original | 68.4% |
|---|---|
| Target | 99.0% |
| Herbie | 99.8% |
Initial program 68.4%
Applied egg-rr68.7%
[Start]68.4 | \[ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\] |
|---|---|
*-un-lft-identity [=>]68.4 | \[ \color{blue}{1 \cdot \frac{1}{\sqrt{x}}} - \frac{1}{\sqrt{x + 1}}
\] |
clear-num [=>]68.4 | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\frac{\sqrt{x + 1}}{1}}}
\] |
associate-/r/ [=>]68.4 | \[ 1 \cdot \frac{1}{\sqrt{x}} - \color{blue}{\frac{1}{\sqrt{x + 1}} \cdot 1}
\] |
prod-diff [=>]68.4 | \[ \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 [<=]68.4 | \[ \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 [<=]68.4 | \[ \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 [<=]68.4 | \[ \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 [=>]68.4 | \[ \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 [=>]64.5 | \[ \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 [=>]64.5 | \[ \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 [=>]64.5 | \[ \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 [=>]68.7 | \[ \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 [=>]68.7 | \[ \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 [=>]68.7 | \[ \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)
\] |
Simplified68.7%
[Start]68.7 | \[ \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 [=>]68.7 | \[ \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 [=>]68.7 | \[ \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 [=>]68.7 | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0} \cdot {\left(1 + x\right)}^{-0.5}
\] |
mul0-lft [=>]68.7 | \[ \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right) + \color{blue}{0}
\] |
+-rgt-identity [=>]68.7 | \[ \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}
\] |
Applied egg-rr68.3%
[Start]68.7 | \[ {x}^{-0.5} - {\left(1 + x\right)}^{-0.5}
\] |
|---|---|
flip-- [=>]68.6 | \[ \color{blue}{\frac{{x}^{-0.5} \cdot {x}^{-0.5} - {\left(1 + x\right)}^{-0.5} \cdot {\left(1 + x\right)}^{-0.5}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}}
\] |
pow-prod-up [=>]60.7 | \[ \frac{\color{blue}{{x}^{\left(-0.5 + -0.5\right)}} - {\left(1 + x\right)}^{-0.5} \cdot {\left(1 + x\right)}^{-0.5}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
metadata-eval [=>]60.7 | \[ \frac{{x}^{\color{blue}{-1}} - {\left(1 + x\right)}^{-0.5} \cdot {\left(1 + x\right)}^{-0.5}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
unpow-1 [=>]60.7 | \[ \frac{\color{blue}{\frac{1}{x}} - {\left(1 + x\right)}^{-0.5} \cdot {\left(1 + x\right)}^{-0.5}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
pow-prod-up [=>]68.3 | \[ \frac{\frac{1}{x} - \color{blue}{{\left(1 + x\right)}^{\left(-0.5 + -0.5\right)}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
metadata-eval [=>]68.3 | \[ \frac{\frac{1}{x} - {\left(1 + x\right)}^{\color{blue}{-1}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
unpow-1 [=>]68.3 | \[ \frac{\frac{1}{x} - \color{blue}{\frac{1}{1 + x}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
+-commutative [=>]68.3 | \[ \frac{\frac{1}{x} - \frac{1}{\color{blue}{x + 1}}}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}
\] |
+-commutative [=>]68.3 | \[ \frac{\frac{1}{x} - \frac{1}{x + 1}}{{x}^{-0.5} + {\color{blue}{\left(x + 1\right)}}^{-0.5}}
\] |
Applied egg-rr91.5%
[Start]68.3 | \[ \frac{\frac{1}{x} - \frac{1}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
|---|---|
frac-sub [=>]69.3 | \[ \frac{\color{blue}{\frac{1 \cdot \left(x + 1\right) - x \cdot 1}{x \cdot \left(x + 1\right)}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
associate-/r* [=>]69.3 | \[ \frac{\color{blue}{\frac{\frac{1 \cdot \left(x + 1\right) - x \cdot 1}{x}}{x + 1}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
*-un-lft-identity [<=]69.3 | \[ \frac{\frac{\frac{\color{blue}{\left(x + 1\right)} - x \cdot 1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
+-commutative [=>]69.3 | \[ \frac{\frac{\frac{\color{blue}{\left(1 + x\right)} - x \cdot 1}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
*-rgt-identity [=>]69.3 | \[ \frac{\frac{\frac{\left(1 + x\right) - \color{blue}{x}}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
associate--l+ [=>]91.5 | \[ \frac{\frac{\frac{\color{blue}{1 + \left(x - x\right)}}{x}}{x + 1}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
+-commutative [=>]91.5 | \[ \frac{\frac{\frac{1 + \left(x - x\right)}{x}}{\color{blue}{1 + x}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
Applied egg-rr99.8%
[Start]91.5 | \[ \frac{\frac{\frac{1 + \left(x - x\right)}{x}}{1 + x}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}
\] |
|---|---|
associate-/l/ [=>]99.4 | \[ \color{blue}{\frac{\frac{1 + \left(x - x\right)}{x}}{\left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right) \cdot \left(1 + x\right)}}
\] |
add-sqr-sqrt [=>]99.4 | \[ \frac{\color{blue}{\sqrt{\frac{1 + \left(x - x\right)}{x}} \cdot \sqrt{\frac{1 + \left(x - x\right)}{x}}}}{\left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right) \cdot \left(1 + x\right)}
\] |
times-frac [=>]99.6 | \[ \color{blue}{\frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}}
\] |
+-inverses [=>]99.6 | \[ \frac{\sqrt{\frac{1 + \color{blue}{0}}{x}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
metadata-eval [=>]99.6 | \[ \frac{\sqrt{\frac{\color{blue}{1}}{x}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
inv-pow [=>]99.6 | \[ \frac{\sqrt{\color{blue}{{x}^{-1}}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
metadata-eval [<=]99.6 | \[ \frac{\sqrt{{x}^{\color{blue}{\left(-0.5 + -0.5\right)}}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
pow-prod-up [<=]99.7 | \[ \frac{\sqrt{\color{blue}{{x}^{-0.5} \cdot {x}^{-0.5}}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
sqrt-unprod [<=]99.1 | \[ \frac{\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
add-sqr-sqrt [<=]99.7 | \[ \frac{\color{blue}{{x}^{-0.5}}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
+-commutative [<=]99.7 | \[ \frac{{x}^{-0.5}}{{x}^{-0.5} + {\color{blue}{\left(1 + x\right)}}^{-0.5}} \cdot \frac{\sqrt{\frac{1 + \left(x - x\right)}{x}}}{1 + x}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 26692 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 19968 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 13892 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 13888 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7172 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7044 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 6916 |
| Alternative 8 | |
|---|---|
| Accuracy | 51.5% |
| Cost | 6788 |
| Alternative 9 | |
|---|---|
| Accuracy | 52.0% |
| Cost | 6720 |
| Alternative 10 | |
|---|---|
| Accuracy | 50.0% |
| Cost | 6528 |
| Alternative 11 | |
|---|---|
| Accuracy | 4.0% |
| Cost | 192 |
| Alternative 12 | |
|---|---|
| Accuracy | 1.9% |
| Cost | 64 |
herbie shell --seed 2023146
(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)))))