| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 13248 |
\[\frac{1}{\sqrt{x} + \sqrt{1 + x}}
\]

(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return 1.0 / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{1}{\sqrt{x} + \sqrt{1 + x}}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 52.5% |
|---|---|
| Target | 99.7% |
| Herbie | 99.7% |
Initial program 48.6%
Applied egg-rr49.6%
[Start]48.6% | \[ \sqrt{x + 1} - \sqrt{x}
\] |
|---|---|
flip-- [=>]49.0% | \[ \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}}
\] |
div-inv [=>]49.0% | \[ \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}}
\] |
add-sqr-sqrt [<=]49.2% | \[ \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
add-sqr-sqrt [<=]49.6% | \[ \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
Simplified99.7%
[Start]49.6% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
|---|---|
*-commutative [=>]49.6% | \[ \color{blue}{\frac{1}{\sqrt{x + 1} + \sqrt{x}} \cdot \left(\left(x + 1\right) - x\right)}
\] |
associate-/r/ [<=]49.6% | \[ \color{blue}{\frac{1}{\frac{\sqrt{x + 1} + \sqrt{x}}{\left(x + 1\right) - x}}}
\] |
+-commutative [=>]49.6% | \[ \frac{1}{\frac{\sqrt{x + 1} + \sqrt{x}}{\color{blue}{\left(1 + x\right)} - x}}
\] |
associate--l+ [=>]99.7% | \[ \frac{1}{\frac{\sqrt{x + 1} + \sqrt{x}}{\color{blue}{1 + \left(x - x\right)}}}
\] |
+-inverses [=>]99.7% | \[ \frac{1}{\frac{\sqrt{x + 1} + \sqrt{x}}{1 + \color{blue}{0}}}
\] |
metadata-eval [=>]99.7% | \[ \frac{1}{\frac{\sqrt{x + 1} + \sqrt{x}}{\color{blue}{1}}}
\] |
/-rgt-identity [=>]99.7% | \[ \frac{1}{\color{blue}{\sqrt{x + 1} + \sqrt{x}}}
\] |
+-commutative [=>]99.7% | \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.5% |
| Cost | 26308 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.0% |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.9% |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 6724 |
| Alternative 7 | |
|---|---|
| Accuracy | 50.5% |
| Cost | 64 |
herbie shell --seed 2023271
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))