
(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 (/ (/ 1.0 (+ (sqrt x) (sqrt (+ 1.0 x)))) (* x (- (/ (- 0.5 (/ 0.125 x)) x) -1.0))))
double code(double x) {
return (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / (sqrt(x) + sqrt((1.0d0 + x)))) / (x * (((0.5d0 - (0.125d0 / x)) / x) - (-1.0d0)))
end function
public static double code(double x) {
return (1.0 / (Math.sqrt(x) + Math.sqrt((1.0 + x)))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
def code(x): return (1.0 / (math.sqrt(x) + math.sqrt((1.0 + x)))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0))
function code(x) return Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) / Float64(x * Float64(Float64(Float64(0.5 - Float64(0.125 / x)) / x) - -1.0))) end
function tmp = code(x) tmp = (1.0 / (sqrt(x) + sqrt((1.0 + x)))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0)); end
code[x_] := N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[(N[(0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}{x \cdot \left(\frac{0.5 - \frac{0.125}{x}}{x} - -1\right)}
\end{array}
Initial program 38.5%
frac-sub38.5%
*-rgt-identity38.5%
*-un-lft-identity38.5%
+-commutative38.5%
sqrt-unprod38.5%
+-commutative38.5%
Applied egg-rr38.5%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
distribute-rgt-neg-in0.0%
Simplified38.5%
flip--39.1%
add-sqr-sqrt22.5%
add-sqr-sqrt39.7%
Applied egg-rr39.7%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (/ (- (* 0.5 (pow x -0.5)) (* (pow x -1.5) 0.375)) x))
double code(double x) {
return ((0.5 * pow(x, -0.5)) - (pow(x, -1.5) * 0.375)) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.5d0 * (x ** (-0.5d0))) - ((x ** (-1.5d0)) * 0.375d0)) / x
end function
public static double code(double x) {
return ((0.5 * Math.pow(x, -0.5)) - (Math.pow(x, -1.5) * 0.375)) / x;
}
def code(x): return ((0.5 * math.pow(x, -0.5)) - (math.pow(x, -1.5) * 0.375)) / x
function code(x) return Float64(Float64(Float64(0.5 * (x ^ -0.5)) - Float64((x ^ -1.5) * 0.375)) / x) end
function tmp = code(x) tmp = ((0.5 * (x ^ -0.5)) - ((x ^ -1.5) * 0.375)) / x; end
code[x_] := N[(N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] - N[(N[Power[x, -1.5], $MachinePrecision] * 0.375), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-0.5} - {x}^{-1.5} \cdot 0.375}{x}
\end{array}
Initial program 38.5%
Taylor expanded in x around inf 80.9%
Taylor expanded in x around inf 99.3%
Simplified99.3%
*-un-lft-identity99.3%
pow-pow99.3%
metadata-eval99.3%
Applied egg-rr99.3%
*-lft-identity99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (/ (* 0.5 (sqrt (/ 1.0 x))) (* x (- (/ (- 0.5 (/ 0.125 x)) x) -1.0))))
double code(double x) {
return (0.5 * sqrt((1.0 / x))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * sqrt((1.0d0 / x))) / (x * (((0.5d0 - (0.125d0 / x)) / x) - (-1.0d0)))
end function
public static double code(double x) {
return (0.5 * Math.sqrt((1.0 / x))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
def code(x): return (0.5 * math.sqrt((1.0 / x))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0))
function code(x) return Float64(Float64(0.5 * sqrt(Float64(1.0 / x))) / Float64(x * Float64(Float64(Float64(0.5 - Float64(0.125 / x)) / x) - -1.0))) end
function tmp = code(x) tmp = (0.5 * sqrt((1.0 / x))) / (x * (((0.5 - (0.125 / x)) / x) - -1.0)); end
code[x_] := N[(N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[(N[(0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{x \cdot \left(\frac{0.5 - \frac{0.125}{x}}{x} - -1\right)}
\end{array}
Initial program 38.5%
frac-sub38.5%
*-rgt-identity38.5%
*-un-lft-identity38.5%
+-commutative38.5%
sqrt-unprod38.5%
+-commutative38.5%
Applied egg-rr38.5%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
distribute-rgt-neg-in0.0%
Simplified38.5%
Taylor expanded in x around inf 98.6%
*-commutative98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x) :precision binary64 (/ (* 0.5 (pow x -0.5)) (* x (- (/ (- 0.5 (/ 0.125 x)) x) -1.0))))
double code(double x) {
return (0.5 * pow(x, -0.5)) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (0.5d0 * (x ** (-0.5d0))) / (x * (((0.5d0 - (0.125d0 / x)) / x) - (-1.0d0)))
end function
public static double code(double x) {
return (0.5 * Math.pow(x, -0.5)) / (x * (((0.5 - (0.125 / x)) / x) - -1.0));
}
def code(x): return (0.5 * math.pow(x, -0.5)) / (x * (((0.5 - (0.125 / x)) / x) - -1.0))
function code(x) return Float64(Float64(0.5 * (x ^ -0.5)) / Float64(x * Float64(Float64(Float64(0.5 - Float64(0.125 / x)) / x) - -1.0))) end
function tmp = code(x) tmp = (0.5 * (x ^ -0.5)) / (x * (((0.5 - (0.125 / x)) / x) - -1.0)); end
code[x_] := N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] / N[(x * N[(N[(N[(0.5 - N[(0.125 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot {x}^{-0.5}}{x \cdot \left(\frac{0.5 - \frac{0.125}{x}}{x} - -1\right)}
\end{array}
Initial program 38.5%
frac-sub38.5%
*-rgt-identity38.5%
*-un-lft-identity38.5%
+-commutative38.5%
sqrt-unprod38.5%
+-commutative38.5%
Applied egg-rr38.5%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
*-commutative0.0%
distribute-rgt-neg-in0.0%
Simplified38.5%
Taylor expanded in x around inf 98.6%
*-commutative98.6%
unpow1/298.6%
rem-exp-log94.4%
exp-neg94.5%
exp-prod94.5%
distribute-lft-neg-out94.5%
distribute-rgt-neg-in94.5%
metadata-eval94.5%
exp-to-pow98.6%
Simplified98.6%
Final simplification98.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 38.5%
Taylor expanded in x around inf 80.9%
Taylor expanded in x around inf 99.3%
fma-define99.3%
distribute-rgt-out99.3%
metadata-eval99.3%
*-commutative99.3%
Simplified99.3%
Taylor expanded in x around inf 98.5%
*-commutative98.5%
Simplified98.5%
Final simplification98.5%
(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 38.5%
flip--38.4%
clear-num38.4%
inv-pow38.4%
sqrt-pow238.4%
metadata-eval38.4%
pow1/238.4%
pow-flip38.4%
+-commutative38.4%
metadata-eval38.4%
frac-times21.2%
metadata-eval21.2%
add-sqr-sqrt21.4%
frac-times24.6%
metadata-eval24.6%
add-sqr-sqrt38.5%
Applied egg-rr38.5%
Taylor expanded in x around inf 60.6%
*-un-lft-identity60.6%
associate-/r*60.6%
metadata-eval60.6%
sqrt-pow196.8%
metadata-eval96.8%
Applied egg-rr96.8%
*-lft-identity96.8%
Simplified96.8%
(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.5%
expm1-log1p-u38.5%
expm1-undefine4.7%
inv-pow4.7%
sqrt-pow24.7%
metadata-eval4.7%
Applied egg-rr4.7%
log1p-undefine4.7%
rem-exp-log4.7%
+-commutative4.7%
associate--l+31.9%
metadata-eval31.9%
+-rgt-identity31.9%
Simplified31.9%
Taylor expanded in x around 0 5.4%
unpow1/25.4%
rem-exp-log5.4%
exp-neg5.4%
exp-prod5.4%
distribute-lft-neg-out5.4%
distribute-rgt-neg-in5.4%
metadata-eval5.4%
exp-to-pow5.4%
Simplified5.4%
(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 2024121
(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)))))