
(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 5 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.5 (pow x -1.5)) (/ 0.375 (pow x 2.5))))
double code(double x) {
return (0.5 * pow(x, -1.5)) - (0.375 / pow(x, 2.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * (x ** (-1.5d0))) - (0.375d0 / (x ** 2.5d0))
end function
public static double code(double x) {
return (0.5 * Math.pow(x, -1.5)) - (0.375 / Math.pow(x, 2.5));
}
def code(x): return (0.5 * math.pow(x, -1.5)) - (0.375 / math.pow(x, 2.5))
function code(x) return Float64(Float64(0.5 * (x ^ -1.5)) - Float64(0.375 / (x ^ 2.5))) end
function tmp = code(x) tmp = (0.5 * (x ^ -1.5)) - (0.375 / (x ^ 2.5)); end
code[x_] := N[(N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision] - N[(0.375 / N[Power[x, 2.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot {x}^{-1.5} - \frac{0.375}{{x}^{2.5}}
\end{array}
Initial program 38.8%
Taylor expanded in x around inf 81.0%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
*-commutative98.5%
distribute-rgt-out98.5%
metadata-eval98.5%
*-rgt-identity98.5%
times-frac98.5%
metadata-eval98.5%
Simplified98.5%
div-sub98.5%
Applied egg-rr98.9%
clear-num98.9%
un-div-inv98.9%
pow198.9%
pow-div98.9%
metadata-eval98.9%
Applied egg-rr98.9%
(FPCore (x) :precision binary64 (/ (* 0.5 (pow x -0.5)) x))
double code(double x) {
return (0.5 * pow(x, -0.5)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * (x ** (-0.5d0))) / x
end function
public static double code(double x) {
return (0.5 * Math.pow(x, -0.5)) / x;
}
def code(x): return (0.5 * math.pow(x, -0.5)) / x
function code(x) return Float64(Float64(0.5 * (x ^ -0.5)) / x) end
function tmp = code(x) tmp = (0.5 * (x ^ -0.5)) / x; end
code[x_] := N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-0.5}}{x}
\end{array}
Initial program 38.8%
Taylor expanded in x around inf 81.0%
Taylor expanded in x around inf 98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
*-commutative98.5%
distribute-rgt-out98.5%
metadata-eval98.5%
*-rgt-identity98.5%
times-frac98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around inf 97.8%
unpow1/297.8%
unpow-197.8%
exp-to-pow93.8%
*-commutative93.8%
neg-mul-193.8%
exp-prod93.8%
distribute-lft-neg-out93.8%
distribute-rgt-neg-in93.8%
metadata-eval93.8%
exp-to-pow97.8%
Simplified97.8%
(FPCore (x) :precision binary64 (* (pow x -0.5) (/ 0.5 x)))
double code(double x) {
return pow(x, -0.5) * (0.5 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) * (0.5d0 / x)
end function
public static double code(double x) {
return Math.pow(x, -0.5) * (0.5 / x);
}
def code(x): return math.pow(x, -0.5) * (0.5 / x)
function code(x) return Float64((x ^ -0.5) * Float64(0.5 / x)) end
function tmp = code(x) tmp = (x ^ -0.5) * (0.5 / x); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} \cdot \frac{0.5}{x}
\end{array}
Initial program 38.8%
Taylor expanded in x around inf 80.3%
distribute-lft-out--80.3%
Simplified80.3%
Taylor expanded in x around inf 80.2%
*-commutative80.2%
Simplified80.2%
unpow280.2%
times-frac97.7%
Applied egg-rr97.7%
pow1/297.7%
pow197.7%
pow-div97.8%
metadata-eval97.8%
*-un-lft-identity97.8%
Applied egg-rr97.8%
*-lft-identity97.8%
Simplified97.8%
(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 38.8%
flip--38.8%
frac-times22.9%
metadata-eval22.9%
add-sqr-sqrt20.9%
frac-times25.1%
metadata-eval25.1%
add-sqr-sqrt39.0%
+-commutative39.0%
inv-pow39.0%
sqrt-pow239.0%
metadata-eval39.0%
inv-pow39.0%
sqrt-pow239.0%
+-commutative39.0%
metadata-eval39.0%
Applied egg-rr39.0%
Taylor expanded in x around inf 37.8%
*-commutative37.8%
Simplified37.8%
Taylor expanded in x around 0 5.7%
(FPCore (x) :precision binary64 (pow x -0.5))
double code(double x) {
return pow(x, -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow(x, -0.5);
}
def code(x): return math.pow(x, -0.5)
function code(x) return x ^ -0.5 end
function tmp = code(x) tmp = x ^ -0.5; end
code[x_] := N[Power[x, -0.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5}
\end{array}
Initial program 38.8%
Taylor expanded in x around 0 5.6%
pow1/25.6%
inv-pow5.6%
pow-pow5.6%
metadata-eval5.6%
*-un-lft-identity5.6%
Applied egg-rr5.6%
*-lft-identity5.6%
Simplified5.6%
(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}
herbie shell --seed 2024165
(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))))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))