| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 32576 |
\[\frac{{\left(1 + x\right)}^{-0.5}}{\mathsf{fma}\left(\mathsf{hypot}\left(1, \sqrt{x}\right), \sqrt{x}, x\right)}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 0.0) (* 0.5 (pow x -1.5)) (/ (pow (+ 1.0 x) -0.5) (+ x (sqrt (* x (+ 1.0 x)))))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 0.0) {
tmp = 0.5 * pow(x, -1.5);
} else {
tmp = pow((1.0 + x), -0.5) / (x + sqrt((x * (1.0 + x))));
}
return tmp;
}
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
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 0.0d0) then
tmp = 0.5d0 * (x ** (-1.5d0))
else
tmp = ((1.0d0 + x) ** (-0.5d0)) / (x + sqrt((x * (1.0d0 + x))))
end if
code = tmp
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) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((1.0 + x)))) <= 0.0) {
tmp = 0.5 * Math.pow(x, -1.5);
} else {
tmp = Math.pow((1.0 + x), -0.5) / (x + Math.sqrt((x * (1.0 + x))));
}
return tmp;
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 0.0: tmp = 0.5 * math.pow(x, -1.5) else: tmp = math.pow((1.0 + x), -0.5) / (x + math.sqrt((x * (1.0 + x)))) return tmp
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 0.0) tmp = Float64(0.5 * (x ^ -1.5)); else tmp = Float64((Float64(1.0 + x) ^ -0.5) / Float64(x + sqrt(Float64(x * Float64(1.0 + x))))); end return tmp end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 0.0) tmp = 0.5 * (x ^ -1.5); else tmp = ((1.0 + x) ^ -0.5) / (x + sqrt((x * (1.0 + x)))); end tmp_2 = tmp; 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_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision] / N[(x + N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 0:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\left(1 + x\right)}^{-0.5}}{x + \sqrt{x \cdot \left(1 + x\right)}}\\
\end{array}
Results
| Original | 20.0 |
|---|---|
| Target | 0.6 |
| Herbie | 0.1 |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 0.0Initial program 40.0
Applied egg-rr40.0
Taylor expanded in x around inf 21.7
Applied egg-rr0.0
if 0.0 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 1.5
Applied egg-rr1.5
Applied egg-rr0.3
Applied egg-rr0.3
Applied egg-rr0.3
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 32576 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 26692 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 26688 |
| Alternative 4 | |
|---|---|
| Error | 0.9 |
| Cost | 7620 |
| Alternative 5 | |
|---|---|
| Error | 1.1 |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Error | 31.0 |
| Cost | 6656 |
| Alternative 7 | |
|---|---|
| Error | 62.6 |
| Cost | 6592 |
| Alternative 8 | |
|---|---|
| Error | 62.8 |
| Cost | 64 |

herbie shell --seed 2022309
(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)))))