
(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 40.3%
Taylor expanded in x around inf 78.5%
Taylor expanded in x around inf 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
*-commutative98.4%
distribute-rgt-out98.4%
metadata-eval98.4%
*-rgt-identity98.4%
times-frac98.4%
metadata-eval98.4%
Simplified98.4%
div-sub98.4%
Applied egg-rr98.7%
clear-num98.7%
un-div-inv98.7%
pow198.7%
pow-div98.7%
metadata-eval98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (/ (* 0.5 (sqrt (/ 1.0 x))) x))
double code(double x) {
return (0.5 * sqrt((1.0 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * sqrt((1.0d0 / x))) / x
end function
public static double code(double x) {
return (0.5 * Math.sqrt((1.0 / x))) / x;
}
def code(x): return (0.5 * math.sqrt((1.0 / x))) / x
function code(x) return Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) / x) end
function tmp = code(x) tmp = (0.5 * sqrt((1.0 / x))) / x; end
code[x_] := N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x}
\end{array}
Initial program 40.3%
Taylor expanded in x around inf 78.5%
Taylor expanded in x around inf 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
*-commutative98.4%
distribute-rgt-out98.4%
metadata-eval98.4%
*-rgt-identity98.4%
times-frac98.4%
metadata-eval98.4%
Simplified98.4%
inv-pow98.4%
sqrt-pow198.4%
metadata-eval98.4%
*-un-lft-identity98.4%
associate-*r/98.4%
add-sqr-sqrt98.4%
times-frac98.4%
metadata-eval98.4%
sqrt-div98.4%
inv-pow98.4%
sqrt-pow198.4%
metadata-eval98.4%
un-div-inv98.4%
metadata-eval98.4%
sqrt-div98.4%
inv-pow98.4%
sqrt-pow198.4%
metadata-eval98.4%
cube-unmult98.4%
*-un-lft-identity98.4%
pow-pow98.4%
metadata-eval98.4%
Applied egg-rr98.4%
*-lft-identity98.4%
Simplified98.4%
Taylor expanded in x around inf 97.1%
Final simplification97.1%
(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 40.3%
inv-pow40.3%
add-sqr-sqrt25.9%
unpow-prod-down22.8%
frac-2neg22.8%
metadata-eval22.8%
div-inv22.8%
distribute-neg-frac222.8%
prod-diff8.0%
Applied egg-rr8.0%
Simplified24.4%
flip--24.4%
Applied egg-rr40.5%
Taylor expanded in x around inf 65.7%
associate-/r*65.7%
metadata-eval65.7%
div-inv65.7%
metadata-eval65.7%
unpow365.7%
sqrt-prod77.1%
sqrt-unprod95.9%
add-sqr-sqrt96.2%
/-rgt-identity96.2%
frac-times97.0%
clear-num97.0%
metadata-eval97.0%
sqrt-div97.0%
associate-*l/97.1%
*-un-lft-identity97.1%
associate-/l*97.1%
*-commutative97.1%
associate-/l*97.0%
inv-pow97.0%
sqrt-pow197.1%
metadata-eval97.1%
Applied egg-rr97.1%
Final simplification97.1%
(FPCore (x) :precision binary64 (/ 0.5 (pow x 1.5)))
double code(double x) {
return 0.5 / pow(x, 1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 / (x ** 1.5d0)
end function
public static double code(double x) {
return 0.5 / Math.pow(x, 1.5);
}
def code(x): return 0.5 / math.pow(x, 1.5)
function code(x) return Float64(0.5 / (x ^ 1.5)) end
function tmp = code(x) tmp = 0.5 / (x ^ 1.5); end
code[x_] := N[(0.5 / N[Power[x, 1.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{{x}^{1.5}}
\end{array}
Initial program 40.3%
inv-pow40.3%
add-sqr-sqrt25.9%
unpow-prod-down22.8%
frac-2neg22.8%
metadata-eval22.8%
div-inv22.8%
distribute-neg-frac222.8%
prod-diff8.0%
Applied egg-rr8.0%
Simplified24.4%
flip--24.4%
Applied egg-rr40.5%
Taylor expanded in x around inf 65.7%
inv-pow65.7%
unpow-prod-down65.7%
metadata-eval65.7%
sqrt-pow196.3%
metadata-eval96.3%
Applied egg-rr96.3%
unpow-196.3%
associate-*r/96.3%
metadata-eval96.3%
Simplified96.3%
Final simplification96.3%
(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 40.3%
Taylor expanded in x around 0 5.7%
pow1/25.7%
inv-pow5.7%
pow-pow5.7%
metadata-eval5.7%
*-un-lft-identity5.7%
Applied egg-rr5.7%
*-lft-identity5.7%
Simplified5.7%
Final simplification5.7%
(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 2024068
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))