
(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 (pow (pow (+ (sqrt (+ 1.0 x)) (sqrt x)) 2.0) -0.5))
double code(double x) {
return pow(pow((sqrt((1.0 + x)) + sqrt(x)), 2.0), -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((sqrt((1.0d0 + x)) + sqrt(x)) ** 2.0d0) ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow(Math.pow((Math.sqrt((1.0 + x)) + Math.sqrt(x)), 2.0), -0.5);
}
def code(x): return math.pow(math.pow((math.sqrt((1.0 + x)) + math.sqrt(x)), 2.0), -0.5)
function code(x) return (Float64(sqrt(Float64(1.0 + x)) + sqrt(x)) ^ 2.0) ^ -0.5 end
function tmp = code(x) tmp = ((sqrt((1.0 + x)) + sqrt(x)) ^ 2.0) ^ -0.5; end
code[x_] := N[Power[N[Power[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{2}\right)}^{-0.5}
\end{array}
Initial program 6.4%
flip--6.7%
div-inv6.7%
add-sqr-sqrt7.0%
add-sqr-sqrt8.0%
associate--l+8.0%
Applied egg-rr8.0%
associate-*r/8.0%
*-rgt-identity8.0%
associate-+r-8.0%
remove-double-neg8.0%
sub-neg8.0%
div-sub6.4%
rem-square-sqrt6.2%
sqr-neg6.2%
div-sub7.0%
+-commutative7.0%
sqr-neg7.0%
rem-square-sqrt8.0%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
Simplified99.5%
add-sqr-sqrt99.1%
sqrt-unprod99.5%
inv-pow99.5%
inv-pow99.5%
pow-prod-up99.5%
metadata-eval99.5%
Applied egg-rr99.5%
sqrt-pow199.5%
metadata-eval99.5%
metadata-eval99.5%
pow-prod-up99.2%
pow-prod-down99.6%
pow299.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (/ 1.0 (+ (sqrt (+ 1.0 x)) (sqrt x))))
double code(double x) {
return 1.0 / (sqrt((1.0 + x)) + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((1.0d0 + x)) + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((1.0 + x)) + Math.sqrt(x));
}
def code(x): return 1.0 / (math.sqrt((1.0 + x)) + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (sqrt((1.0 + x)) + sqrt(x)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\end{array}
Initial program 6.4%
flip--6.7%
div-inv6.7%
add-sqr-sqrt7.0%
add-sqr-sqrt8.0%
associate--l+8.0%
Applied egg-rr8.0%
associate-*r/8.0%
*-rgt-identity8.0%
associate-+r-8.0%
remove-double-neg8.0%
sub-neg8.0%
div-sub6.4%
rem-square-sqrt6.2%
sqr-neg6.2%
div-sub7.0%
+-commutative7.0%
sqr-neg7.0%
rem-square-sqrt8.0%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (* 0.5 (pow x -0.5)))
double code(double x) {
return 0.5 * pow(x, -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * (x ** (-0.5d0))
end function
public static double code(double x) {
return 0.5 * Math.pow(x, -0.5);
}
def code(x): return 0.5 * math.pow(x, -0.5)
function code(x) return Float64(0.5 * (x ^ -0.5)) end
function tmp = code(x) tmp = 0.5 * (x ^ -0.5); end
code[x_] := N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-0.5}
\end{array}
Initial program 6.4%
flip--6.7%
div-inv6.7%
add-sqr-sqrt7.0%
add-sqr-sqrt8.0%
associate--l+8.0%
Applied egg-rr8.0%
associate-*r/8.0%
*-rgt-identity8.0%
associate-+r-8.0%
remove-double-neg8.0%
sub-neg8.0%
div-sub6.4%
rem-square-sqrt6.2%
sqr-neg6.2%
div-sub7.0%
+-commutative7.0%
sqr-neg7.0%
rem-square-sqrt8.0%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
sub-neg99.5%
Simplified99.5%
flip3-+67.8%
associate-/r/67.7%
sqrt-pow267.7%
metadata-eval67.7%
sqrt-pow267.5%
metadata-eval67.5%
add-sqr-sqrt67.8%
add-sqr-sqrt67.5%
associate-+r-67.5%
sqrt-unprod47.1%
Applied egg-rr47.1%
associate-*l/47.2%
*-lft-identity47.2%
associate-+l+47.2%
associate--l+47.2%
count-247.2%
*-commutative47.2%
Simplified47.2%
Taylor expanded in x around inf 98.1%
*-un-lft-identity98.1%
inv-pow98.1%
sqrt-pow198.4%
metadata-eval98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 6.4%
Taylor expanded in x around inf 3.8%
Final simplification3.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.4%
Taylor expanded in x around 0 6.9%
Final simplification6.9%
(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 2024050
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))