| Alternative 1 | |
|---|---|
| Error | 99.5% |
| Cost | 13252.00 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 44000000:\\
\;\;\;\;\sqrt{1 + x} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\end{array}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) (hypot 1.0 (sqrt x)))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return 1.0 / (sqrt(x) + hypot(1.0, sqrt(x)));
}
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.hypot(1.0, Math.sqrt(x)));
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return 1.0 / (math.sqrt(x) + math.hypot(1.0, math.sqrt(x)))
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return Float64(1.0 / Float64(sqrt(x) + hypot(1.0, sqrt(x)))) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + hypot(1.0, sqrt(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[1.0 ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\frac{1}{\sqrt{x} + \mathsf{hypot}\left(1, \sqrt{x}\right)}
Results
| Original | 53.7% |
|---|---|
| Target | 99.7% |
| Herbie | 99.7% |
Initial program 53.7
Applied egg-rr54.7
Simplified99.7
[Start]54.7 | \[ \left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
|---|---|
associate-*r/ [=>]54.7 | \[ \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}}
\] |
*-rgt-identity [=>]54.7 | \[ \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]54.7 | \[ \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}}
\] |
associate-+l- [=>]99.7 | \[ \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-inverses [=>]99.7 | \[ \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}}
\] |
metadata-eval [=>]99.7 | \[ \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]99.7 | \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}}
\] |
Applied egg-rr99.7
Final simplification99.7
| Alternative 1 | |
|---|---|
| Error | 99.5% |
| Cost | 13252.00 |
| Alternative 2 | |
|---|---|
| Error | 99.7% |
| Cost | 13248.00 |
| Alternative 3 | |
|---|---|
| Error | 98.5% |
| Cost | 6980.00 |
| Alternative 4 | |
|---|---|
| Error | 97.9% |
| Cost | 6852.00 |
| Alternative 5 | |
|---|---|
| Error | 96.7% |
| Cost | 6788.00 |
| Alternative 6 | |
|---|---|
| Error | 51.5% |
| Cost | 64.00 |
herbie shell --seed 2023093
(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)))