
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); 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]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); 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]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (- (* 0.3125 (pow x -3.5)) (fma 0.375 (pow x -2.5) (* -0.5 (pow x -1.5)))))
double code(double x) {
return (0.3125 * pow(x, -3.5)) - fma(0.375, pow(x, -2.5), (-0.5 * pow(x, -1.5)));
}
function code(x) return Float64(Float64(0.3125 * (x ^ -3.5)) - fma(0.375, (x ^ -2.5), Float64(-0.5 * (x ^ -1.5)))) end
code[x_] := N[(N[(0.3125 * N[Power[x, -3.5], $MachinePrecision]), $MachinePrecision] - N[(0.375 * N[Power[x, -2.5], $MachinePrecision] + N[(-0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3125 \cdot {x}^{-3.5} - \mathsf{fma}\left(0.375, {x}^{-2.5}, -0.5 \cdot {x}^{-1.5}\right)
\end{array}
Initial program 39.4%
add-exp-log6.8%
log-rec6.8%
pow1/26.8%
log-pow6.8%
+-commutative6.8%
log1p-define6.8%
Applied egg-rr6.8%
Taylor expanded in x around inf 6.0%
associate--r+6.8%
Simplified98.4%
+-lft-identity98.4%
associate--l+98.4%
+-rgt-identity98.4%
associate-/l*98.4%
pow-div98.4%
metadata-eval98.4%
pow-pow99.1%
metadata-eval99.1%
pow-div99.1%
metadata-eval99.1%
Applied egg-rr99.1%
+-lft-identity99.1%
fma-define99.1%
+-commutative99.1%
*-commutative99.1%
fma-define99.1%
Simplified99.1%
(FPCore (x)
:precision binary64
(*
(/
(+
(+ 0.5 (/ 0.0625 (pow x 2.0)))
(+ (* 0.125 (/ -1.0 x)) (* 0.0390625 (/ -1.0 (pow x 3.0)))))
x)
(pow (+ x 1.0) -0.5)))
double code(double x) {
return (((0.5 + (0.0625 / pow(x, 2.0))) + ((0.125 * (-1.0 / x)) + (0.0390625 * (-1.0 / pow(x, 3.0))))) / x) * pow((x + 1.0), -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((0.5d0 + (0.0625d0 / (x ** 2.0d0))) + ((0.125d0 * ((-1.0d0) / x)) + (0.0390625d0 * ((-1.0d0) / (x ** 3.0d0))))) / x) * ((x + 1.0d0) ** (-0.5d0))
end function
public static double code(double x) {
return (((0.5 + (0.0625 / Math.pow(x, 2.0))) + ((0.125 * (-1.0 / x)) + (0.0390625 * (-1.0 / Math.pow(x, 3.0))))) / x) * Math.pow((x + 1.0), -0.5);
}
def code(x): return (((0.5 + (0.0625 / math.pow(x, 2.0))) + ((0.125 * (-1.0 / x)) + (0.0390625 * (-1.0 / math.pow(x, 3.0))))) / x) * math.pow((x + 1.0), -0.5)
function code(x) return Float64(Float64(Float64(Float64(0.5 + Float64(0.0625 / (x ^ 2.0))) + Float64(Float64(0.125 * Float64(-1.0 / x)) + Float64(0.0390625 * Float64(-1.0 / (x ^ 3.0))))) / x) * (Float64(x + 1.0) ^ -0.5)) end
function tmp = code(x) tmp = (((0.5 + (0.0625 / (x ^ 2.0))) + ((0.125 * (-1.0 / x)) + (0.0390625 * (-1.0 / (x ^ 3.0))))) / x) * ((x + 1.0) ^ -0.5); end
code[x_] := N[(N[(N[(N[(0.5 + N[(0.0625 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.125 * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] + N[(0.0390625 * N[(-1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(0.5 + \frac{0.0625}{{x}^{2}}\right) + \left(0.125 \cdot \frac{-1}{x} + 0.0390625 \cdot \frac{-1}{{x}^{3}}\right)}{x} \cdot {\left(x + 1\right)}^{-0.5}
\end{array}
Initial program 39.4%
frac-sub39.4%
div-inv39.4%
*-un-lft-identity39.4%
*-rgt-identity39.4%
+-commutative39.4%
metadata-eval39.4%
frac-times39.4%
associate-*l/39.4%
*-un-lft-identity39.4%
inv-pow39.4%
sqrt-pow239.4%
+-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
associate-*r/39.4%
*-rgt-identity39.4%
times-frac39.4%
div-sub39.4%
sub-neg39.4%
*-inverses39.4%
metadata-eval39.4%
/-rgt-identity39.4%
Simplified39.4%
Taylor expanded in x around inf 99.0%
Final simplification99.0%
(FPCore (x)
:precision binary64
(*
(pow (+ x 1.0) -0.5)
(/
(-
(+ (/ 0.0625 (pow x 2.0)) (+ 0.5 (/ -0.125 x)))
(/ 0.0390625 (pow x 3.0)))
x)))
double code(double x) {
return pow((x + 1.0), -0.5) * ((((0.0625 / pow(x, 2.0)) + (0.5 + (-0.125 / x))) - (0.0390625 / pow(x, 3.0))) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x + 1.0d0) ** (-0.5d0)) * ((((0.0625d0 / (x ** 2.0d0)) + (0.5d0 + ((-0.125d0) / x))) - (0.0390625d0 / (x ** 3.0d0))) / x)
end function
public static double code(double x) {
return Math.pow((x + 1.0), -0.5) * ((((0.0625 / Math.pow(x, 2.0)) + (0.5 + (-0.125 / x))) - (0.0390625 / Math.pow(x, 3.0))) / x);
}
def code(x): return math.pow((x + 1.0), -0.5) * ((((0.0625 / math.pow(x, 2.0)) + (0.5 + (-0.125 / x))) - (0.0390625 / math.pow(x, 3.0))) / x)
function code(x) return Float64((Float64(x + 1.0) ^ -0.5) * Float64(Float64(Float64(Float64(0.0625 / (x ^ 2.0)) + Float64(0.5 + Float64(-0.125 / x))) - Float64(0.0390625 / (x ^ 3.0))) / x)) end
function tmp = code(x) tmp = ((x + 1.0) ^ -0.5) * ((((0.0625 / (x ^ 2.0)) + (0.5 + (-0.125 / x))) - (0.0390625 / (x ^ 3.0))) / x); end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] * N[(N[(N[(N[(0.0625 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(-0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.0390625 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{-0.5} \cdot \frac{\left(\frac{0.0625}{{x}^{2}} + \left(0.5 + \frac{-0.125}{x}\right)\right) - \frac{0.0390625}{{x}^{3}}}{x}
\end{array}
Initial program 39.4%
frac-sub39.4%
div-inv39.4%
*-un-lft-identity39.4%
*-rgt-identity39.4%
+-commutative39.4%
metadata-eval39.4%
frac-times39.4%
associate-*l/39.4%
*-un-lft-identity39.4%
inv-pow39.4%
sqrt-pow239.4%
+-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
associate-*r/39.4%
*-rgt-identity39.4%
times-frac39.4%
div-sub39.4%
sub-neg39.4%
*-inverses39.4%
metadata-eval39.4%
/-rgt-identity39.4%
Simplified39.4%
Taylor expanded in x around inf 99.0%
associate--r+99.0%
+-commutative99.0%
associate--l+99.0%
sub-neg99.0%
associate-*r/99.0%
metadata-eval99.0%
distribute-neg-frac99.0%
metadata-eval99.0%
associate-*r/99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (* (pow (+ x 1.0) -0.5) (/ (+ (/ 0.0625 (pow x 2.0)) (+ 0.5 (/ -0.125 x))) x)))
double code(double x) {
return pow((x + 1.0), -0.5) * (((0.0625 / pow(x, 2.0)) + (0.5 + (-0.125 / x))) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x + 1.0d0) ** (-0.5d0)) * (((0.0625d0 / (x ** 2.0d0)) + (0.5d0 + ((-0.125d0) / x))) / x)
end function
public static double code(double x) {
return Math.pow((x + 1.0), -0.5) * (((0.0625 / Math.pow(x, 2.0)) + (0.5 + (-0.125 / x))) / x);
}
def code(x): return math.pow((x + 1.0), -0.5) * (((0.0625 / math.pow(x, 2.0)) + (0.5 + (-0.125 / x))) / x)
function code(x) return Float64((Float64(x + 1.0) ^ -0.5) * Float64(Float64(Float64(0.0625 / (x ^ 2.0)) + Float64(0.5 + Float64(-0.125 / x))) / x)) end
function tmp = code(x) tmp = ((x + 1.0) ^ -0.5) * (((0.0625 / (x ^ 2.0)) + (0.5 + (-0.125 / x))) / x); end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] * N[(N[(N[(0.0625 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(-0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{-0.5} \cdot \frac{\frac{0.0625}{{x}^{2}} + \left(0.5 + \frac{-0.125}{x}\right)}{x}
\end{array}
Initial program 39.4%
frac-sub39.4%
div-inv39.4%
*-un-lft-identity39.4%
*-rgt-identity39.4%
+-commutative39.4%
metadata-eval39.4%
frac-times39.4%
associate-*l/39.4%
*-un-lft-identity39.4%
inv-pow39.4%
sqrt-pow239.4%
+-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
associate-*r/39.4%
*-rgt-identity39.4%
times-frac39.4%
div-sub39.4%
sub-neg39.4%
*-inverses39.4%
metadata-eval39.4%
/-rgt-identity39.4%
Simplified39.4%
Taylor expanded in x around inf 98.8%
+-commutative98.8%
associate--l+98.9%
sub-neg98.9%
associate-*r/98.9%
metadata-eval98.9%
distribute-neg-frac98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (* (pow (+ x 1.0) -0.5) (/ (- 0.5 (/ 0.125 x)) x)))
double code(double x) {
return pow((x + 1.0), -0.5) * ((0.5 - (0.125 / x)) / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x + 1.0d0) ** (-0.5d0)) * ((0.5d0 - (0.125d0 / x)) / x)
end function
public static double code(double x) {
return Math.pow((x + 1.0), -0.5) * ((0.5 - (0.125 / x)) / x);
}
def code(x): return math.pow((x + 1.0), -0.5) * ((0.5 - (0.125 / x)) / x)
function code(x) return Float64((Float64(x + 1.0) ^ -0.5) * Float64(Float64(0.5 - Float64(0.125 / x)) / x)) end
function tmp = code(x) tmp = ((x + 1.0) ^ -0.5) * ((0.5 - (0.125 / x)) / x); end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(x + 1\right)}^{-0.5} \cdot \frac{0.5 - \frac{0.125}{x}}{x}
\end{array}
Initial program 39.4%
frac-sub39.4%
div-inv39.4%
*-un-lft-identity39.4%
*-rgt-identity39.4%
+-commutative39.4%
metadata-eval39.4%
frac-times39.4%
associate-*l/39.4%
*-un-lft-identity39.4%
inv-pow39.4%
sqrt-pow239.4%
+-commutative39.4%
metadata-eval39.4%
Applied egg-rr39.4%
associate-*r/39.4%
*-rgt-identity39.4%
times-frac39.4%
div-sub39.4%
sub-neg39.4%
*-inverses39.4%
metadata-eval39.4%
/-rgt-identity39.4%
Simplified39.4%
Taylor expanded in x around inf 98.6%
associate-*r/98.6%
metadata-eval98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x) :precision binary64 (* (pow x -1.5) 0.5))
double code(double x) {
return pow(x, -1.5) * 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-1.5d0)) * 0.5d0
end function
public static double code(double x) {
return Math.pow(x, -1.5) * 0.5;
}
def code(x): return math.pow(x, -1.5) * 0.5
function code(x) return Float64((x ^ -1.5) * 0.5) end
function tmp = code(x) tmp = (x ^ -1.5) * 0.5; end
code[x_] := N[(N[Power[x, -1.5], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5} \cdot 0.5
\end{array}
Initial program 39.4%
add-exp-log6.8%
log-rec6.8%
pow1/26.8%
log-pow6.8%
+-commutative6.8%
log1p-define6.8%
Applied egg-rr6.8%
Taylor expanded in x around inf 5.7%
+-commutative5.7%
distribute-lft-neg-in5.7%
metadata-eval5.7%
*-commutative5.7%
exp-to-pow38.3%
unpow1/238.3%
associate--l+93.6%
Simplified97.4%
+-rgt-identity97.4%
*-commutative97.4%
pow-pow98.1%
metadata-eval98.1%
Applied egg-rr98.1%
(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 39.4%
add-exp-log6.8%
log-rec6.8%
pow1/26.8%
log-pow6.8%
+-commutative6.8%
log1p-define6.8%
Applied egg-rr6.8%
Taylor expanded in x around inf 4.5%
distribute-lft-neg-in4.5%
metadata-eval4.5%
*-commutative4.5%
exp-to-pow36.9%
unpow1/236.9%
+-inverses36.9%
Simplified36.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (- (pow x -0.5) (pow (+ x 1.0) -0.5)))
double code(double x) {
return pow(x, -0.5) - pow((x + 1.0), -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end function
public static double code(double x) {
return Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
def code(x): return math.pow(x, -0.5) - math.pow((x + 1.0), -0.5)
function code(x) return Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)) end
function tmp = code(x) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}
\end{array}
herbie shell --seed 2024172
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (+ x 1) (sqrt x)) (* x (sqrt (+ x 1))))))
:alt
(! :herbie-platform default (- (pow x -1/2) (pow (+ x 1) -1/2)))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))