
(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 (+ (sqrt (+ 1.0 x)) (pow x 0.5))))
double code(double x) {
return 1.0 / (sqrt((1.0 + x)) + pow(x, 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (sqrt((1.0d0 + x)) + (x ** 0.5d0))
end function
public static double code(double x) {
return 1.0 / (Math.sqrt((1.0 + x)) + Math.pow(x, 0.5));
}
def code(x): return 1.0 / (math.sqrt((1.0 + x)) + math.pow(x, 0.5))
function code(x) return Float64(1.0 / Float64(sqrt(Float64(1.0 + x)) + (x ^ 0.5))) end
function tmp = code(x) tmp = 1.0 / (sqrt((1.0 + x)) + (x ^ 0.5)); end
code[x_] := N[(1.0 / N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{1 + x} + {x}^{0.5}}
\end{array}
Initial program 6.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.7%
add-sqr-sqrt8.7%
associate--l+8.7%
Applied egg-rr8.7%
+-commutative8.7%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
associate-*r/99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
+-commutative99.6%
add-sqr-sqrt99.3%
fma-def99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
+-commutative99.5%
Applied egg-rr99.5%
fma-udef99.4%
+-commutative99.4%
+-commutative99.4%
pow-sqr99.6%
metadata-eval99.6%
Simplified99.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.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.7%
add-sqr-sqrt8.7%
associate--l+8.7%
Applied egg-rr8.7%
+-commutative8.7%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
associate-*r/99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Final simplification99.6%
(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.6%
flip3--5.2%
div-inv5.2%
sqrt-pow25.4%
metadata-eval5.4%
sqrt-pow25.3%
metadata-eval5.3%
add-sqr-sqrt5.3%
add-sqr-sqrt5.3%
associate-+r+5.3%
sqrt-unprod5.3%
add-sqr-sqrt5.3%
pow25.3%
metadata-eval5.3%
Applied egg-rr5.3%
Taylor expanded in x around inf 98.0%
*-commutative98.0%
Simplified98.0%
expm1-log1p-u98.0%
expm1-udef8.2%
inv-pow8.2%
sqrt-pow18.2%
metadata-eval8.2%
Applied egg-rr8.2%
expm1-def98.2%
expm1-log1p98.2%
Simplified98.2%
Final simplification98.2%
(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.6%
flip--7.2%
div-inv7.2%
add-sqr-sqrt7.7%
add-sqr-sqrt8.7%
associate--l+8.7%
Applied egg-rr8.7%
+-commutative8.7%
associate-+l-99.6%
+-inverses99.6%
metadata-eval99.6%
associate-*r/99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
+-commutative99.6%
add-sqr-sqrt99.3%
fma-def99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
pow1/299.5%
sqrt-pow199.5%
metadata-eval99.5%
+-commutative99.5%
Applied egg-rr99.5%
Taylor expanded in x around 0 7.1%
*-commutative7.1%
Simplified7.1%
Taylor expanded in x around inf 7.0%
Final simplification7.0%
(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.6%
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 2024026
(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)))