
(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 12 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 (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-9) (fma (pow x -1.5) 0.5 (* (pow x -2.5) -0.375)) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-9) {
tmp = fma(pow(x, -1.5), 0.5, (pow(x, -2.5) * -0.375));
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 2e-9) tmp = fma((x ^ -1.5), 0.5, Float64((x ^ -2.5) * -0.375)); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
code[x_] := If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-9], N[(N[Power[x, -1.5], $MachinePrecision] * 0.5 + N[(N[Power[x, -2.5], $MachinePrecision] * -0.375), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\mathsf{fma}\left({x}^{-1.5}, 0.5, {x}^{-2.5} \cdot -0.375\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000012e-9Initial program 34.6%
*-un-lft-identity34.6%
clear-num34.6%
associate-/r/34.6%
prod-diff34.6%
*-un-lft-identity34.6%
fma-neg34.6%
*-un-lft-identity34.6%
pow1/234.6%
pow-flip21.6%
metadata-eval21.6%
pow1/221.6%
pow-flip34.7%
+-commutative34.7%
metadata-eval34.7%
Applied egg-rr34.7%
associate-+l-34.7%
expm1-log1p34.7%
expm1-def5.6%
associate--l-5.6%
fma-udef5.6%
distribute-lft1-in5.6%
metadata-eval5.6%
mul0-lft5.6%
metadata-eval5.6%
expm1-def34.7%
expm1-log1p34.7%
Simplified34.7%
Taylor expanded in x around inf 69.8%
+-commutative69.8%
*-commutative69.8%
fma-def69.8%
pow-flip70.4%
sqrt-pow199.8%
metadata-eval99.8%
metadata-eval99.8%
*-commutative99.8%
pow-flip99.8%
sqrt-pow199.8%
metadata-eval99.8%
metadata-eval99.8%
Applied egg-rr99.8%
if 2.00000000000000012e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
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%
Simplified100.0%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-9)
(/ (/ 1.0 (+ (sqrt x) t_0)) (+ x 0.5))
(- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-9) {
tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 2d-9) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + 0.5d0)
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 2e-9) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 2e-9: tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + 0.5) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 2e-9) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + 0.5)); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-9) tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 2e-9], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000012e-9Initial program 34.6%
frac-sub34.7%
*-un-lft-identity34.7%
*-rgt-identity34.7%
+-commutative34.7%
sqrt-unprod34.7%
+-commutative34.7%
Applied egg-rr34.7%
flip--34.8%
div-inv34.8%
add-sqr-sqrt36.2%
add-sqr-sqrt37.1%
Applied egg-rr37.1%
associate-*r/37.1%
*-rgt-identity37.1%
associate--l+85.3%
+-inverses85.3%
metadata-eval85.3%
Simplified85.3%
Taylor expanded in x around inf 99.5%
+-commutative8.1%
Simplified99.5%
if 2.00000000000000012e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
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%
Simplified100.0%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ 1.0 x))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 5e-17)
(/ (/ 1.0 (+ (sqrt x) t_0)) x)
(- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))
double code(double x) {
double t_0 = sqrt((1.0 + x));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 5e-17) {
tmp = (1.0 / (sqrt(x) + t_0)) / x;
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((1.0d0 + x))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 5d-17) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / x
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((1.0 + x));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 5e-17) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / x;
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((1.0 + x)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 5e-17: tmp = (1.0 / (math.sqrt(x) + t_0)) / x else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 5e-17) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / x); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((1.0 + x)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 5e-17) tmp = (1.0 / (sqrt(x) + t_0)) / x; else tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 5e-17], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 5 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999999e-17Initial program 34.4%
frac-sub34.4%
*-un-lft-identity34.4%
*-rgt-identity34.4%
+-commutative34.4%
sqrt-unprod34.4%
+-commutative34.4%
Applied egg-rr34.4%
flip--34.3%
div-inv34.3%
add-sqr-sqrt35.8%
add-sqr-sqrt36.7%
Applied egg-rr36.7%
associate-*r/36.7%
*-rgt-identity36.7%
associate--l+85.2%
+-inverses85.2%
metadata-eval85.2%
Simplified85.2%
Taylor expanded in x around inf 99.1%
if 4.9999999999999999e-17 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.6%
associate--l-99.6%
fma-udef99.6%
distribute-lft1-in99.6%
metadata-eval99.6%
mul0-lft99.6%
metadata-eval99.6%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 5e-17) (* 0.5 (sqrt (/ 1.0 (pow x 3.0)))) (- (pow x -0.5) (pow (+ 1.0 x) -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-17) {
tmp = 0.5 * sqrt((1.0 / pow(x, 3.0)));
} else {
tmp = pow(x, -0.5) - pow((1.0 + x), -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((1.0d0 + x)))) <= 5d-17) then
tmp = 0.5d0 * sqrt((1.0d0 / (x ** 3.0d0)))
else
tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-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((1.0 + x)))) <= 5e-17) {
tmp = 0.5 * Math.sqrt((1.0 / Math.pow(x, 3.0)));
} else {
tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 5e-17: tmp = 0.5 * math.sqrt((1.0 / math.pow(x, 3.0))) else: tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5) return tmp
function code(x) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / sqrt(Float64(1.0 + x)))) <= 5e-17) tmp = Float64(0.5 * sqrt(Float64(1.0 / (x ^ 3.0)))); else tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 5e-17) tmp = 0.5 * sqrt((1.0 / (x ^ 3.0))); else tmp = (x ^ -0.5) - ((1.0 + x) ^ -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[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-17], N[(0.5 * N[Sqrt[N[(1.0 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-17}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{1}{{x}^{3}}}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 4.9999999999999999e-17Initial program 34.4%
*-un-lft-identity34.4%
clear-num34.4%
associate-/r/34.4%
prod-diff34.4%
*-un-lft-identity34.4%
fma-neg34.4%
*-un-lft-identity34.4%
pow1/234.4%
pow-flip21.2%
metadata-eval21.2%
pow1/221.2%
pow-flip34.4%
+-commutative34.4%
metadata-eval34.4%
Applied egg-rr34.4%
associate-+l-34.4%
expm1-log1p34.4%
expm1-def5.3%
associate--l-5.3%
fma-udef5.3%
distribute-lft1-in5.3%
metadata-eval5.3%
mul0-lft5.3%
metadata-eval5.3%
expm1-def34.4%
expm1-log1p34.4%
Simplified34.4%
Taylor expanded in x around inf 69.2%
if 4.9999999999999999e-17 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-+l-99.8%
expm1-log1p99.8%
expm1-def99.6%
associate--l-99.6%
fma-udef99.6%
distribute-lft1-in99.6%
metadata-eval99.6%
mul0-lft99.6%
metadata-eval99.6%
expm1-def99.8%
expm1-log1p99.8%
Simplified99.8%
Final simplification83.1%
(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%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
Simplified99.2%
expm1-log1p-u92.4%
expm1-udef92.4%
pow1/292.4%
pow-flip92.4%
metadata-eval92.4%
Applied egg-rr92.4%
expm1-def92.4%
expm1-log1p99.6%
Simplified99.6%
if 1.69999999999999996 < x Initial program 34.6%
*-un-lft-identity34.6%
clear-num34.6%
associate-/r/34.6%
prod-diff34.6%
*-un-lft-identity34.6%
fma-neg34.6%
*-un-lft-identity34.6%
pow1/234.6%
pow-flip21.6%
metadata-eval21.6%
pow1/221.6%
pow-flip34.7%
+-commutative34.7%
metadata-eval34.7%
Applied egg-rr34.7%
associate-+l-34.7%
expm1-log1p34.7%
expm1-def5.6%
associate--l-5.6%
fma-udef5.6%
distribute-lft1-in5.6%
metadata-eval5.6%
mul0-lft5.6%
metadata-eval5.6%
expm1-def34.7%
expm1-log1p34.7%
Simplified34.7%
Taylor expanded in x around inf 69.0%
Final simplification82.8%
(FPCore (x) :precision binary64 (if (<= x 6.0) (- (pow x -0.5) (/ 1.0 (+ 1.0 (* x 0.5)))) (/ 1.0 (sqrt (* x (+ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 6.0) {
tmp = pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 1.0 / sqrt((x * (1.0 + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 6.0d0) then
tmp = (x ** (-0.5d0)) - (1.0d0 / (1.0d0 + (x * 0.5d0)))
else
tmp = 1.0d0 / sqrt((x * (1.0d0 + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 6.0) {
tmp = Math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5)));
} else {
tmp = 1.0 / Math.sqrt((x * (1.0 + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 6.0: tmp = math.pow(x, -0.5) - (1.0 / (1.0 + (x * 0.5))) else: tmp = 1.0 / math.sqrt((x * (1.0 + x))) return tmp
function code(x) tmp = 0.0 if (x <= 6.0) tmp = Float64((x ^ -0.5) - Float64(1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 6.0) tmp = (x ^ -0.5) - (1.0 / (1.0 + (x * 0.5))); else tmp = 1.0 / sqrt((x * (1.0 + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 6.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[(1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6:\\
\;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if x < 6Initial program 99.6%
Taylor expanded in x around 0 99.2%
*-commutative99.2%
Simplified99.2%
expm1-log1p-u92.4%
expm1-udef92.4%
pow1/292.4%
pow-flip92.4%
metadata-eval92.4%
Applied egg-rr92.4%
expm1-def92.4%
expm1-log1p99.6%
Simplified99.6%
if 6 < x Initial program 34.6%
frac-sub34.7%
*-un-lft-identity34.7%
*-rgt-identity34.7%
+-commutative34.7%
sqrt-unprod34.7%
+-commutative34.7%
Applied egg-rr34.7%
Taylor expanded in x around 0 35.2%
Final simplification64.4%
(FPCore (x) :precision binary64 (if (<= x 1.4) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ 1.0 (sqrt (* x (+ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 1.0 / sqrt((x * (1.0 + x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.4d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / sqrt((x * (1.0d0 + x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 1.0 / Math.sqrt((x * (1.0 + x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.4: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = 1.0 / math.sqrt((x * (1.0 + x))) return tmp
function code(x) tmp = 0.0 if (x <= 1.4) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = 1.0 / sqrt((x * (1.0 + x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.4], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
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%
Simplified100.0%
Taylor expanded in x around 0 99.5%
if 1.3999999999999999 < x Initial program 34.6%
frac-sub34.7%
*-un-lft-identity34.7%
*-rgt-identity34.7%
+-commutative34.7%
sqrt-unprod34.7%
+-commutative34.7%
Applied egg-rr34.7%
Taylor expanded in x around 0 35.2%
Final simplification64.3%
(FPCore (x) :precision binary64 (/ 1.0 (sqrt (* x (+ 1.0 x)))))
double code(double x) {
return 1.0 / sqrt((x * (1.0 + x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / sqrt((x * (1.0d0 + x)))
end function
public static double code(double x) {
return 1.0 / Math.sqrt((x * (1.0 + x)));
}
def code(x): return 1.0 / math.sqrt((x * (1.0 + x)))
function code(x) return Float64(1.0 / sqrt(Float64(x * Float64(1.0 + x)))) end
function tmp = code(x) tmp = 1.0 / sqrt((x * (1.0 + x))); end
code[x_] := N[(1.0 / N[Sqrt[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}
\end{array}
Initial program 64.1%
frac-sub64.1%
*-un-lft-identity64.1%
*-rgt-identity64.1%
+-commutative64.1%
sqrt-unprod64.1%
+-commutative64.1%
Applied egg-rr64.1%
Taylor expanded in x around 0 62.5%
Final simplification62.5%
(FPCore (x) :precision binary64 (if (<= x 0.58) (+ (pow x -0.5) -1.0) (/ 1.0 (+ x 0.5))))
double code(double x) {
double tmp;
if (x <= 0.58) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / (x + 0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.58d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / (x + 0.5d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.58) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / (x + 0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.58: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / (x + 0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.58) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / Float64(x + 0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.58) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / (x + 0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.58], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.58:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x + 0.5}\\
\end{array}
\end{array}
if x < 0.57999999999999996Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
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%
Simplified100.0%
Taylor expanded in x around 0 98.8%
if 0.57999999999999996 < x Initial program 34.6%
frac-sub34.7%
*-un-lft-identity34.7%
*-rgt-identity34.7%
+-commutative34.7%
sqrt-unprod34.7%
+-commutative34.7%
Applied egg-rr34.7%
Taylor expanded in x around 0 35.2%
Taylor expanded in x around inf 8.1%
+-commutative8.1%
Simplified8.1%
Final simplification49.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 64.1%
flip--64.1%
div-inv64.0%
frac-times57.1%
metadata-eval57.1%
add-sqr-sqrt54.4%
frac-times55.3%
metadata-eval55.3%
add-sqr-sqrt64.1%
+-commutative64.1%
pow1/264.1%
pow-flip64.0%
metadata-eval64.0%
inv-pow64.0%
sqrt-pow264.0%
+-commutative64.0%
metadata-eval64.0%
Applied egg-rr64.0%
Taylor expanded in x around 0 48.4%
distribute-rgt-in48.4%
*-lft-identity48.4%
pow-plus48.6%
metadata-eval48.6%
Simplified48.6%
Final simplification48.6%
(FPCore (x) :precision binary64 (/ 1.0 (+ x 0.5)))
double code(double x) {
return 1.0 / (x + 0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + 0.5d0)
end function
public static double code(double x) {
return 1.0 / (x + 0.5);
}
def code(x): return 1.0 / (x + 0.5)
function code(x) return Float64(1.0 / Float64(x + 0.5)) end
function tmp = code(x) tmp = 1.0 / (x + 0.5); end
code[x_] := N[(1.0 / N[(x + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + 0.5}
\end{array}
Initial program 64.1%
frac-sub64.1%
*-un-lft-identity64.1%
*-rgt-identity64.1%
+-commutative64.1%
sqrt-unprod64.1%
+-commutative64.1%
Applied egg-rr64.1%
Taylor expanded in x around 0 62.5%
Taylor expanded in x around inf 7.7%
+-commutative7.7%
Simplified7.7%
Final simplification7.7%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 64.1%
frac-sub64.1%
*-un-lft-identity64.1%
*-rgt-identity64.1%
+-commutative64.1%
sqrt-unprod64.1%
+-commutative64.1%
Applied egg-rr64.1%
Taylor expanded in x around 0 62.5%
Taylor expanded in x around inf 7.7%
Final simplification7.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 2023315
(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)))))