
(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 13 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 (if (<= x 2e+16) (/ (/ 1.0 (fma x x x)) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))) (/ (- (/ (* (sqrt (/ 1.0 x)) 0.625) x) (* -0.5 (pow x -0.5))) x)))
double code(double x) {
double tmp;
if (x <= 2e+16) {
tmp = (1.0 / fma(x, x, x)) / (pow(x, -0.5) + pow((x + 1.0), -0.5));
} else {
tmp = (((sqrt((1.0 / x)) * 0.625) / x) - (-0.5 * pow(x, -0.5))) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 2e+16) tmp = Float64(Float64(1.0 / fma(x, x, x)) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))); else tmp = Float64(Float64(Float64(Float64(sqrt(Float64(1.0 / x)) * 0.625) / x) - Float64(-0.5 * (x ^ -0.5))) / x); end return tmp end
code[x_] := If[LessEqual[x, 2e+16], N[(N[(1.0 / N[(x * x + x), $MachinePrecision]), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 0.625), $MachinePrecision] / x), $MachinePrecision] - N[(-0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+16}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{fma}\left(x, x, x\right)}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\sqrt{\frac{1}{x}} \cdot 0.625}{x} - -0.5 \cdot {x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 2e16Initial program 59.3%
flip--59.4%
div-inv59.5%
frac-times59.7%
metadata-eval59.7%
add-sqr-sqrt59.9%
frac-times61.0%
metadata-eval61.0%
add-sqr-sqrt61.9%
+-commutative61.9%
inv-pow61.9%
sqrt-pow261.9%
metadata-eval61.9%
pow1/261.9%
pow-flip61.9%
+-commutative61.9%
metadata-eval61.9%
Applied egg-rr61.9%
associate-*r/62.0%
*-rgt-identity62.0%
Simplified62.0%
frac-sub94.0%
*-un-lft-identity94.0%
distribute-rgt-in94.1%
*-un-lft-identity94.1%
unpow294.1%
Applied egg-rr94.1%
*-rgt-identity94.1%
associate--l+99.1%
+-inverses99.1%
metadata-eval99.1%
+-commutative99.1%
unpow299.1%
fma-define99.1%
Simplified99.1%
if 2e16 < x Initial program 38.0%
Taylor expanded in x around inf 84.1%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
distribute-neg-frac20.0%
Simplified99.7%
pow1/299.7%
inv-pow99.7%
pow-pow99.8%
metadata-eval99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x)
:precision binary64
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ x 1.0)))) 4e-16)
(* 0.5 (/ (pow x -0.5) (+ x 0.5)))
(/
-1.0
(/
(+ (pow x -0.5) (pow (+ x 1.0) -0.5))
(+ (/ -1.0 (- -1.0 x)) (/ -1.0 x))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 4e-16) {
tmp = 0.5 * (pow(x, -0.5) / (x + 0.5));
} else {
tmp = -1.0 / ((pow(x, -0.5) + pow((x + 1.0), -0.5)) / ((-1.0 / (-1.0 - x)) + (-1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((x + 1.0d0)))) <= 4d-16) then
tmp = 0.5d0 * ((x ** (-0.5d0)) / (x + 0.5d0))
else
tmp = (-1.0d0) / (((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0))) / (((-1.0d0) / ((-1.0d0) - x)) + ((-1.0d0) / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((x + 1.0)))) <= 4e-16) {
tmp = 0.5 * (Math.pow(x, -0.5) / (x + 0.5));
} else {
tmp = -1.0 / ((Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5)) / ((-1.0 / (-1.0 - x)) + (-1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((x + 1.0)))) <= 4e-16: tmp = 0.5 * (math.pow(x, -0.5) / (x + 0.5)) else: tmp = -1.0 / ((math.pow(x, -0.5) + math.pow((x + 1.0), -0.5)) / ((-1.0 / (-1.0 - x)) + (-1.0 / x))) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 4e-16) tmp = Float64(0.5 * Float64((x ^ -0.5) / Float64(x + 0.5))); else tmp = Float64(-1.0 / Float64(Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5)) / Float64(Float64(-1.0 / Float64(-1.0 - x)) + Float64(-1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 4e-16) tmp = 0.5 * ((x ^ -0.5) / (x + 0.5)); else tmp = -1.0 / (((x ^ -0.5) + ((x + 1.0) ^ -0.5)) / ((-1.0 / (-1.0 - x)) + (-1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-16], N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 / N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 4 \cdot 10^{-16}:\\
\;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{\frac{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}}{\frac{-1}{-1 - x} + \frac{-1}{x}}}\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 3.9999999999999999e-16Initial program 37.7%
frac-sub37.8%
*-un-lft-identity37.8%
+-commutative37.8%
*-rgt-identity37.8%
sqrt-unprod37.8%
+-commutative37.8%
Applied egg-rr37.8%
Taylor expanded in x around inf 84.2%
*-commutative84.2%
Simplified84.2%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
times-frac99.3%
inv-pow99.3%
sqrt-pow199.4%
metadata-eval99.4%
frac-times99.4%
*-commutative99.4%
*-un-lft-identity99.4%
times-frac99.4%
metadata-eval99.4%
Applied egg-rr99.4%
distribute-rgt-in99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/l*99.4%
*-inverses99.4%
metadata-eval99.4%
Simplified99.4%
if 3.9999999999999999e-16 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 80.2%
flip--79.9%
clear-num80.0%
inv-pow80.0%
sqrt-pow280.0%
metadata-eval80.0%
pow1/280.0%
pow-flip80.0%
+-commutative80.0%
metadata-eval80.0%
frac-times80.7%
metadata-eval80.7%
add-sqr-sqrt81.4%
frac-times82.3%
metadata-eval82.3%
add-sqr-sqrt83.5%
Applied egg-rr83.5%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ x 1.0)))) 4e-16) (* 0.5 (/ (pow x -0.5) (+ x 0.5))) (- (pow x -0.5) (pow (+ x 1.0) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 4e-16) {
tmp = 0.5 * (pow(x, -0.5) / (x + 0.5));
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((x + 1.0d0)))) <= 4d-16) then
tmp = 0.5d0 * ((x ** (-0.5d0)) / (x + 0.5d0))
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / Math.sqrt((x + 1.0)))) <= 4e-16) {
tmp = 0.5 * (Math.pow(x, -0.5) / (x + 0.5));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((x + 1.0)))) <= 4e-16: tmp = 0.5 * (math.pow(x, -0.5) / (x + 0.5)) else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(x + 1.0)))) <= 4e-16) tmp = Float64(0.5 * Float64((x ^ -0.5) / Float64(x + 0.5))); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((x + 1.0)))) <= 4e-16) tmp = 0.5 * ((x ^ -0.5) / (x + 0.5)); else tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-16], N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 4 \cdot 10^{-16}:\\
\;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 3.9999999999999999e-16Initial program 37.7%
frac-sub37.8%
*-un-lft-identity37.8%
+-commutative37.8%
*-rgt-identity37.8%
sqrt-unprod37.8%
+-commutative37.8%
Applied egg-rr37.8%
Taylor expanded in x around inf 84.2%
*-commutative84.2%
Simplified84.2%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
times-frac99.3%
inv-pow99.3%
sqrt-pow199.4%
metadata-eval99.4%
frac-times99.4%
*-commutative99.4%
*-un-lft-identity99.4%
times-frac99.4%
metadata-eval99.4%
Applied egg-rr99.4%
distribute-rgt-in99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/l*99.4%
*-inverses99.4%
metadata-eval99.4%
Simplified99.4%
if 3.9999999999999999e-16 < (-.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 x)) (/.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) Initial program 80.2%
sub-neg80.2%
inv-pow80.2%
sqrt-pow280.6%
metadata-eval80.6%
distribute-neg-frac80.6%
metadata-eval80.6%
+-commutative80.6%
Applied egg-rr80.6%
*-rgt-identity80.6%
cancel-sign-sub80.6%
distribute-lft-neg-in80.6%
*-rgt-identity80.6%
distribute-neg-frac80.6%
metadata-eval80.6%
unpow1/280.6%
exp-to-pow79.2%
log1p-undefine79.2%
*-commutative79.2%
exp-neg80.2%
*-commutative80.2%
distribute-rgt-neg-in80.2%
log1p-undefine80.2%
metadata-eval80.2%
exp-to-pow83.4%
Simplified83.4%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 5e+22) (/ (/ 1.0 (+ (sqrt x) (sqrt (+ x 1.0)))) (sqrt (* x (+ x 1.0)))) (/ (- (/ (* (sqrt (/ 1.0 x)) 0.625) x) (* -0.5 (pow x -0.5))) x)))
double code(double x) {
double tmp;
if (x <= 5e+22) {
tmp = (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / sqrt((x * (x + 1.0)));
} else {
tmp = (((sqrt((1.0 / x)) * 0.625) / x) - (-0.5 * pow(x, -0.5))) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5d+22) then
tmp = (1.0d0 / (sqrt(x) + sqrt((x + 1.0d0)))) / sqrt((x * (x + 1.0d0)))
else
tmp = (((sqrt((1.0d0 / x)) * 0.625d0) / x) - ((-0.5d0) * (x ** (-0.5d0)))) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5e+22) {
tmp = (1.0 / (Math.sqrt(x) + Math.sqrt((x + 1.0)))) / Math.sqrt((x * (x + 1.0)));
} else {
tmp = (((Math.sqrt((1.0 / x)) * 0.625) / x) - (-0.5 * Math.pow(x, -0.5))) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 5e+22: tmp = (1.0 / (math.sqrt(x) + math.sqrt((x + 1.0)))) / math.sqrt((x * (x + 1.0))) else: tmp = (((math.sqrt((1.0 / x)) * 0.625) / x) - (-0.5 * math.pow(x, -0.5))) / x return tmp
function code(x) tmp = 0.0 if (x <= 5e+22) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + sqrt(Float64(x + 1.0)))) / sqrt(Float64(x * Float64(x + 1.0)))); else tmp = Float64(Float64(Float64(Float64(sqrt(Float64(1.0 / x)) * 0.625) / x) - Float64(-0.5 * (x ^ -0.5))) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5e+22) tmp = (1.0 / (sqrt(x) + sqrt((x + 1.0)))) / sqrt((x * (x + 1.0))); else tmp = (((sqrt((1.0 / x)) * 0.625) / x) - (-0.5 * (x ^ -0.5))) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5e+22], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 0.625), $MachinePrecision] / x), $MachinePrecision] - N[(-0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+22}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + \sqrt{x + 1}}}{\sqrt{x \cdot \left(x + 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\sqrt{\frac{1}{x}} \cdot 0.625}{x} - -0.5 \cdot {x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 4.9999999999999996e22Initial program 49.6%
frac-sub51.7%
*-un-lft-identity51.7%
+-commutative51.7%
*-rgt-identity51.7%
sqrt-unprod51.7%
+-commutative51.7%
Applied egg-rr51.7%
flip--68.0%
add-sqr-sqrt58.8%
add-sqr-sqrt78.2%
Applied egg-rr78.2%
associate--l+99.2%
+-inverses99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
if 4.9999999999999996e22 < x Initial program 38.6%
Taylor expanded in x around inf 83.8%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
distribute-neg-frac20.0%
Simplified99.7%
pow1/299.7%
inv-pow99.7%
pow-pow99.8%
metadata-eval99.8%
*-un-lft-identity99.8%
Applied egg-rr99.8%
*-lft-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 75000000.0) (/ (- (sqrt (+ x 1.0)) (sqrt x)) (sqrt (* x (+ x 1.0)))) (* 0.5 (/ (pow x -0.5) (+ x 0.5)))))
double code(double x) {
double tmp;
if (x <= 75000000.0) {
tmp = (sqrt((x + 1.0)) - sqrt(x)) / sqrt((x * (x + 1.0)));
} else {
tmp = 0.5 * (pow(x, -0.5) / (x + 0.5));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 75000000.0d0) then
tmp = (sqrt((x + 1.0d0)) - sqrt(x)) / sqrt((x * (x + 1.0d0)))
else
tmp = 0.5d0 * ((x ** (-0.5d0)) / (x + 0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 75000000.0) {
tmp = (Math.sqrt((x + 1.0)) - Math.sqrt(x)) / Math.sqrt((x * (x + 1.0)));
} else {
tmp = 0.5 * (Math.pow(x, -0.5) / (x + 0.5));
}
return tmp;
}
def code(x): tmp = 0 if x <= 75000000.0: tmp = (math.sqrt((x + 1.0)) - math.sqrt(x)) / math.sqrt((x * (x + 1.0))) else: tmp = 0.5 * (math.pow(x, -0.5) / (x + 0.5)) return tmp
function code(x) tmp = 0.0 if (x <= 75000000.0) tmp = Float64(Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) / sqrt(Float64(x * Float64(x + 1.0)))); else tmp = Float64(0.5 * Float64((x ^ -0.5) / Float64(x + 0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 75000000.0) tmp = (sqrt((x + 1.0)) - sqrt(x)) / sqrt((x * (x + 1.0))); else tmp = 0.5 * ((x ^ -0.5) / (x + 0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 75000000.0], N[(N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 75000000:\\
\;\;\;\;\frac{\sqrt{x + 1} - \sqrt{x}}{\sqrt{x \cdot \left(x + 1\right)}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x + 0.5}\\
\end{array}
\end{array}
if x < 7.5e7Initial program 80.2%
frac-sub83.5%
*-un-lft-identity83.5%
+-commutative83.5%
*-rgt-identity83.5%
sqrt-unprod83.5%
+-commutative83.5%
Applied egg-rr83.5%
if 7.5e7 < x Initial program 37.7%
frac-sub37.8%
*-un-lft-identity37.8%
+-commutative37.8%
*-rgt-identity37.8%
sqrt-unprod37.8%
+-commutative37.8%
Applied egg-rr37.8%
Taylor expanded in x around inf 84.2%
*-commutative84.2%
Simplified84.2%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
times-frac99.3%
inv-pow99.3%
sqrt-pow199.4%
metadata-eval99.4%
frac-times99.4%
*-commutative99.4%
*-un-lft-identity99.4%
times-frac99.4%
metadata-eval99.4%
Applied egg-rr99.4%
distribute-rgt-in99.4%
*-lft-identity99.4%
associate-*l/99.4%
associate-/l*99.4%
*-inverses99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification98.7%
(FPCore (x) :precision binary64 (* 0.5 (/ (pow x -0.5) (+ x 0.5))))
double code(double x) {
return 0.5 * (pow(x, -0.5) / (x + 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 * ((x ** (-0.5d0)) / (x + 0.5d0))
end function
public static double code(double x) {
return 0.5 * (Math.pow(x, -0.5) / (x + 0.5));
}
def code(x): return 0.5 * (math.pow(x, -0.5) / (x + 0.5))
function code(x) return Float64(0.5 * Float64((x ^ -0.5) / Float64(x + 0.5))) end
function tmp = code(x) tmp = 0.5 * ((x ^ -0.5) / (x + 0.5)); end
code[x_] := N[(0.5 * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{{x}^{-0.5}}{x + 0.5}
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Taylor expanded in x around inf 96.8%
associate-*r/96.8%
metadata-eval96.8%
Simplified96.8%
times-frac96.8%
inv-pow96.8%
sqrt-pow196.9%
metadata-eval96.9%
frac-times96.9%
*-commutative96.9%
*-un-lft-identity96.9%
times-frac96.9%
metadata-eval96.9%
Applied egg-rr96.9%
distribute-rgt-in96.9%
*-lft-identity96.9%
associate-*l/96.9%
associate-/l*96.9%
*-inverses96.9%
metadata-eval96.9%
Simplified96.9%
(FPCore (x) :precision binary64 (/ (* (sqrt (/ 1.0 x)) 0.5) x))
double code(double x) {
return (sqrt((1.0 / x)) * 0.5) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (sqrt((1.0d0 / x)) * 0.5d0) / x
end function
public static double code(double x) {
return (Math.sqrt((1.0 / x)) * 0.5) / x;
}
def code(x): return (math.sqrt((1.0 / x)) * 0.5) / x
function code(x) return Float64(Float64(sqrt(Float64(1.0 / x)) * 0.5) / x) end
function tmp = code(x) tmp = (sqrt((1.0 / x)) * 0.5) / x; end
code[x_] := N[(N[(N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt{\frac{1}{x}} \cdot 0.5}{x}
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Taylor expanded in x around inf 96.7%
(FPCore (x) :precision binary64 (/ 0.5 (* (sqrt x) (+ x 0.5))))
double code(double x) {
return 0.5 / (sqrt(x) * (x + 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.5d0 / (sqrt(x) * (x + 0.5d0))
end function
public static double code(double x) {
return 0.5 / (Math.sqrt(x) * (x + 0.5));
}
def code(x): return 0.5 / (math.sqrt(x) * (x + 0.5))
function code(x) return Float64(0.5 / Float64(sqrt(x) * Float64(x + 0.5))) end
function tmp = code(x) tmp = 0.5 / (sqrt(x) * (x + 0.5)); end
code[x_] := N[(0.5 / N[(N[Sqrt[x], $MachinePrecision] * N[(x + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\sqrt{x} \cdot \left(x + 0.5\right)}
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Taylor expanded in x around inf 96.8%
associate-*r/96.8%
metadata-eval96.8%
Simplified96.8%
associate-/l*96.6%
inv-pow96.6%
sqrt-pow196.7%
metadata-eval96.7%
*-un-lft-identity96.7%
metadata-eval96.7%
sqrt-pow196.6%
inv-pow96.6%
sqrt-div96.6%
metadata-eval96.6%
frac-times95.4%
metadata-eval95.4%
Applied egg-rr95.4%
*-lft-identity95.4%
distribute-rgt-in95.4%
*-lft-identity95.4%
associate-*l/95.4%
associate-/l*95.4%
*-inverses95.4%
metadata-eval95.4%
Simplified95.4%
(FPCore (x) :precision binary64 (pow x -1.5))
double code(double x) {
return pow(x, -1.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x ** (-1.5d0)
end function
public static double code(double x) {
return Math.pow(x, -1.5);
}
def code(x): return math.pow(x, -1.5)
function code(x) return x ^ -1.5 end
function tmp = code(x) tmp = x ^ -1.5; end
code[x_] := N[Power[x, -1.5], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-1.5}
\end{array}
Initial program 39.6%
Taylor expanded in x around 0 5.7%
pow1/25.7%
pow-to-exp5.7%
log-rec5.7%
Applied egg-rr5.7%
Applied egg-rr44.4%
(FPCore (x) :precision binary64 (/ (/ -1.0 x) (/ (- -1.0 x) 0.5)))
double code(double x) {
return (-1.0 / x) / ((-1.0 - x) / 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-1.0d0) / x) / (((-1.0d0) - x) / 0.5d0)
end function
public static double code(double x) {
return (-1.0 / x) / ((-1.0 - x) / 0.5);
}
def code(x): return (-1.0 / x) / ((-1.0 - x) / 0.5)
function code(x) return Float64(Float64(-1.0 / x) / Float64(Float64(-1.0 - x) / 0.5)) end
function tmp = code(x) tmp = (-1.0 / x) / ((-1.0 - x) / 0.5); end
code[x_] := N[(N[(-1.0 / x), $MachinePrecision] / N[(N[(-1.0 - x), $MachinePrecision] / 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{-1}{x}}{\frac{-1 - x}{0.5}}
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Applied egg-rr37.6%
unpow-137.6%
associate-/r*37.6%
Simplified37.6%
Final simplification37.6%
(FPCore (x) :precision binary64 (if (<= x 5.5e+153) 0.25 (/ -0.125 x)))
double code(double x) {
double tmp;
if (x <= 5.5e+153) {
tmp = 0.25;
} else {
tmp = -0.125 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 5.5d+153) then
tmp = 0.25d0
else
tmp = (-0.125d0) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 5.5e+153) {
tmp = 0.25;
} else {
tmp = -0.125 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 5.5e+153: tmp = 0.25 else: tmp = -0.125 / x return tmp
function code(x) tmp = 0.0 if (x <= 5.5e+153) tmp = 0.25; else tmp = Float64(-0.125 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 5.5e+153) tmp = 0.25; else tmp = -0.125 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 5.5e+153], 0.25, N[(-0.125 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.5 \cdot 10^{+153}:\\
\;\;\;\;0.25\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.125}{x}\\
\end{array}
\end{array}
if x < 5.5000000000000003e153Initial program 12.4%
frac-sub12.7%
*-un-lft-identity12.7%
+-commutative12.7%
*-rgt-identity12.7%
sqrt-unprod12.7%
+-commutative12.7%
Applied egg-rr12.7%
Taylor expanded in x around inf 94.0%
*-commutative94.0%
Simplified94.0%
Applied egg-rr6.2%
associate-*r/6.2%
count-26.2%
times-frac6.2%
metadata-eval6.2%
*-inverses6.2%
metadata-eval6.2%
Simplified6.2%
if 5.5000000000000003e153 < x Initial program 69.5%
frac-sub69.5%
*-un-lft-identity69.5%
+-commutative69.5%
*-rgt-identity69.5%
sqrt-unprod69.5%
+-commutative69.5%
Applied egg-rr69.5%
Taylor expanded in x around inf 69.5%
*-commutative69.5%
Simplified69.5%
Applied egg-rr7.4%
associate-*l/7.4%
count-27.4%
associate-/r*7.4%
associate-*r/7.4%
count-27.4%
times-frac7.4%
metadata-eval7.4%
*-inverses7.4%
metadata-eval7.4%
metadata-eval7.4%
Simplified7.4%
(FPCore (x) :precision binary64 (/ 0.25 x))
double code(double x) {
return 0.25 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.25d0 / x
end function
public static double code(double x) {
return 0.25 / x;
}
def code(x): return 0.25 / x
function code(x) return Float64(0.25 / x) end
function tmp = code(x) tmp = 0.25 / x; end
code[x_] := N[(0.25 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.25}{x}
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Applied egg-rr8.2%
distribute-neg-frac8.2%
metadata-eval8.2%
count-28.2%
associate-/r*8.2%
metadata-eval8.2%
Simplified8.2%
(FPCore (x) :precision binary64 0.25)
double code(double x) {
return 0.25;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.25d0
end function
public static double code(double x) {
return 0.25;
}
def code(x): return 0.25
function code(x) return 0.25 end
function tmp = code(x) tmp = 0.25; end
code[x_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 39.6%
frac-sub39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
sqrt-unprod39.8%
+-commutative39.8%
Applied egg-rr39.8%
Taylor expanded in x around inf 82.3%
*-commutative82.3%
Simplified82.3%
Applied egg-rr4.8%
associate-*r/4.8%
count-24.8%
times-frac4.8%
metadata-eval4.8%
*-inverses4.8%
metadata-eval4.8%
Simplified4.8%
(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 2024090
(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)))))