
(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
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-9)
(* (+ (/ 0.5 x) (- (/ 0.3125 (pow x 3.0)) (/ 0.375 (* x x)))) (pow x -0.5))
(fma
(- 0.0 (pow (+ 1.0 x) -0.3333333333333333))
(cbrt (pow (+ 1.0 x) -0.5))
(pow x -0.5))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-9) {
tmp = ((0.5 / x) + ((0.3125 / pow(x, 3.0)) - (0.375 / (x * x)))) * pow(x, -0.5);
} else {
tmp = fma((0.0 - pow((1.0 + x), -0.3333333333333333)), cbrt(pow((1.0 + x), -0.5)), pow(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 = Float64(Float64(Float64(0.5 / x) + Float64(Float64(0.3125 / (x ^ 3.0)) - Float64(0.375 / Float64(x * x)))) * (x ^ -0.5)); else tmp = fma(Float64(0.0 - (Float64(1.0 + x) ^ -0.3333333333333333)), cbrt((Float64(1.0 + x) ^ -0.5)), (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[(N[(0.5 / x), $MachinePrecision] + N[(N[(0.3125 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(0.0 - N[Power[N[(1.0 + x), $MachinePrecision], -0.3333333333333333], $MachinePrecision]), $MachinePrecision] * N[Power[N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision], 1/3], $MachinePrecision] + N[Power[x, -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}:\\
\;\;\;\;\left(\frac{0.5}{x} + \left(\frac{0.3125}{{x}^{3}} - \frac{0.375}{x \cdot x}\right)\right) \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0 - {\left(1 + x\right)}^{-0.3333333333333333}, \sqrt[3]{{\left(1 + x\right)}^{-0.5}}, {x}^{-0.5}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000012e-9Initial program 38.2%
frac-sub38.3%
div-inv38.3%
*-un-lft-identity38.3%
+-commutative38.3%
*-rgt-identity38.3%
metadata-eval38.3%
frac-times38.3%
un-div-inv38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
+-commutative38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
times-frac38.3%
div-sub38.3%
*-inverses38.3%
/-rgt-identity38.3%
Simplified38.3%
Taylor expanded in x around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
unpow299.7%
Simplified99.7%
if 2.00000000000000012e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
sub-neg99.4%
+-commutative99.4%
add-cube-cbrt99.4%
distribute-lft-neg-in99.4%
fma-def99.4%
Applied egg-rr99.9%
pow1/399.9%
inv-pow99.9%
pow-pow99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-9) (* (+ (/ 0.5 x) (- (/ 0.3125 (pow x 3.0)) (/ 0.375 (* x x)))) (pow x -0.5)) (* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-9) {
tmp = ((0.5 / x) + ((0.3125 / pow(x, 3.0)) - (0.375 / (x * x)))) * pow(x, -0.5);
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((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((1.0d0 + x)))) <= 2d-9) then
tmp = ((0.5d0 / x) + ((0.3125d0 / (x ** 3.0d0)) - (0.375d0 / (x * x)))) * (x ** (-0.5d0))
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((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((1.0 + x)))) <= 2e-9) {
tmp = ((0.5 / x) + ((0.3125 / Math.pow(x, 3.0)) - (0.375 / (x * x)))) * Math.pow(x, -0.5);
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 2e-9: tmp = ((0.5 / x) + ((0.3125 / math.pow(x, 3.0)) - (0.375 / (x * x)))) * math.pow(x, -0.5) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) 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 = Float64(Float64(Float64(0.5 / x) + Float64(Float64(0.3125 / (x ^ 3.0)) - Float64(0.375 / Float64(x * x)))) * (x ^ -0.5)); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(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((1.0 + x)))) <= 2e-9) tmp = ((0.5 / x) + ((0.3125 / (x ^ 3.0)) - (0.375 / (x * x)))) * (x ^ -0.5); else tmp = (x ^ -0.5) * (1.0 - sqrt((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[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-9], N[(N[(N[(0.5 / x), $MachinePrecision] + N[(N[(0.3125 / N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;\left(\frac{0.5}{x} + \left(\frac{0.3125}{{x}^{3}} - \frac{0.375}{x \cdot x}\right)\right) \cdot {x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000012e-9Initial program 38.2%
frac-sub38.3%
div-inv38.3%
*-un-lft-identity38.3%
+-commutative38.3%
*-rgt-identity38.3%
metadata-eval38.3%
frac-times38.3%
un-div-inv38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
+-commutative38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
times-frac38.3%
div-sub38.3%
*-inverses38.3%
/-rgt-identity38.3%
Simplified38.3%
Taylor expanded in x around inf 99.7%
associate--l+99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
unpow299.7%
Simplified99.7%
if 2.00000000000000012e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
frac-sub99.4%
div-inv99.4%
*-un-lft-identity99.4%
+-commutative99.4%
*-rgt-identity99.4%
metadata-eval99.4%
frac-times99.4%
un-div-inv99.4%
pow1/299.4%
pow-flip99.9%
metadata-eval99.9%
+-commutative99.9%
Applied egg-rr99.9%
associate-*r/99.9%
*-rgt-identity99.9%
times-frac99.9%
div-sub99.9%
*-inverses99.9%
/-rgt-identity99.9%
Simplified99.9%
expm1-log1p-u92.2%
expm1-udef92.1%
sqrt-undiv92.1%
Applied egg-rr92.1%
expm1-def92.2%
expm1-log1p99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-9) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x)) (* (pow x -0.5) (- 1.0 (sqrt (/ x (+ 1.0 x)))))))
double code(double x) {
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / sqrt((1.0 + x)))) <= 2e-9) {
tmp = pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
} else {
tmp = pow(x, -0.5) * (1.0 - sqrt((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((1.0d0 + x)))) <= 2d-9) then
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
else
tmp = (x ** (-0.5d0)) * (1.0d0 - sqrt((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((1.0 + x)))) <= 2e-9) {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
} else {
tmp = Math.pow(x, -0.5) * (1.0 - Math.sqrt((x / (1.0 + x))));
}
return tmp;
}
def code(x): tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / math.sqrt((1.0 + x)))) <= 2e-9: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) else: tmp = math.pow(x, -0.5) * (1.0 - math.sqrt((x / (1.0 + x)))) 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 = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); else tmp = Float64((x ^ -0.5) * Float64(1.0 - sqrt(Float64(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((1.0 + x)))) <= 2e-9) tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); else tmp = (x ^ -0.5) * (1.0 - sqrt((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[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e-9], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(1.0 - N[Sqrt[N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 2 \cdot 10^{-9}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{x}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \left(1 - \sqrt{\frac{x}{1 + x}}\right)\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000012e-9Initial program 38.2%
frac-sub38.3%
div-inv38.3%
*-un-lft-identity38.3%
+-commutative38.3%
*-rgt-identity38.3%
metadata-eval38.3%
frac-times38.3%
un-div-inv38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
+-commutative38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
times-frac38.3%
div-sub38.3%
*-inverses38.3%
/-rgt-identity38.3%
Simplified38.3%
Taylor expanded in x around inf 99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
unpow299.5%
Simplified99.5%
expm1-log1p-u99.5%
expm1-udef37.7%
*-commutative37.7%
associate-/r*37.7%
sub-div37.7%
Applied egg-rr37.7%
expm1-def99.5%
expm1-log1p99.5%
Simplified99.5%
if 2.00000000000000012e-9 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
frac-sub99.4%
div-inv99.4%
*-un-lft-identity99.4%
+-commutative99.4%
*-rgt-identity99.4%
metadata-eval99.4%
frac-times99.4%
un-div-inv99.4%
pow1/299.4%
pow-flip99.9%
metadata-eval99.9%
+-commutative99.9%
Applied egg-rr99.9%
associate-*r/99.9%
*-rgt-identity99.9%
times-frac99.9%
div-sub99.9%
*-inverses99.9%
/-rgt-identity99.9%
Simplified99.9%
expm1-log1p-u92.2%
expm1-udef92.1%
sqrt-undiv92.1%
Applied egg-rr92.1%
expm1-def92.2%
expm1-log1p99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 (sqrt (+ 1.0 x)))) 2e-9) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x)) (- (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 = pow(x, -0.5) * ((0.5 - (0.375 / x)) / 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) :: tmp
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / sqrt((1.0d0 + x)))) <= 2d-9) then
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
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)))) <= 2e-9) {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
} 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)))) <= 2e-9: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) 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)))) <= 2e-9) tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); 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)))) <= 2e-9) tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); 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], 2e-9], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $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}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{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)))) < 2.00000000000000012e-9Initial program 38.2%
frac-sub38.3%
div-inv38.3%
*-un-lft-identity38.3%
+-commutative38.3%
*-rgt-identity38.3%
metadata-eval38.3%
frac-times38.3%
un-div-inv38.3%
pow1/238.3%
pow-flip38.3%
metadata-eval38.3%
+-commutative38.3%
Applied egg-rr38.3%
associate-*r/38.3%
*-rgt-identity38.3%
times-frac38.3%
div-sub38.3%
*-inverses38.3%
/-rgt-identity38.3%
Simplified38.3%
Taylor expanded in x around inf 99.5%
associate-*r/99.5%
metadata-eval99.5%
associate-*r/99.5%
metadata-eval99.5%
unpow299.5%
Simplified99.5%
expm1-log1p-u99.5%
expm1-udef37.7%
*-commutative37.7%
associate-/r*37.7%
sub-div37.7%
Applied egg-rr37.7%
expm1-def99.5%
expm1-log1p99.5%
Simplified99.5%
if 2.00000000000000012e-9 < (-.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%
inv-pow99.4%
sqrt-pow299.9%
metadata-eval99.9%
pow1/299.9%
pow-flip99.9%
+-commutative99.9%
metadata-eval99.9%
Applied egg-rr99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
+-rgt-identity99.9%
Simplified99.9%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 1.1) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x))))
double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.1d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.1) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.1: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) return tmp
function code(x) tmp = 0.0 if (x <= 1.1) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.1) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.1], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{x}\\
\end{array}
\end{array}
if x < 1.1000000000000001Initial program 99.5%
inv-pow99.5%
pow1/299.5%
pow-pow100.0%
add-exp-log92.1%
pow-exp92.1%
metadata-eval92.1%
Applied egg-rr92.1%
Taylor expanded in x around 0 99.5%
if 1.1000000000000001 < x Initial program 39.2%
frac-sub39.3%
div-inv39.3%
*-un-lft-identity39.3%
+-commutative39.3%
*-rgt-identity39.3%
metadata-eval39.3%
frac-times39.3%
un-div-inv39.3%
pow1/239.3%
pow-flip39.3%
metadata-eval39.3%
+-commutative39.3%
Applied egg-rr39.3%
associate-*r/39.3%
*-rgt-identity39.3%
times-frac39.3%
div-sub39.3%
*-inverses39.3%
/-rgt-identity39.3%
Simplified39.3%
Taylor expanded in x around inf 98.3%
associate-*r/98.3%
metadata-eval98.3%
associate-*r/98.3%
metadata-eval98.3%
unpow298.3%
Simplified98.3%
expm1-log1p-u98.3%
expm1-udef37.7%
*-commutative37.7%
associate-/r*37.7%
sub-div37.7%
Applied egg-rr37.7%
expm1-def98.3%
expm1-log1p98.3%
Simplified98.3%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x 1.42) (+ (pow x -0.5) (/ -1.0 (+ 1.0 (* x 0.5)))) (* (pow x -0.5) (/ (- 0.5 (/ 0.375 x)) x))))
double code(double x) {
double tmp;
if (x <= 1.42) {
tmp = pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.42d0) then
tmp = (x ** (-0.5d0)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (x ** (-0.5d0)) * ((0.5d0 - (0.375d0 / x)) / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.42) {
tmp = Math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = Math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.42: tmp = math.pow(x, -0.5) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = math.pow(x, -0.5) * ((0.5 - (0.375 / x)) / x) return tmp
function code(x) tmp = 0.0 if (x <= 1.42) tmp = Float64((x ^ -0.5) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64((x ^ -0.5) * Float64(Float64(0.5 - Float64(0.375 / x)) / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.42) tmp = (x ^ -0.5) + (-1.0 / (1.0 + (x * 0.5))); else tmp = (x ^ -0.5) * ((0.5 - (0.375 / x)) / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.42], N[(N[Power[x, -0.5], $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] * N[(N[(0.5 - N[(0.375 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.42:\\
\;\;\;\;{x}^{-0.5} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} \cdot \frac{0.5 - \frac{0.375}{x}}{x}\\
\end{array}
\end{array}
if x < 1.4199999999999999Initial program 99.5%
Taylor expanded in x around 0 99.0%
add-log-exp4.0%
*-un-lft-identity4.0%
log-prod4.0%
metadata-eval4.0%
add-log-exp99.0%
pow1/299.0%
pow-flip99.5%
metadata-eval99.5%
Applied egg-rr99.5%
+-lft-identity99.5%
Simplified99.5%
if 1.4199999999999999 < x Initial program 39.2%
frac-sub39.3%
div-inv39.3%
*-un-lft-identity39.3%
+-commutative39.3%
*-rgt-identity39.3%
metadata-eval39.3%
frac-times39.3%
un-div-inv39.3%
pow1/239.3%
pow-flip39.3%
metadata-eval39.3%
+-commutative39.3%
Applied egg-rr39.3%
associate-*r/39.3%
*-rgt-identity39.3%
times-frac39.3%
div-sub39.3%
*-inverses39.3%
/-rgt-identity39.3%
Simplified39.3%
Taylor expanded in x around inf 98.3%
associate-*r/98.3%
metadata-eval98.3%
associate-*r/98.3%
metadata-eval98.3%
unpow298.3%
Simplified98.3%
expm1-log1p-u98.3%
expm1-udef37.7%
*-commutative37.7%
associate-/r*37.7%
sub-div37.7%
Applied egg-rr37.7%
expm1-def98.3%
expm1-log1p98.3%
Simplified98.3%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 1Initial program 99.5%
inv-pow99.5%
pow1/299.5%
pow-pow100.0%
add-exp-log92.1%
pow-exp92.1%
metadata-eval92.1%
Applied egg-rr92.1%
Taylor expanded in x around 0 99.5%
if 1 < x Initial program 39.2%
frac-sub39.3%
div-inv39.3%
*-un-lft-identity39.3%
+-commutative39.3%
*-rgt-identity39.3%
metadata-eval39.3%
frac-times39.3%
un-div-inv39.3%
pow1/239.3%
pow-flip39.3%
metadata-eval39.3%
+-commutative39.3%
Applied egg-rr39.3%
associate-*r/39.3%
*-rgt-identity39.3%
times-frac39.3%
div-sub39.3%
*-inverses39.3%
/-rgt-identity39.3%
Simplified39.3%
Taylor expanded in x around inf 97.2%
expm1-log1p-u97.2%
expm1-udef37.4%
*-commutative37.4%
Applied egg-rr37.4%
expm1-def97.2%
expm1-log1p97.2%
associate-*r/97.3%
*-commutative97.3%
associate-/l*96.0%
Simplified96.0%
div-inv96.0%
metadata-eval96.0%
div-inv96.0%
add-sqr-sqrt95.7%
pow-flip95.6%
metadata-eval95.6%
pow1/295.6%
pow395.7%
cube-div96.7%
pow1/296.7%
pow-flip96.8%
metadata-eval96.8%
pow-pow97.5%
metadata-eval97.5%
Applied egg-rr97.5%
Final simplification98.6%
(FPCore (x) :precision binary64 (if (<= x 0.5) (pow x -0.5) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.5) {
tmp = pow(x, -0.5);
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.5d0) then
tmp = x ** (-0.5d0)
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.5) {
tmp = Math.pow(x, -0.5);
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.5: tmp = math.pow(x, -0.5) else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.5) tmp = x ^ -0.5; else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.5) tmp = x ^ -0.5; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.5], N[Power[x, -0.5], $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.5:\\
\;\;\;\;{x}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.5Initial program 99.5%
inv-pow99.5%
pow1/299.5%
pow-pow100.0%
add-exp-log92.1%
pow-exp92.1%
metadata-eval92.1%
Applied egg-rr92.1%
Taylor expanded in x around inf 97.3%
inv-pow97.3%
sqrt-pow197.5%
metadata-eval97.5%
expm1-log1p-u89.9%
expm1-udef89.9%
Applied egg-rr89.9%
expm1-def89.9%
expm1-log1p97.5%
Simplified97.5%
if 0.5 < x Initial program 39.8%
frac-sub39.9%
div-inv39.8%
*-un-lft-identity39.8%
+-commutative39.8%
*-rgt-identity39.8%
metadata-eval39.8%
frac-times39.8%
un-div-inv39.8%
pow1/239.8%
pow-flip39.8%
metadata-eval39.8%
+-commutative39.8%
Applied egg-rr39.8%
associate-*r/39.9%
*-rgt-identity39.9%
times-frac39.8%
div-sub39.8%
*-inverses39.8%
/-rgt-identity39.8%
Simplified39.8%
Taylor expanded in x around inf 96.4%
expm1-log1p-u96.4%
expm1-udef37.3%
*-commutative37.3%
Applied egg-rr37.3%
expm1-def96.4%
expm1-log1p96.4%
associate-*r/96.6%
*-commutative96.6%
associate-/l*95.3%
Simplified95.3%
div-inv95.3%
metadata-eval95.3%
div-inv95.3%
add-sqr-sqrt95.0%
pow-flip94.9%
metadata-eval94.9%
pow1/294.9%
pow395.0%
cube-div96.0%
pow1/296.0%
pow-flip96.1%
metadata-eval96.1%
pow-pow96.7%
metadata-eval96.7%
Applied egg-rr96.7%
Final simplification97.2%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* 0.5 (pow x -1.5))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * pow(x, -1.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 0.5d0 * (x ** (-1.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 0.5 * Math.pow(x, -1.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 0.5 * math.pow(x, -1.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(0.5 * (x ^ -1.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = 0.5 * (x ^ -1.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[Power[x, -1.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-1.5}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.5%
inv-pow99.5%
pow1/299.5%
pow-pow100.0%
add-exp-log92.1%
pow-exp92.1%
metadata-eval92.1%
Applied egg-rr92.1%
Taylor expanded in x around 0 99.4%
if 0.680000000000000049 < x Initial program 39.2%
frac-sub39.3%
div-inv39.3%
*-un-lft-identity39.3%
+-commutative39.3%
*-rgt-identity39.3%
metadata-eval39.3%
frac-times39.3%
un-div-inv39.3%
pow1/239.3%
pow-flip39.3%
metadata-eval39.3%
+-commutative39.3%
Applied egg-rr39.3%
associate-*r/39.3%
*-rgt-identity39.3%
times-frac39.3%
div-sub39.3%
*-inverses39.3%
/-rgt-identity39.3%
Simplified39.3%
Taylor expanded in x around inf 97.2%
expm1-log1p-u97.2%
expm1-udef37.4%
*-commutative37.4%
Applied egg-rr37.4%
expm1-def97.2%
expm1-log1p97.2%
associate-*r/97.3%
*-commutative97.3%
associate-/l*96.0%
Simplified96.0%
div-inv96.0%
metadata-eval96.0%
div-inv96.0%
add-sqr-sqrt95.7%
pow-flip95.6%
metadata-eval95.6%
pow1/295.6%
pow395.7%
cube-div96.7%
pow1/296.7%
pow-flip96.8%
metadata-eval96.8%
pow-pow97.5%
metadata-eval97.5%
Applied egg-rr97.5%
Final simplification98.6%
(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 74.1%
inv-pow74.1%
pow1/274.1%
pow-pow70.9%
add-exp-log56.4%
pow-exp56.4%
metadata-eval56.4%
Applied egg-rr56.4%
Taylor expanded in x around inf 58.2%
inv-pow58.2%
sqrt-pow158.4%
metadata-eval58.4%
expm1-log1p-u54.0%
expm1-udef67.1%
Applied egg-rr67.1%
expm1-def54.0%
expm1-log1p58.4%
Simplified58.4%
Final simplification58.4%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2023275
(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)))))