| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 39296 |
\[\frac{{x}^{-0.25} \cdot \frac{{x}^{-0.25}}{\mathsf{hypot}\left(1, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{x + 1}}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 1e-20)
(/ (/ 1.0 (+ x 0.5)) (+ (sqrt x) t_0))
(- (pow x -0.5) (pow (+ x 1.0) -0.5)))))double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-20) {
tmp = (1.0 / (x + 0.5)) / (sqrt(x) + t_0);
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
}
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) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 1d-20) then
tmp = (1.0d0 / (x + 0.5d0)) / (sqrt(x) + t_0)
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
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 t_0 = Math.sqrt((x + 1.0));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 1e-20) {
tmp = (1.0 / (x + 0.5)) / (Math.sqrt(x) + t_0);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
return tmp;
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 1e-20: tmp = (1.0 / (x + 0.5)) / (math.sqrt(x) + t_0) else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) return tmp
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 1e-20) tmp = Float64(Float64(1.0 / Float64(x + 0.5)) / Float64(sqrt(x) + t_0)); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); 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) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 1e-20) tmp = (1.0 / (x + 0.5)) / (sqrt(x) + t_0); else tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); 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_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 1e-20], N[(N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 10^{-20}:\\
\;\;\;\;\frac{\frac{1}{x + 0.5}}{\sqrt{x} + t_0}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
Results
| Original | 20.0 |
|---|---|
| Target | 0.6 |
| Herbie | 0.6 |
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 9.99999999999999945e-21Initial program 40.2
Applied egg-rr11.4
Simplified11.4
[Start]11.4 | \[ \frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{x + 1}\right)}
\] |
|---|---|
associate-/r* [=>]11.4 | \[ \color{blue}{\frac{\frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{x + 1}}}
\] |
+-commutative [=>]11.4 | \[ \frac{\frac{\color{blue}{\left(x - x\right) + 1}}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{x + 1}}
\] |
+-inverses [=>]11.4 | \[ \frac{\frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{x + 1}}
\] |
metadata-eval [=>]11.4 | \[ \frac{\frac{\color{blue}{1}}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{x + 1}}
\] |
+-commutative [=>]11.4 | \[ \frac{\frac{1}{\sqrt{x + x \cdot x}}}{\sqrt{x} + \sqrt{\color{blue}{1 + x}}}
\] |
Taylor expanded in x around inf 0.2
Simplified0.2
[Start]0.2 | \[ \frac{\frac{1}{0.5 + x}}{\sqrt{x} + \sqrt{1 + x}}
\] |
|---|---|
+-commutative [=>]0.2 | \[ \frac{\frac{1}{\color{blue}{x + 0.5}}}{\sqrt{x} + \sqrt{1 + x}}
\] |
if 9.99999999999999945e-21 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 1.2
Applied egg-rr1.2
Applied egg-rr0.9
Final simplification0.6
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 39296 |
| Alternative 2 | |
|---|---|
| Error | 0.5 |
| Cost | 33088 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 13508 |
| Alternative 4 | |
|---|---|
| Error | 0.4 |
| Cost | 13508 |
| Alternative 5 | |
|---|---|
| Error | 19.7 |
| Cost | 7232 |
| Alternative 6 | |
|---|---|
| Error | 21.5 |
| Cost | 6848 |
| Alternative 7 | |
|---|---|
| Error | 30.1 |
| Cost | 6788 |
| Alternative 8 | |
|---|---|
| Error | 59.3 |
| Cost | 320 |
| Alternative 9 | |
|---|---|
| Error | 59.3 |
| Cost | 192 |
| Alternative 10 | |
|---|---|
| Error | 60.3 |
| Cost | 64 |
herbie shell --seed 2023011
(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)))))