
(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.5 (+ (pow x -0.5) (pow x -2.5))) (* (pow x -0.5) (/ 0.375 x))) x))
double code(double x) {
return ((0.5 * (pow(x, -0.5) + pow(x, -2.5))) - (pow(x, -0.5) * (0.375 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.5d0 * ((x ** (-0.5d0)) + (x ** (-2.5d0)))) - ((x ** (-0.5d0)) * (0.375d0 / x))) / x
end function
public static double code(double x) {
return ((0.5 * (Math.pow(x, -0.5) + Math.pow(x, -2.5))) - (Math.pow(x, -0.5) * (0.375 / x))) / x;
}
def code(x): return ((0.5 * (math.pow(x, -0.5) + math.pow(x, -2.5))) - (math.pow(x, -0.5) * (0.375 / x))) / x
function code(x) return Float64(Float64(Float64(0.5 * Float64((x ^ -0.5) + (x ^ -2.5))) - Float64((x ^ -0.5) * Float64(0.375 / x))) / x) end
function tmp = code(x) tmp = ((0.5 * ((x ^ -0.5) + (x ^ -2.5))) - ((x ^ -0.5) * (0.375 / x))) / x; end
code[x_] := N[(N[(N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[x, -2.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \left({x}^{-0.5} + {x}^{-2.5}\right) - {x}^{-0.5} \cdot \frac{0.375}{x}}{x}
\end{array}
Initial program 35.5%
Taylor expanded in x around inf 79.3%
Taylor expanded in x around 0 79.2%
unpow-179.2%
exp-to-pow79.2%
*-commutative79.2%
exp-prod79.2%
*-commutative79.2%
associate-*r*79.2%
metadata-eval79.2%
*-commutative79.2%
exp-to-pow79.2%
metadata-eval79.2%
pow-sqr79.2%
rem-sqrt-square79.2%
rem-square-sqrt79.2%
fabs-sqr79.2%
rem-square-sqrt79.2%
Simplified79.2%
Taylor expanded in x around inf 98.5%
Simplified98.5%
distribute-lft-in98.5%
pow-flip98.5%
sqrt-pow198.5%
metadata-eval98.5%
metadata-eval98.5%
Applied egg-rr98.5%
distribute-lft-in98.5%
Simplified98.5%
(FPCore (x) :precision binary64 (/ (- (* 0.5 (pow x -0.5)) (* (pow x -0.5) (/ 0.375 x))) x))
double code(double x) {
return ((0.5 * pow(x, -0.5)) - (pow(x, -0.5) * (0.375 / x))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.5d0 * (x ** (-0.5d0))) - ((x ** (-0.5d0)) * (0.375d0 / x))) / x
end function
public static double code(double x) {
return ((0.5 * Math.pow(x, -0.5)) - (Math.pow(x, -0.5) * (0.375 / x))) / x;
}
def code(x): return ((0.5 * math.pow(x, -0.5)) - (math.pow(x, -0.5) * (0.375 / x))) / x
function code(x) return Float64(Float64(Float64(0.5 * (x ^ -0.5)) - Float64((x ^ -0.5) * Float64(0.375 / x))) / x) end
function tmp = code(x) tmp = ((0.5 * (x ^ -0.5)) - ((x ^ -0.5) * (0.375 / x))) / x; end
code[x_] := N[(N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] - N[(N[Power[x, -0.5], $MachinePrecision] * N[(0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-0.5} - {x}^{-0.5} \cdot \frac{0.375}{x}}{x}
\end{array}
Initial program 35.5%
Taylor expanded in x around inf 79.3%
Taylor expanded in x around 0 79.2%
unpow-179.2%
exp-to-pow79.2%
*-commutative79.2%
exp-prod79.2%
*-commutative79.2%
associate-*r*79.2%
metadata-eval79.2%
*-commutative79.2%
exp-to-pow79.2%
metadata-eval79.2%
pow-sqr79.2%
rem-sqrt-square79.2%
rem-square-sqrt79.2%
fabs-sqr79.2%
rem-square-sqrt79.2%
Simplified79.2%
Taylor expanded in x around inf 98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (/ (* -0.5 (- (pow x -1.5) (pow x -0.5))) x))
double code(double x) {
return (-0.5 * (pow(x, -1.5) - pow(x, -0.5))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-0.5d0) * ((x ** (-1.5d0)) - (x ** (-0.5d0)))) / x
end function
public static double code(double x) {
return (-0.5 * (Math.pow(x, -1.5) - Math.pow(x, -0.5))) / x;
}
def code(x): return (-0.5 * (math.pow(x, -1.5) - math.pow(x, -0.5))) / x
function code(x) return Float64(Float64(-0.5 * Float64((x ^ -1.5) - (x ^ -0.5))) / x) end
function tmp = code(x) tmp = (-0.5 * ((x ^ -1.5) - (x ^ -0.5))) / x; end
code[x_] := N[(N[(-0.5 * N[(N[Power[x, -1.5], $MachinePrecision] - N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.5 \cdot \left({x}^{-1.5} - {x}^{-0.5}\right)}{x}
\end{array}
Initial program 35.5%
Taylor expanded in x around inf 77.9%
distribute-lft-out--77.9%
Simplified77.9%
*-commutative77.9%
unpow277.9%
times-frac97.0%
inv-pow97.0%
sqrt-pow197.0%
metadata-eval97.0%
Applied egg-rr97.0%
associate-*r/97.1%
div-sub97.1%
pow197.1%
pow-div97.1%
metadata-eval97.1%
pow1/297.1%
pow197.1%
pow-div97.2%
metadata-eval97.2%
Applied egg-rr97.2%
Final simplification97.2%
(FPCore (x) :precision binary64 (* (- (pow x -1.5) (pow x -0.5)) (/ -0.5 x)))
double code(double x) {
return (pow(x, -1.5) - pow(x, -0.5)) * (-0.5 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x ** (-1.5d0)) - (x ** (-0.5d0))) * ((-0.5d0) / x)
end function
public static double code(double x) {
return (Math.pow(x, -1.5) - Math.pow(x, -0.5)) * (-0.5 / x);
}
def code(x): return (math.pow(x, -1.5) - math.pow(x, -0.5)) * (-0.5 / x)
function code(x) return Float64(Float64((x ^ -1.5) - (x ^ -0.5)) * Float64(-0.5 / x)) end
function tmp = code(x) tmp = ((x ^ -1.5) - (x ^ -0.5)) * (-0.5 / x); end
code[x_] := N[(N[(N[Power[x, -1.5], $MachinePrecision] - N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left({x}^{-1.5} - {x}^{-0.5}\right) \cdot \frac{-0.5}{x}
\end{array}
Initial program 35.5%
Taylor expanded in x around inf 77.9%
distribute-lft-out--77.9%
Simplified77.9%
*-commutative77.9%
unpow277.9%
times-frac97.0%
inv-pow97.0%
sqrt-pow197.0%
metadata-eval97.0%
Applied egg-rr97.0%
div-sub97.0%
pow197.0%
pow-div97.0%
metadata-eval97.0%
pow1/297.0%
pow197.0%
pow-div97.2%
metadata-eval97.2%
Applied egg-rr97.2%
(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 35.5%
Taylor expanded in x around inf 77.9%
distribute-lft-out--77.9%
Simplified77.9%
*-commutative77.9%
unpow277.9%
times-frac97.0%
inv-pow97.0%
sqrt-pow197.0%
metadata-eval97.0%
Applied egg-rr97.0%
associate-*l/97.0%
Applied egg-rr97.0%
Taylor expanded in x around inf 97.0%
(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 / Float64(-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 35.5%
Taylor expanded in x around inf 77.9%
distribute-lft-out--77.9%
Simplified77.9%
*-commutative77.9%
unpow277.9%
times-frac97.0%
inv-pow97.0%
sqrt-pow197.0%
metadata-eval97.0%
Applied egg-rr97.0%
Taylor expanded in x around inf 96.9%
mul-1-neg96.9%
unpow1/296.9%
exp-to-pow92.8%
log-rec92.8%
distribute-lft-neg-out92.8%
distribute-rgt-neg-in92.8%
metadata-eval92.8%
exp-to-pow97.0%
Simplified97.0%
Final simplification97.0%
(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 35.5%
sub-neg35.5%
+-commutative35.5%
add-cube-cbrt13.5%
distribute-lft-neg-in13.5%
fma-define8.5%
Applied egg-rr8.9%
Taylor expanded in x around inf 31.7%
distribute-rgt1-in31.7%
metadata-eval31.7%
unpow-131.7%
metadata-eval31.7%
pow-sqr31.7%
rem-sqrt-square31.7%
metadata-eval31.7%
pow-sqr31.7%
fabs-sqr31.7%
pow-sqr31.7%
metadata-eval31.7%
mul0-lft31.7%
Simplified31.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 2024114
(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)))))