| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 26308 |
\[\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 4 \cdot 10^{-6}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (sqrt (pow (+ (sqrt x) (sqrt (+ 1.0 x))) -2.0)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return sqrt(pow((sqrt(x) + sqrt((1.0 + x))), -2.0));
}
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 = sqrt(((sqrt(x) + sqrt((1.0d0 + x))) ** (-2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
return Math.sqrt(Math.pow((Math.sqrt(x) + Math.sqrt((1.0 + x))), -2.0));
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return math.sqrt(math.pow((math.sqrt(x) + math.sqrt((1.0 + x))), -2.0))
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return sqrt((Float64(sqrt(x) + sqrt(Float64(1.0 + x))) ^ -2.0)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp = code(x) tmp = sqrt(((sqrt(x) + sqrt((1.0 + x))) ^ -2.0)); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Sqrt[N[Power[N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]], $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\sqrt{{\left(\sqrt{x} + \sqrt{1 + x}\right)}^{-2}}
Results
| Original | 30.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
Initial program 30.3
Applied egg-rr29.6
Simplified0.2
[Start]29.6 | \[ \left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
|---|---|
associate-*r/ [=>]29.6 | \[ \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}}
\] |
*-rgt-identity [=>]29.6 | \[ \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]29.6 | \[ \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}}
\] |
associate-+l- [=>]0.2 | \[ \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-inverses [=>]0.2 | \[ \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}}
\] |
metadata-eval [=>]0.2 | \[ \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]0.2 | \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}}
\] |
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 26308 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Error | 1.2 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 1.9 |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Error | 31.5 |
| Cost | 64 |
herbie shell --seed 2023054
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))