
(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 4 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 (/ (+ (* (pow x -1.5) -0.375) (* 0.5 (sqrt (/ 1.0 x)))) x))
double code(double x) {
return ((pow(x, -1.5) * -0.375) + (0.5 * sqrt((1.0 / x)))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (((x ** (-1.5d0)) * (-0.375d0)) + (0.5d0 * sqrt((1.0d0 / x)))) / x
end function
public static double code(double x) {
return ((Math.pow(x, -1.5) * -0.375) + (0.5 * Math.sqrt((1.0 / x)))) / x;
}
def code(x): return ((math.pow(x, -1.5) * -0.375) + (0.5 * math.sqrt((1.0 / x)))) / x
function code(x) return Float64(Float64(Float64((x ^ -1.5) * -0.375) + Float64(0.5 * sqrt(Float64(1.0 / x)))) / x) end
function tmp = code(x) tmp = (((x ^ -1.5) * -0.375) + (0.5 * sqrt((1.0 / x)))) / x; end
code[x_] := N[(N[(N[(N[Power[x, -1.5], $MachinePrecision] * -0.375), $MachinePrecision] + N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-1.5} \cdot -0.375 + 0.5 \cdot \sqrt{\frac{1}{x}}}{x}
\end{array}
Initial program 34.1%
Taylor expanded in x around inf 80.9%
Taylor expanded in x around inf 98.9%
Simplified98.9%
Taylor expanded in x around inf 98.9%
associate-+r+98.9%
distribute-rgt-out98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in x around -inf 0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt98.9%
associate-*r*98.9%
metadata-eval98.9%
*-lft-identity98.9%
unpow-198.9%
exp-to-pow98.9%
*-commutative98.9%
exp-prod98.9%
*-commutative98.9%
associate-*r*98.9%
metadata-eval98.9%
*-commutative98.9%
exp-to-pow98.9%
metadata-eval98.9%
pow-sqr98.9%
rem-sqrt-square98.9%
rem-square-sqrt98.9%
fabs-sqr98.9%
rem-square-sqrt98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (/ (* 0.5 (- (sqrt (/ 1.0 x)) (pow x -1.5))) x))
double code(double x) {
return (0.5 * (sqrt((1.0 / x)) - pow(x, -1.5))) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * (sqrt((1.0d0 / x)) - (x ** (-1.5d0)))) / x
end function
public static double code(double x) {
return (0.5 * (Math.sqrt((1.0 / x)) - Math.pow(x, -1.5))) / x;
}
def code(x): return (0.5 * (math.sqrt((1.0 / x)) - math.pow(x, -1.5))) / x
function code(x) return Float64(Float64(0.5 * Float64(sqrt(Float64(1.0 / x)) - (x ^ -1.5))) / x) end
function tmp = code(x) tmp = (0.5 * (sqrt((1.0 / x)) - (x ^ -1.5))) / x; end
code[x_] := N[(N[(0.5 * N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] - N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \left(\sqrt{\frac{1}{x}} - {x}^{-1.5}\right)}{x}
\end{array}
Initial program 34.1%
Taylor expanded in x around inf 79.6%
distribute-lft-out--79.6%
Simplified79.6%
Taylor expanded in x around inf 97.6%
Simplified97.6%
Final simplification97.6%
(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 34.1%
Taylor expanded in x around inf 80.9%
Taylor expanded in x around inf 98.9%
Simplified98.9%
Taylor expanded in x around inf 97.5%
Final simplification97.5%
(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 34.1%
inv-pow34.1%
add-sqr-sqrt21.7%
unpow-prod-down18.8%
fma-neg7.8%
pow1/27.8%
sqrt-pow17.7%
metadata-eval7.7%
pow1/27.7%
sqrt-pow17.8%
metadata-eval7.8%
distribute-neg-frac7.8%
metadata-eval7.8%
+-commutative7.8%
Applied egg-rr7.8%
Taylor expanded in x around inf 30.7%
distribute-rgt1-in30.7%
metadata-eval30.7%
mul0-lft30.7%
Simplified30.7%
Final simplification30.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 2024053
(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)))))