
(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 6 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.6%
flip--7.5%
div-inv7.5%
add-sqr-sqrt7.7%
add-sqr-sqrt8.4%
associate--l+8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
+-commutative8.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
inv-pow99.5%
sqr-pow99.1%
pow-prod-down99.6%
pow299.6%
metadata-eval99.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (x) :precision binary64 (pow (+ (sqrt (+ 1.0 x)) (sqrt x)) -1.0))
double code(double x) {
return pow((sqrt((1.0 + x)) + sqrt(x)), -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (sqrt((1.0d0 + x)) + sqrt(x)) ** (-1.0d0)
end function
public static double code(double x) {
return Math.pow((Math.sqrt((1.0 + x)) + Math.sqrt(x)), -1.0);
}
def code(x): return math.pow((math.sqrt((1.0 + x)) + math.sqrt(x)), -1.0)
function code(x) return Float64(sqrt(Float64(1.0 + x)) + sqrt(x)) ^ -1.0 end
function tmp = code(x) tmp = (sqrt((1.0 + x)) + sqrt(x)) ^ -1.0; end
code[x_] := N[Power[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\sqrt{1 + x} + \sqrt{x}\right)}^{-1}
\end{array}
Initial program 6.6%
flip--7.5%
div-inv7.5%
add-sqr-sqrt7.7%
add-sqr-sqrt8.4%
associate--l+8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
+-commutative8.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
inv-pow99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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.5%
div-inv7.5%
add-sqr-sqrt7.7%
add-sqr-sqrt8.4%
associate--l+8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
+-commutative8.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Final simplification99.5%
(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.6%
flip--7.5%
div-inv7.5%
add-sqr-sqrt7.7%
add-sqr-sqrt8.4%
associate--l+8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
+-commutative8.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
inv-pow99.5%
sqr-pow99.1%
pow-prod-down99.6%
pow299.6%
metadata-eval99.6%
Applied egg-rr99.6%
pow-pow99.5%
metadata-eval99.5%
inv-pow99.5%
flip3-+66.4%
associate-/r/66.4%
sqrt-pow266.3%
metadata-eval66.3%
sqrt-pow266.1%
metadata-eval66.1%
add-sqr-sqrt66.3%
add-sqr-sqrt66.2%
associate-+r-66.2%
Applied egg-rr47.9%
Taylor expanded in x around inf 98.0%
Final simplification98.0%
(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.5%
div-inv7.5%
add-sqr-sqrt7.7%
add-sqr-sqrt8.4%
associate--l+8.4%
Applied egg-rr8.4%
associate-*r/8.4%
*-rgt-identity8.4%
+-commutative8.4%
associate-+l-99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in x around 0 7.0%
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 2024040
(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)))