
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x + 1} - \sqrt{x}
\end{array}
(FPCore (x) :precision binary64 (/ 1.0 (+ (/ 1.0 (pow (+ 1.0 x) -0.5)) (sqrt x))))
double code(double x) {
return 1.0 / ((1.0 / pow((1.0 + x), -0.5)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / ((1.0d0 / ((1.0d0 + x) ** (-0.5d0))) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / ((1.0 / Math.pow((1.0 + x), -0.5)) + Math.sqrt(x));
}
def code(x): return 1.0 / ((1.0 / math.pow((1.0 + x), -0.5)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(Float64(1.0 / (Float64(1.0 + x) ^ -0.5)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / ((1.0 / ((1.0 + x) ^ -0.5)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[(1.0 / N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{1}{{\left(1 + x\right)}^{-0.5}} + \sqrt{x}}
\end{array}
Initial program 6.0%
flip--6.4%
div-inv6.4%
add-sqr-sqrt6.9%
+-commutative6.9%
add-sqr-sqrt7.7%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
add099.6%
flip-+99.6%
metadata-eval99.6%
fma-neg99.6%
metadata-eval99.6%
fma-define99.6%
add099.6%
add-sqr-sqrt99.5%
*-un-lft-identity99.5%
fma-neg99.5%
metadata-eval99.5%
fma-define99.5%
*-un-lft-identity99.5%
add099.5%
Applied egg-rr99.5%
clear-num99.5%
inv-pow99.5%
pow1/299.5%
pow199.5%
pow-div99.7%
metadata-eval99.7%
Applied egg-rr99.7%
unpow-199.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
return 1.0 / (sqrt(x) + sqrt((1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return 1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x} + \sqrt{1 + x}}
\end{array}
Initial program 6.0%
flip--6.4%
div-inv6.4%
add-sqr-sqrt6.9%
+-commutative6.9%
add-sqr-sqrt7.7%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (* 0.5 (sqrt (/ 1.0 x))))
double code(double x) {
return 0.5 * sqrt((1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * sqrt((1.0d0 / x))
end function
public static double code(double x) {
return 0.5 * Math.sqrt((1.0 / x));
}
def code(x): return 0.5 * math.sqrt((1.0 / x))
function code(x) return Float64(0.5 * sqrt(Float64(1.0 / x))) end
function tmp = code(x) tmp = 0.5 * sqrt((1.0 / x)); end
code[x_] := N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{\frac{1}{x}}
\end{array}
Initial program 6.0%
flip--6.4%
div-inv6.4%
add-sqr-sqrt6.9%
+-commutative6.9%
add-sqr-sqrt7.7%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
add-sqr-sqrt99.1%
sqrt-unprod99.6%
inv-pow99.6%
inv-pow99.6%
pow-prod-up99.5%
metadata-eval99.5%
Applied egg-rr99.5%
sqrt-pow199.6%
metadata-eval99.6%
inv-pow99.6%
flip3-+62.2%
associate-/r/62.2%
sqrt-pow262.1%
metadata-eval62.1%
sqrt-pow262.0%
metadata-eval62.0%
add-sqr-sqrt62.3%
add-sqr-sqrt62.1%
associate-+r-62.1%
Applied egg-rr44.4%
Taylor expanded in x around inf 98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (/ 2.0 x))
double code(double x) {
return 2.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / x
end function
public static double code(double x) {
return 2.0 / x;
}
def code(x): return 2.0 / x
function code(x) return Float64(2.0 / x) end
function tmp = code(x) tmp = 2.0 / x; end
code[x_] := N[(2.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{x}
\end{array}
Initial program 6.0%
flip--6.4%
div-inv6.4%
add-sqr-sqrt6.9%
+-commutative6.9%
add-sqr-sqrt7.7%
associate--l+99.6%
Applied egg-rr99.6%
+-inverses99.6%
metadata-eval99.6%
*-lft-identity99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 6.8%
Taylor expanded in x around inf 6.8%
Final simplification6.8%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 6.0%
Taylor expanded in x around 0 6.7%
Final simplification6.7%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((x + 1.0)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((x + 1.0d0)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((x + 1.0)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((x + 1.0)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(x + 1.0)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((x + 1.0)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x + 1} + \sqrt{x}}
\end{array}
herbie shell --seed 2024034
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))