| 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 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x)))) (if (<= t_0 0.0) (* 0.5 (pow x -0.5)) t_0)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
double t_0 = sqrt((1.0 + x)) - sqrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = 0.5 * pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x)) - sqrt(x)
if (t_0 <= 0.0d0) then
tmp = 0.5d0 * (x ** (-0.5d0))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = 0.5 * Math.pow(x, -0.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): t_0 = math.sqrt((1.0 + x)) - math.sqrt(x) tmp = 0 if t_0 <= 0.0: tmp = 0.5 * math.pow(x, -0.5) else: tmp = t_0 return tmp
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(0.5 * (x ^ -0.5)); else tmp = t_0; end return tmp end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)) - sqrt(x); tmp = 0.0; if (t_0 <= 0.0) tmp = 0.5 * (x ^ -0.5); else tmp = t_0; end tmp_2 = tmp; end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 53.5% |
|---|---|
| Target | 99.7% |
| Herbie | 99.0% |
if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 0.0Initial program 3.9%
Applied egg-rr3.9%
Simplified99.6%
[Start]3.9 | \[ \left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}
\] |
|---|---|
associate-*r/ [=>]3.9 | \[ \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}}
\] |
*-rgt-identity [=>]3.9 | \[ \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]3.9 | \[ \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}}
\] |
associate-+l- [=>]99.6 | \[ \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-inverses [=>]99.6 | \[ \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}}
\] |
metadata-eval [=>]99.6 | \[ \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}
\] |
+-commutative [=>]99.6 | \[ \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}}
\] |
Applied egg-rr46.6%
Taylor expanded in x around inf 99.8%
Applied egg-rr5.7%
Simplified100.0%
[Start]5.7 | \[ 0.5 \cdot \left(\left(1 + {x}^{-0.5}\right) - 1\right)
\] |
|---|---|
+-commutative [=>]5.7 | \[ 0.5 \cdot \left(\color{blue}{\left({x}^{-0.5} + 1\right)} - 1\right)
\] |
associate--l+ [=>]100.0 | \[ 0.5 \cdot \color{blue}{\left({x}^{-0.5} + \left(1 - 1\right)\right)}
\] |
metadata-eval [=>]100.0 | \[ 0.5 \cdot \left({x}^{-0.5} + \color{blue}{0}\right)
\] |
+-rgt-identity [=>]100.0 | \[ 0.5 \cdot \color{blue}{{x}^{-0.5}}
\] |
if 0.0 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) Initial program 98.1%
Final simplification99.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 6980 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Accuracy | 96.7% |
| Cost | 6788 |
| Alternative 5 | |
|---|---|
| Accuracy | 51.2% |
| Cost | 64 |
herbie shell --seed 2023129
(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)))