
(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 14 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
(let* ((t_0 (/ -1.0 (sqrt (+ 1.0 x)))))
(if (<= (+ (/ 1.0 (sqrt x)) t_0) 2e-10)
(+ (fma 0.3125 (pow x -3.5) (* 0.5 (pow x -1.5))) (* -0.375 (pow x -2.5)))
(+ (pow x -0.5) t_0))))
double code(double x) {
double t_0 = -1.0 / sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + t_0) <= 2e-10) {
tmp = fma(0.3125, pow(x, -3.5), (0.5 * pow(x, -1.5))) + (-0.375 * pow(x, -2.5));
} else {
tmp = pow(x, -0.5) + t_0;
}
return tmp;
}
function code(x) t_0 = Float64(-1.0 / sqrt(Float64(1.0 + x))) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + t_0) <= 2e-10) tmp = Float64(fma(0.3125, (x ^ -3.5), Float64(0.5 * (x ^ -1.5))) + Float64(-0.375 * (x ^ -2.5))); else tmp = Float64((x ^ -0.5) + t_0); end return tmp end
code[x_] := Block[{t$95$0 = N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], 2e-10], N[(N[(0.3125 * N[Power[x, -3.5], $MachinePrecision] + N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.375 * N[Power[x, -2.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{\sqrt{1 + x}}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + t_0 \leq 2 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(0.3125, {x}^{-3.5}, 0.5 \cdot {x}^{-1.5}\right) + -0.375 \cdot {x}^{-2.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} + t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000007e-10Initial program 39.4%
reciprocal-define4.6%
reciprocal-define37.9%
+-commutative37.9%
Simplified37.9%
add-sqr-sqrt25.2%
*-un-lft-identity25.2%
*-commutative25.2%
prod-diff4.8%
Applied egg-rr39.4%
associate-+l-39.4%
expm1-log1p39.4%
expm1-def5.6%
associate--l-5.6%
fma-udef5.6%
distribute-lft1-in5.6%
metadata-eval5.6%
mul0-lft5.6%
metadata-eval5.6%
expm1-def39.4%
expm1-log1p39.4%
+-commutative39.4%
Simplified39.4%
Taylor expanded in x around inf 68.6%
+-commutative68.6%
*-un-lft-identity68.6%
fma-def68.6%
Applied egg-rr99.9%
fma-udef99.9%
*-lft-identity99.9%
*-commutative99.9%
Simplified99.9%
if 2.00000000000000007e-10 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
reciprocal-define39.3%
reciprocal-define39.3%
+-commutative39.3%
Simplified39.3%
add-sqr-sqrt39.3%
*-un-lft-identity39.3%
*-commutative39.3%
prod-diff39.3%
Applied egg-rr99.9%
associate-+l-99.9%
expm1-log1p99.9%
expm1-def99.9%
associate--l-99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
metadata-eval99.9%
expm1-def99.9%
expm1-log1p99.9%
+-commutative99.9%
Simplified99.9%
metadata-eval99.9%
pow-flip99.9%
pow1/299.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 64000000.0) (- (pow x -0.5) (/ (cbrt (pow (+ 1.0 x) -0.5)) (cbrt (+ 1.0 x)))) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 64000000.0) {
tmp = pow(x, -0.5) - (cbrt(pow((1.0 + x), -0.5)) / cbrt((1.0 + x)));
} else {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 64000000.0) {
tmp = Math.pow(x, -0.5) - (Math.cbrt(Math.pow((1.0 + x), -0.5)) / Math.cbrt((1.0 + x)));
} else {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 64000000.0) tmp = Float64((x ^ -0.5) - Float64(cbrt((Float64(1.0 + x) ^ -0.5)) / cbrt(Float64(1.0 + x)))); else tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); end return tmp end
code[x_] := If[LessEqual[x, 64000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $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 64000000:\\
\;\;\;\;{x}^{-0.5} - \frac{\sqrt[3]{{\left(1 + x\right)}^{-0.5}}}{\sqrt[3]{1 + x}}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 6.4e7Initial program 99.4%
reciprocal-define39.1%
reciprocal-define39.0%
+-commutative39.0%
Simplified39.0%
add-sqr-sqrt39.1%
*-un-lft-identity39.1%
*-commutative39.1%
prod-diff39.1%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.5%
associate--l-99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
metadata-eval99.5%
expm1-def99.8%
expm1-log1p99.8%
+-commutative99.8%
Simplified99.8%
metadata-eval99.8%
pow-flip99.7%
metadata-eval99.7%
pow1/299.7%
add-cbrt-cube99.6%
add-sqr-sqrt99.6%
metadata-eval99.6%
add-sqr-sqrt99.6%
hypot-udef99.6%
cbrt-prod99.6%
hypot-udef99.6%
metadata-eval99.6%
add-sqr-sqrt99.6%
frac-times99.6%
metadata-eval99.6%
metadata-eval99.6%
add-sqr-sqrt99.6%
Applied egg-rr99.8%
if 6.4e7 < x Initial program 39.1%
reciprocal-define4.5%
reciprocal-define38.2%
+-commutative38.2%
Simplified38.2%
add-sqr-sqrt25.3%
*-un-lft-identity25.3%
*-commutative25.3%
prod-diff4.7%
Applied egg-rr39.1%
associate-+l-39.1%
expm1-log1p39.1%
expm1-def5.2%
associate--l-5.2%
fma-udef5.2%
distribute-lft1-in5.2%
metadata-eval5.2%
mul0-lft5.2%
metadata-eval5.2%
expm1-def39.1%
expm1-log1p39.1%
+-commutative39.1%
Simplified39.1%
Taylor expanded in x around inf 68.0%
Final simplification83.6%
(FPCore (x) :precision binary64 (if (<= x 300000000.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 <= 300000000.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 <= 300000000.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 <= 300000000.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 <= 300000000.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 <= 300000000.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 <= 300000000.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, 300000000.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 300000000:\\
\;\;\;\;{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 < 3e8Initial program 99.4%
reciprocal-define39.1%
reciprocal-define39.0%
+-commutative39.0%
Simplified39.0%
add-sqr-sqrt39.1%
*-un-lft-identity39.1%
*-commutative39.1%
prod-diff39.1%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.5%
associate--l-99.5%
fma-udef99.5%
distribute-lft1-in99.5%
metadata-eval99.5%
mul0-lft99.5%
metadata-eval99.5%
expm1-def99.8%
expm1-log1p99.8%
+-commutative99.8%
Simplified99.8%
if 3e8 < x Initial program 39.1%
reciprocal-define4.5%
reciprocal-define38.2%
+-commutative38.2%
Simplified38.2%
add-sqr-sqrt25.3%
*-un-lft-identity25.3%
*-commutative25.3%
prod-diff4.7%
Applied egg-rr39.1%
associate-+l-39.1%
expm1-log1p39.1%
expm1-def5.2%
associate--l-5.2%
fma-udef5.2%
distribute-lft1-in5.2%
metadata-eval5.2%
mul0-lft5.2%
metadata-eval5.2%
expm1-def39.1%
expm1-log1p39.1%
+-commutative39.1%
Simplified39.1%
Taylor expanded in x around inf 68.0%
Final simplification83.6%
(FPCore (x) :precision binary64 (if (<= x 1.7) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (* 0.5 (sqrt (/ 1.0 (pow x 3.0))))))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = pow(x, -0.5) - (1.0 / (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 <= 1.7d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (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 <= 1.7) {
tmp = Math.pow(x, -0.5) - (1.0 / (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 <= 1.7: tmp = math.pow(x, -0.5) - (1.0 / (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 <= 1.7) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(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 <= 1.7) tmp = (x ^ -0.5) - (1.0 / (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, 1.7], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $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 1.7:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.6%
reciprocal-define39.4%
reciprocal-define39.5%
+-commutative39.5%
Simplified39.5%
add-sqr-sqrt39.5%
*-un-lft-identity39.5%
*-commutative39.5%
prod-diff39.5%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
+-commutative100.0%
Simplified100.0%
metadata-eval100.0%
pow-flip100.0%
pow1/2100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
if 1.69999999999999996 < x Initial program 40.3%
reciprocal-define5.0%
reciprocal-define37.8%
+-commutative37.8%
Simplified37.8%
add-sqr-sqrt25.3%
*-un-lft-identity25.3%
*-commutative25.3%
prod-diff5.2%
Applied egg-rr40.3%
associate-+l-40.3%
expm1-log1p40.3%
expm1-def6.9%
associate--l-6.9%
fma-udef6.9%
distribute-lft1-in6.9%
metadata-eval6.9%
mul0-lft6.9%
metadata-eval6.9%
expm1-def40.3%
expm1-log1p40.3%
+-commutative40.3%
Simplified40.3%
Taylor expanded in x around inf 67.2%
Final simplification82.4%
(FPCore (x) :precision binary64 (if (<= x 4.4) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (* (sqrt (reciprocal (pow x 3.0))) 1.5)))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.4:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{reciprocal}\left(\left({x}^{3}\right)\right)} \cdot 1.5\\
\end{array}
\end{array}
if x < 4.4000000000000004Initial program 99.6%
reciprocal-define39.4%
reciprocal-define39.4%
+-commutative39.4%
Simplified39.4%
add-sqr-sqrt39.4%
*-un-lft-identity39.4%
*-commutative39.4%
prod-diff39.4%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def99.9%
associate--l-99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
metadata-eval99.9%
expm1-def100.0%
expm1-log1p100.0%
+-commutative100.0%
Simplified100.0%
metadata-eval100.0%
pow-flip100.0%
pow1/2100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.3%
*-commutative98.3%
Simplified98.3%
if 4.4000000000000004 < x Initial program 39.9%
reciprocal-define4.8%
reciprocal-define37.8%
+-commutative37.8%
Simplified37.8%
add-sqr-sqrt25.2%
*-un-lft-identity25.2%
*-commutative25.2%
prod-diff5.0%
Applied egg-rr39.9%
associate-+l-39.9%
expm1-log1p39.9%
expm1-def6.2%
associate--l-6.2%
fma-udef6.2%
distribute-lft1-in6.2%
metadata-eval6.2%
mul0-lft6.2%
metadata-eval6.2%
expm1-def39.9%
expm1-log1p39.9%
+-commutative39.9%
Simplified39.9%
Applied egg-rr39.8%
Taylor expanded in x around inf 42.2%
reciprocal-define42.2%
Simplified42.2%
Final simplification69.4%
(FPCore (x) :precision binary64 (if (<= x 1.7) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (* 0.5 (sqrt (reciprocal (pow x 3.0))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{reciprocal}\left(\left({x}^{3}\right)\right)}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.6%
reciprocal-define39.4%
reciprocal-define39.5%
+-commutative39.5%
Simplified39.5%
add-sqr-sqrt39.5%
*-un-lft-identity39.5%
*-commutative39.5%
prod-diff39.5%
Applied egg-rr100.0%
associate-+l-100.0%
expm1-log1p100.0%
expm1-def100.0%
associate--l-100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
metadata-eval100.0%
expm1-def100.0%
expm1-log1p100.0%
+-commutative100.0%
Simplified100.0%
metadata-eval100.0%
pow-flip100.0%
pow1/2100.0%
+-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
Simplified98.9%
if 1.69999999999999996 < x Initial program 40.3%
reciprocal-define5.0%
reciprocal-define37.8%
+-commutative37.8%
Simplified37.8%
add-sqr-sqrt25.3%
*-un-lft-identity25.3%
*-commutative25.3%
prod-diff5.2%
Applied egg-rr40.3%
associate-+l-40.3%
expm1-log1p40.3%
expm1-def6.9%
associate--l-6.9%
fma-udef6.9%
distribute-lft1-in6.9%
metadata-eval6.9%
mul0-lft6.9%
metadata-eval6.9%
expm1-def40.3%
expm1-log1p40.3%
+-commutative40.3%
Simplified40.3%
add-exp-log6.7%
log-pow6.7%
log1p-udef6.7%
Applied egg-rr6.7%
Simplified6.6%
Taylor expanded in x around inf 67.2%
*-commutative67.2%
reciprocal-define49.6%
Simplified49.6%
Final simplification73.3%
(FPCore (x) :precision binary64 (if (<= x 2.2e+23) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (pow (pow x 2.0) -0.25)))
double code(double x) {
double tmp;
if (x <= 2.2e+23) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = pow(pow(x, 2.0), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 2.2d+23) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
else
tmp = (x ** 2.0d0) ** (-0.25d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 2.2e+23) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.pow(Math.pow(x, 2.0), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 2.2e+23: tmp = math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5))) else: tmp = math.pow(math.pow(x, 2.0), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 2.2e+23) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = (x ^ 2.0) ^ -0.25; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 2.2e+23) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); else tmp = (x ^ 2.0) ^ -0.25; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 2.2e+23], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[Power[x, 2.0], $MachinePrecision], -0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2 \cdot 10^{+23}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{\left({x}^{2}\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 2.20000000000000008e23Initial program 96.7%
reciprocal-define37.9%
reciprocal-define37.7%
+-commutative37.7%
Simplified37.7%
add-sqr-sqrt37.8%
*-un-lft-identity37.8%
*-commutative37.8%
prod-diff38.0%
Applied egg-rr97.0%
associate-+l-97.0%
expm1-log1p97.0%
expm1-def96.0%
associate--l-96.0%
fma-udef96.0%
distribute-lft1-in96.0%
metadata-eval96.0%
mul0-lft96.0%
metadata-eval96.0%
expm1-def97.0%
expm1-log1p97.0%
+-commutative97.0%
Simplified97.0%
metadata-eval97.0%
pow-flip96.9%
pow1/296.9%
+-commutative96.9%
Applied egg-rr96.9%
Taylor expanded in x around 0 93.6%
*-commutative93.6%
Simplified93.6%
if 2.20000000000000008e23 < x Initial program 39.6%
reciprocal-define4.4%
reciprocal-define39.6%
+-commutative39.6%
Simplified39.6%
add-sqr-sqrt26.1%
*-un-lft-identity26.1%
*-commutative26.1%
prod-diff4.5%
Applied egg-rr39.6%
associate-+l-39.6%
expm1-log1p39.6%
expm1-def5.1%
associate--l-5.1%
fma-udef5.1%
distribute-lft1-in5.1%
metadata-eval5.1%
mul0-lft5.1%
metadata-eval5.1%
expm1-def39.6%
expm1-log1p39.6%
+-commutative39.6%
Simplified39.6%
metadata-eval39.6%
pow-flip32.1%
pow1/232.1%
+-commutative32.1%
Applied egg-rr32.1%
Taylor expanded in x around inf 5.2%
reciprocal-define5.2%
Simplified5.2%
reciprocal-define5.2%
pow1/25.2%
inv-pow5.2%
pow-pow5.2%
metadata-eval5.2%
sqr-pow5.2%
pow-prod-down40.4%
pow240.4%
metadata-eval40.4%
Applied egg-rr40.4%
Final simplification67.7%
(FPCore (x) :precision binary64 (if (<= x 2.2e+23) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (cbrt (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 2.2e+23) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = cbrt(pow(x, -1.5));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 2.2e+23) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.cbrt(Math.pow(x, -1.5));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 2.2e+23) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = cbrt((x ^ -1.5)); end return tmp end
code[x_] := If[LessEqual[x, 2.2e+23], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[Power[x, -1.5], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2 \cdot 10^{+23}:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{x}^{-1.5}}\\
\end{array}
\end{array}
if x < 2.20000000000000008e23Initial program 96.7%
reciprocal-define37.9%
reciprocal-define37.7%
+-commutative37.7%
Simplified37.7%
add-sqr-sqrt37.8%
*-un-lft-identity37.8%
*-commutative37.8%
prod-diff38.0%
Applied egg-rr97.0%
associate-+l-97.0%
expm1-log1p97.0%
expm1-def96.0%
associate--l-96.0%
fma-udef96.0%
distribute-lft1-in96.0%
metadata-eval96.0%
mul0-lft96.0%
metadata-eval96.0%
expm1-def97.0%
expm1-log1p97.0%
+-commutative97.0%
Simplified97.0%
metadata-eval97.0%
pow-flip96.9%
pow1/296.9%
+-commutative96.9%
Applied egg-rr96.9%
Taylor expanded in x around 0 93.6%
*-commutative93.6%
Simplified93.6%
if 2.20000000000000008e23 < x Initial program 39.6%
reciprocal-define4.4%
reciprocal-define39.6%
+-commutative39.6%
Simplified39.6%
add-sqr-sqrt26.1%
*-un-lft-identity26.1%
*-commutative26.1%
prod-diff4.5%
Applied egg-rr39.6%
associate-+l-39.6%
expm1-log1p39.6%
expm1-def5.1%
associate--l-5.1%
fma-udef5.1%
distribute-lft1-in5.1%
metadata-eval5.1%
mul0-lft5.1%
metadata-eval5.1%
expm1-def39.6%
expm1-log1p39.6%
+-commutative39.6%
Simplified39.6%
metadata-eval39.6%
pow-flip32.1%
pow1/232.1%
+-commutative32.1%
Applied egg-rr32.1%
Taylor expanded in x around inf 5.2%
reciprocal-define5.2%
Simplified5.2%
reciprocal-define5.2%
add-cbrt-cube36.6%
pow336.6%
reciprocal-define36.6%
reciprocal-define36.6%
pow1/236.6%
inv-pow36.6%
pow-pow36.6%
metadata-eval36.6%
pow-pow36.6%
metadata-eval36.6%
pow1/336.6%
Applied egg-rr36.6%
unpow1/336.6%
Simplified36.6%
Final simplification65.8%
(FPCore (x) :precision binary64 (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))))
double code(double x) {
return pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
end function
public static double code(double x) {
return Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
}
def code(x): return math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)))
function code(x) return Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))) end
function tmp = code(x) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}
\end{array}
Initial program 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
add-sqr-sqrt32.1%
*-un-lft-identity32.1%
*-commutative32.1%
prod-diff21.6%
Applied egg-rr69.0%
associate-+l-69.0%
expm1-log1p69.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def69.0%
expm1-log1p69.0%
+-commutative69.0%
Simplified69.0%
metadata-eval69.0%
pow-flip65.3%
pow1/265.3%
+-commutative65.3%
Applied egg-rr65.3%
Taylor expanded in x around 0 50.5%
*-commutative50.5%
Simplified50.5%
Final simplification50.5%
(FPCore (x) :precision binary64 (- (pow x -0.5) (+ 1.0 (* x -0.5))))
double code(double x) {
return pow(x, -0.5) - (1.0 + (x * -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) - (1.0d0 + (x * (-0.5d0)))
end function
public static double code(double x) {
return Math.pow(x, -0.5) - (1.0 + (x * -0.5));
}
def code(x): return math.pow(x, -0.5) - (1.0 + (x * -0.5))
function code(x) return Float64((x ^ -0.5) - Float64(1.0 + Float64(x * -0.5))) end
function tmp = code(x) tmp = (x ^ -0.5) - (1.0 + (x * -0.5)); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} - \left(1 + x \cdot -0.5\right)
\end{array}
Initial program 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
add-sqr-sqrt32.1%
*-un-lft-identity32.1%
*-commutative32.1%
prod-diff21.6%
Applied egg-rr69.0%
associate-+l-69.0%
expm1-log1p69.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def69.0%
expm1-log1p69.0%
+-commutative69.0%
Simplified69.0%
Taylor expanded in x around 0 49.3%
Final simplification49.3%
(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 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
add-sqr-sqrt32.1%
*-un-lft-identity32.1%
*-commutative32.1%
prod-diff21.6%
Applied egg-rr69.0%
associate-+l-69.0%
expm1-log1p69.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def69.0%
expm1-log1p69.0%
+-commutative69.0%
Simplified69.0%
metadata-eval69.0%
pow-flip65.3%
pow1/265.3%
+-commutative65.3%
Applied egg-rr65.3%
Taylor expanded in x around inf 48.5%
reciprocal-define22.6%
unpow1/222.6%
rem-exp-log22.6%
reciprocal-define45.2%
exp-neg45.2%
exp-prod45.2%
distribute-lft-neg-out45.2%
distribute-rgt-neg-in45.2%
metadata-eval45.2%
exp-to-pow48.5%
Simplified48.5%
Final simplification48.5%
(FPCore (x) :precision binary64 (reciprocal (sqrt x)))
\begin{array}{l}
\\
\mathsf{reciprocal}\left(\left(\sqrt{x}\right)\right)
\end{array}
Initial program 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
add-sqr-sqrt32.1%
*-un-lft-identity32.1%
*-commutative32.1%
prod-diff21.6%
Applied egg-rr69.0%
associate-+l-69.0%
expm1-log1p69.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def69.0%
expm1-log1p69.0%
+-commutative69.0%
Simplified69.0%
metadata-eval69.0%
pow-flip65.3%
pow1/265.3%
+-commutative65.3%
Applied egg-rr65.3%
Taylor expanded in x around inf 48.5%
reciprocal-define22.6%
Simplified22.6%
reciprocal-define48.5%
pow1/248.5%
inv-pow48.5%
pow-pow48.5%
metadata-eval48.5%
add-sqr-sqrt48.4%
unpow-prod-down48.1%
Applied egg-rr48.1%
pow-sqr48.4%
metadata-eval48.4%
unpow-148.4%
reciprocal-define21.6%
Simplified21.6%
Final simplification21.6%
(FPCore (x) :precision binary64 (sqrt (reciprocal x)))
\begin{array}{l}
\\
\sqrt{\mathsf{reciprocal}\left(x\right)}
\end{array}
Initial program 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
add-sqr-sqrt32.1%
*-un-lft-identity32.1%
*-commutative32.1%
prod-diff21.6%
Applied egg-rr69.0%
associate-+l-69.0%
expm1-log1p69.0%
expm1-def51.6%
associate--l-51.6%
fma-udef51.6%
distribute-lft1-in51.6%
metadata-eval51.6%
mul0-lft51.6%
metadata-eval51.6%
expm1-def69.0%
expm1-log1p69.0%
+-commutative69.0%
Simplified69.0%
metadata-eval69.0%
pow-flip65.3%
pow1/265.3%
+-commutative65.3%
Applied egg-rr65.3%
Taylor expanded in x around inf 48.5%
reciprocal-define22.6%
Simplified22.6%
Final simplification22.6%
(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 68.8%
reciprocal-define21.5%
reciprocal-define38.6%
+-commutative38.6%
Simplified38.6%
Taylor expanded in x around 0 20.2%
Taylor expanded in x around inf 2.0%
Final simplification2.0%
(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 2024024
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))