
(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 10 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 (/ (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (+ 1.0 (- x x)) (+ x (pow x 2.0))))))
double code(double x) {
return 1.0 / ((pow(x, -0.5) + pow((1.0 + x), -0.5)) / ((1.0 + (x - x)) / (x + pow(x, 2.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0))) / ((1.0d0 + (x - x)) / (x + (x ** 2.0d0))))
end function
public static double code(double x) {
return 1.0 / ((Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5)) / ((1.0 + (x - x)) / (x + Math.pow(x, 2.0))));
}
def code(x): return 1.0 / ((math.pow(x, -0.5) + math.pow((1.0 + x), -0.5)) / ((1.0 + (x - x)) / (x + math.pow(x, 2.0))))
function code(x) return Float64(1.0 / Float64(Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)) / Float64(Float64(1.0 + Float64(x - x)) / Float64(x + (x ^ 2.0))))) end
function tmp = code(x) tmp = 1.0 / (((x ^ -0.5) + ((1.0 + x) ^ -0.5)) / ((1.0 + (x - x)) / (x + (x ^ 2.0)))); end
code[x_] := N[(1.0 / N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(x + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}{\frac{1 + \left(x - x\right)}{x + {x}^{2}}}}
\end{array}
Initial program 13.4%
flip--13.4%
clear-num13.4%
pow1/213.4%
pow-flip13.4%
metadata-eval13.4%
inv-pow13.4%
sqrt-pow213.4%
+-commutative13.4%
metadata-eval13.4%
frac-times13.9%
metadata-eval13.9%
add-sqr-sqrt13.8%
frac-times14.0%
metadata-eval14.0%
add-sqr-sqrt13.8%
Applied egg-rr13.8%
frac-sub19.2%
*-un-lft-identity19.2%
Applied egg-rr19.2%
*-rgt-identity19.2%
associate--l+99.3%
distribute-lft-in99.3%
*-rgt-identity99.3%
unpow299.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (/ 1.0 (/ (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)) (/ (/ 1.0 x) (+ 1.0 x)))))
double code(double x) {
return 1.0 / ((pow(x, -0.5) + pow((1.0 + x), -0.5)) / ((1.0 / x) / (1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x ** (-0.5d0)) + ((1.0d0 + x) ** (-0.5d0))) / ((1.0d0 / x) / (1.0d0 + x)))
end function
public static double code(double x) {
return 1.0 / ((Math.pow(x, -0.5) + Math.pow((1.0 + x), -0.5)) / ((1.0 / x) / (1.0 + x)));
}
def code(x): return 1.0 / ((math.pow(x, -0.5) + math.pow((1.0 + x), -0.5)) / ((1.0 / x) / (1.0 + x)))
function code(x) return Float64(1.0 / Float64(Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)) / Float64(Float64(1.0 / x) / Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / (((x ^ -0.5) + ((1.0 + x) ^ -0.5)) / ((1.0 / x) / (1.0 + x))); end
code[x_] := N[(1.0 / N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}{\frac{\frac{1}{x}}{1 + x}}}
\end{array}
Initial program 13.4%
flip--13.4%
clear-num13.4%
pow1/213.4%
pow-flip13.4%
metadata-eval13.4%
inv-pow13.4%
sqrt-pow213.4%
+-commutative13.4%
metadata-eval13.4%
frac-times13.9%
metadata-eval13.9%
add-sqr-sqrt13.8%
frac-times14.0%
metadata-eval14.0%
add-sqr-sqrt13.8%
Applied egg-rr13.8%
frac-sub19.2%
*-un-lft-identity19.2%
Applied egg-rr19.2%
associate-/r*19.2%
*-rgt-identity19.2%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 120000000.0) (- (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 120000000.0) {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 120000000.0d0) then
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
else
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 120000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
} else {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 120000000.0: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) else: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) return tmp
function code(x) tmp = 0.0 if (x <= 120000000.0) tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); else tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 120000000.0) tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); else tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 120000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 120000000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1.2e8Initial program 79.7%
*-un-lft-identity79.7%
clear-num79.7%
associate-/r/79.7%
prod-diff79.7%
*-un-lft-identity79.7%
fma-neg79.7%
*-un-lft-identity79.7%
pow1/279.7%
pow-flip80.4%
metadata-eval80.4%
pow1/280.4%
pow-flip80.6%
+-commutative80.6%
metadata-eval80.6%
Applied egg-rr80.6%
+-commutative80.6%
sub-neg80.6%
fma-udef80.6%
distribute-lft1-in80.6%
metadata-eval80.6%
mul0-lft80.6%
+-commutative80.6%
associate-+r+80.6%
sub-neg80.6%
neg-sub080.6%
+-commutative80.6%
sub-neg80.6%
Simplified80.6%
if 1.2e8 < x Initial program 6.9%
flip--6.8%
clear-num6.8%
pow1/26.8%
pow-flip6.8%
metadata-eval6.8%
inv-pow6.8%
sqrt-pow26.8%
+-commutative6.8%
metadata-eval6.8%
frac-times7.4%
metadata-eval7.4%
add-sqr-sqrt7.3%
frac-times7.4%
metadata-eval7.4%
add-sqr-sqrt7.0%
Applied egg-rr7.0%
Taylor expanded in x around inf 97.9%
Final simplification96.4%
(FPCore (x) :precision binary64 (if (<= x 7.2e+15) (/ 1.0 (/ (* 2.0 (sqrt (/ 1.0 x))) (- (/ 1.0 x) (/ 1.0 (+ 1.0 x))))) (sqrt (/ 1.0 (pow x 3.0)))))
double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((2.0 * sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 7.2d+15) then
tmp = 1.0d0 / ((2.0d0 * sqrt((1.0d0 / x))) / ((1.0d0 / x) - (1.0d0 / (1.0d0 + x))))
else
tmp = sqrt((1.0d0 / (x ** 3.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((2.0 * Math.sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 7.2e+15: tmp = 1.0 / ((2.0 * math.sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x)))) else: tmp = math.sqrt((1.0 / math.pow(x, 3.0))) return tmp
function code(x) tmp = 0.0 if (x <= 7.2e+15) tmp = Float64(1.0 / Float64(Float64(2.0 * sqrt(Float64(1.0 / x))) / Float64(Float64(1.0 / x) - Float64(1.0 / Float64(1.0 + x))))); else tmp = sqrt(Float64(1.0 / (x ^ 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 7.2e+15) tmp = 1.0 / ((2.0 * sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x)))); else tmp = sqrt((1.0 / (x ^ 3.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 7.2e+15], N[(1.0 / N[(N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot \sqrt{\frac{1}{x}}}{\frac{1}{x} - \frac{1}{1 + x}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 7.2e15Initial program 64.6%
flip--64.5%
clear-num64.5%
pow1/264.5%
pow-flip64.5%
metadata-eval64.5%
inv-pow64.5%
sqrt-pow264.5%
+-commutative64.5%
metadata-eval64.5%
frac-times64.7%
metadata-eval64.7%
add-sqr-sqrt65.3%
frac-times65.7%
metadata-eval65.7%
add-sqr-sqrt66.9%
Applied egg-rr66.9%
Taylor expanded in x around inf 43.8%
if 7.2e15 < x Initial program 3.9%
sub-neg3.9%
flip-+3.9%
frac-times4.5%
metadata-eval4.5%
add-sqr-sqrt4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
pow1/24.3%
pow-flip4.3%
metadata-eval4.3%
Applied egg-rr4.3%
Taylor expanded in x around inf 18.8%
Final simplification22.7%
(FPCore (x) :precision binary64 (* 0.5 (sqrt (/ 1.0 (pow x 3.0)))))
double code(double x) {
return 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
end function
public static double code(double x) {
return 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
def code(x): return 0.5 * math.sqrt((1.0 / math.pow(x, 3.0)))
function code(x) return Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))) end
function tmp = code(x) tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); end
code[x_] := N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}
\end{array}
Initial program 13.4%
flip--13.4%
clear-num13.4%
pow1/213.4%
pow-flip13.4%
metadata-eval13.4%
inv-pow13.4%
sqrt-pow213.4%
+-commutative13.4%
metadata-eval13.4%
frac-times13.9%
metadata-eval13.9%
add-sqr-sqrt13.8%
frac-times14.0%
metadata-eval14.0%
add-sqr-sqrt13.8%
Applied egg-rr13.8%
Taylor expanded in x around inf 92.6%
Final simplification92.6%
(FPCore (x) :precision binary64 (if (<= x 7.2e+15) (/ 1.0 (/ (* 2.0 (sqrt (/ 1.0 x))) (- (/ 1.0 x) (/ 1.0 (+ 1.0 x))))) (/ 1.0 (+ x (pow x 0.5)))))
double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((2.0 * sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = 1.0 / (x + pow(x, 0.5));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 7.2d+15) then
tmp = 1.0d0 / ((2.0d0 * sqrt((1.0d0 / x))) / ((1.0d0 / x) - (1.0d0 / (1.0d0 + x))))
else
tmp = 1.0d0 / (x + (x ** 0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((2.0 * Math.sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = 1.0 / (x + Math.pow(x, 0.5));
}
return tmp;
}
def code(x): tmp = 0 if x <= 7.2e+15: tmp = 1.0 / ((2.0 * math.sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x)))) else: tmp = 1.0 / (x + math.pow(x, 0.5)) return tmp
function code(x) tmp = 0.0 if (x <= 7.2e+15) tmp = Float64(1.0 / Float64(Float64(2.0 * sqrt(Float64(1.0 / x))) / Float64(Float64(1.0 / x) - Float64(1.0 / Float64(1.0 + x))))); else tmp = Float64(1.0 / Float64(x + (x ^ 0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 7.2e+15) tmp = 1.0 / ((2.0 * sqrt((1.0 / x))) / ((1.0 / x) - (1.0 / (1.0 + x)))); else tmp = 1.0 / (x + (x ^ 0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 7.2e+15], N[(1.0 / N[(N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{1}{\frac{2 \cdot \sqrt{\frac{1}{x}}}{\frac{1}{x} - \frac{1}{1 + x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x + {x}^{0.5}}\\
\end{array}
\end{array}
if x < 7.2e15Initial program 64.6%
flip--64.5%
clear-num64.5%
pow1/264.5%
pow-flip64.5%
metadata-eval64.5%
inv-pow64.5%
sqrt-pow264.5%
+-commutative64.5%
metadata-eval64.5%
frac-times64.7%
metadata-eval64.7%
add-sqr-sqrt65.3%
frac-times65.7%
metadata-eval65.7%
add-sqr-sqrt66.9%
Applied egg-rr66.9%
Taylor expanded in x around inf 43.8%
if 7.2e15 < x Initial program 3.9%
sub-neg3.9%
flip-+3.9%
frac-times4.5%
metadata-eval4.5%
add-sqr-sqrt4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
pow1/24.3%
pow-flip4.3%
metadata-eval4.3%
Applied egg-rr4.3%
Taylor expanded in x around 0 8.7%
distribute-rgt-in8.7%
*-lft-identity8.7%
pow-plus8.7%
metadata-eval8.7%
Simplified8.7%
Final simplification14.2%
(FPCore (x) :precision binary64 (if (<= x 7.2e+15) (/ 1.0 (/ (* (pow x -0.5) 2.0) (- (/ 1.0 x) (/ 1.0 (+ 1.0 x))))) (/ 1.0 (+ x (pow x 0.5)))))
double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((pow(x, -0.5) * 2.0) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = 1.0 / (x + pow(x, 0.5));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 7.2d+15) then
tmp = 1.0d0 / (((x ** (-0.5d0)) * 2.0d0) / ((1.0d0 / x) - (1.0d0 / (1.0d0 + x))))
else
tmp = 1.0d0 / (x + (x ** 0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 7.2e+15) {
tmp = 1.0 / ((Math.pow(x, -0.5) * 2.0) / ((1.0 / x) - (1.0 / (1.0 + x))));
} else {
tmp = 1.0 / (x + Math.pow(x, 0.5));
}
return tmp;
}
def code(x): tmp = 0 if x <= 7.2e+15: tmp = 1.0 / ((math.pow(x, -0.5) * 2.0) / ((1.0 / x) - (1.0 / (1.0 + x)))) else: tmp = 1.0 / (x + math.pow(x, 0.5)) return tmp
function code(x) tmp = 0.0 if (x <= 7.2e+15) tmp = Float64(1.0 / Float64(Float64((x ^ -0.5) * 2.0) / Float64(Float64(1.0 / x) - Float64(1.0 / Float64(1.0 + x))))); else tmp = Float64(1.0 / Float64(x + (x ^ 0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 7.2e+15) tmp = 1.0 / (((x ^ -0.5) * 2.0) / ((1.0 / x) - (1.0 / (1.0 + x)))); else tmp = 1.0 / (x + (x ^ 0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 7.2e+15], N[(1.0 / N[(N[(N[Power[x, -0.5], $MachinePrecision] * 2.0), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+15}:\\
\;\;\;\;\frac{1}{\frac{{x}^{-0.5} \cdot 2}{\frac{1}{x} - \frac{1}{1 + x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x + {x}^{0.5}}\\
\end{array}
\end{array}
if x < 7.2e15Initial program 64.6%
flip--64.5%
clear-num64.5%
pow1/264.5%
pow-flip64.5%
metadata-eval64.5%
inv-pow64.5%
sqrt-pow264.5%
+-commutative64.5%
metadata-eval64.5%
frac-times64.7%
metadata-eval64.7%
add-sqr-sqrt65.3%
frac-times65.7%
metadata-eval65.7%
add-sqr-sqrt66.9%
Applied egg-rr66.9%
Taylor expanded in x around inf 43.8%
*-commutative43.8%
rem-exp-log43.8%
exp-neg43.8%
unpow1/243.8%
exp-prod43.8%
distribute-lft-neg-out43.8%
distribute-rgt-neg-in43.8%
metadata-eval43.8%
exp-to-pow43.8%
Simplified43.8%
if 7.2e15 < x Initial program 3.9%
sub-neg3.9%
flip-+3.9%
frac-times4.5%
metadata-eval4.5%
add-sqr-sqrt4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
distribute-neg-frac4.3%
metadata-eval4.3%
+-commutative4.3%
pow1/24.3%
pow-flip4.3%
metadata-eval4.3%
Applied egg-rr4.3%
Taylor expanded in x around 0 8.7%
distribute-rgt-in8.7%
*-lft-identity8.7%
pow-plus8.7%
metadata-eval8.7%
Simplified8.7%
Final simplification14.2%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (pow x 0.5))))
double code(double x) {
return 1.0 / (x + pow(x, 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + (x ** 0.5d0))
end function
public static double code(double x) {
return 1.0 / (x + Math.pow(x, 0.5));
}
def code(x): return 1.0 / (x + math.pow(x, 0.5))
function code(x) return Float64(1.0 / Float64(x + (x ^ 0.5))) end
function tmp = code(x) tmp = 1.0 / (x + (x ^ 0.5)); end
code[x_] := N[(1.0 / N[(x + N[Power[x, 0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + {x}^{0.5}}
\end{array}
Initial program 13.4%
sub-neg13.4%
flip-+13.4%
frac-times13.9%
metadata-eval13.9%
add-sqr-sqrt13.8%
distribute-neg-frac13.8%
metadata-eval13.8%
+-commutative13.8%
distribute-neg-frac13.8%
metadata-eval13.8%
+-commutative13.8%
pow1/213.8%
pow-flip13.8%
metadata-eval13.8%
Applied egg-rr13.8%
Taylor expanded in x around 0 9.4%
distribute-rgt-in9.4%
*-lft-identity9.4%
pow-plus9.4%
metadata-eval9.4%
Simplified9.4%
Final simplification9.4%
(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 13.4%
inv-pow13.4%
add-sqr-sqrt13.6%
unpow-prod-down13.9%
pow1/213.9%
sqrt-pow113.7%
metadata-eval13.7%
pow1/213.7%
sqrt-pow113.7%
metadata-eval13.7%
Applied egg-rr13.7%
pow-sqr13.5%
metadata-eval13.5%
Simplified13.5%
Taylor expanded in x around inf 7.9%
pow1/27.9%
inv-pow7.9%
pow-pow7.9%
metadata-eval7.9%
expm1-log1p-u7.9%
expm1-udef6.2%
Applied egg-rr6.2%
expm1-def7.9%
expm1-log1p7.9%
Simplified7.9%
Final simplification7.9%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 13.4%
Taylor expanded in x around 0 1.9%
Taylor expanded in x around inf 1.9%
Final simplification1.9%
(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 2023333
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+100))
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))