
(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 1e+81) (/ (pow x -0.5) (+ 1.0 (+ x (sqrt (fma x x x))))) (/ (/ 1.0 (sqrt x)) (+ x x))))
double code(double x) {
double tmp;
if (x <= 1e+81) {
tmp = pow(x, -0.5) / (1.0 + (x + sqrt(fma(x, x, x))));
} else {
tmp = (1.0 / sqrt(x)) / (x + x);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1e+81) tmp = Float64((x ^ -0.5) / Float64(1.0 + Float64(x + sqrt(fma(x, x, x))))); else tmp = Float64(Float64(1.0 / sqrt(x)) / Float64(x + x)); end return tmp end
code[x_] := If[LessEqual[x, 1e+81], N[(N[Power[x, -0.5], $MachinePrecision] / N[(1.0 + N[(x + N[Sqrt[N[(x * x + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] / N[(x + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+81}:\\
\;\;\;\;\frac{{x}^{-0.5}}{1 + \left(x + \sqrt{\mathsf{fma}\left(x, x, x\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x}}}{x + x}\\
\end{array}
\end{array}
if x < 9.99999999999999921e80Initial program 82.9%
frac-sub82.9%
associate-/r*82.9%
div-inv82.9%
associate-*r/82.9%
flip--83.5%
frac-times83.5%
Applied egg-rr85.6%
associate-/l*85.5%
associate--l+99.6%
+-inverses99.6%
metadata-eval99.6%
associate-/l*99.8%
*-lft-identity99.8%
*-commutative99.8%
+-commutative99.8%
distribute-lft-in99.8%
rem-square-sqrt99.8%
Simplified99.8%
add-sqr-sqrt_binary6499.6%
Applied rewrite-once99.6%
rem-square-sqrt99.8%
associate-+l+99.9%
+-commutative99.9%
sqrt-prod99.9%
+-commutative99.9%
distribute-lft1-in99.9%
fma-udef99.9%
Applied egg-rr99.9%
if 9.99999999999999921e80 < x Initial program 48.4%
frac-sub48.4%
associate-/r*48.4%
div-inv48.4%
associate-*r/48.4%
flip--48.4%
frac-times48.4%
Applied egg-rr48.4%
associate-/l*48.4%
associate--l+96.7%
+-inverses96.7%
metadata-eval96.7%
associate-/l*99.6%
*-lft-identity99.6%
*-commutative99.6%
+-commutative99.6%
distribute-lft-in99.6%
rem-square-sqrt99.7%
Simplified99.7%
clear-num96.8%
frac-2neg96.8%
div-inv96.8%
metadata-eval96.8%
metadata-eval96.8%
pow-flip96.7%
pow1/296.7%
div-inv96.8%
remove-double-div96.8%
*-commutative96.8%
associate-+l+96.8%
sqrt-unprod69.6%
+-commutative69.6%
distribute-lft1-in69.6%
fma-def69.6%
Applied egg-rr69.6%
associate-*r/69.6%
metadata-eval69.6%
neg-mul-169.6%
associate-/r*69.6%
metadata-eval69.6%
associate-/r*69.6%
associate-+r+69.6%
+-commutative69.6%
associate-+r+69.6%
Simplified69.6%
Taylor expanded in x around inf 99.8%
Taylor expanded in x around inf 99.8%
count-299.8%
Simplified99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (/ (pow x -0.5) (+ (+ x 1.0) (* (sqrt (+ x 1.0)) (sqrt x)))))
double code(double x) {
return pow(x, -0.5) / ((x + 1.0) + (sqrt((x + 1.0)) * sqrt(x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) / ((x + 1.0d0) + (sqrt((x + 1.0d0)) * sqrt(x)))
end function
public static double code(double x) {
return Math.pow(x, -0.5) / ((x + 1.0) + (Math.sqrt((x + 1.0)) * Math.sqrt(x)));
}
def code(x): return math.pow(x, -0.5) / ((x + 1.0) + (math.sqrt((x + 1.0)) * math.sqrt(x)))
function code(x) return Float64((x ^ -0.5) / Float64(Float64(x + 1.0) + Float64(sqrt(Float64(x + 1.0)) * sqrt(x)))) end
function tmp = code(x) tmp = (x ^ -0.5) / ((x + 1.0) + (sqrt((x + 1.0)) * sqrt(x))); end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] + N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x + 1} \cdot \sqrt{x}}
\end{array}
Initial program 70.2%
frac-sub70.3%
associate-/r*70.2%
div-inv70.3%
associate-*r/70.3%
flip--70.6%
frac-times70.6%
Applied egg-rr72.0%
associate-/l*71.9%
associate--l+98.5%
+-inverses98.5%
metadata-eval98.5%
associate-/l*99.7%
*-lft-identity99.7%
*-commutative99.7%
+-commutative99.7%
distribute-lft-in99.7%
rem-square-sqrt99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 650.0) (- (pow x -0.5) (pow (+ x 1.0) -0.5)) (/ (pow x -0.5) (+ (/ (+ -0.125 (/ 0.0625 x)) x) (- 1.5 (* x -2.0))))))
double code(double x) {
double tmp;
if (x <= 650.0) {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
} else {
tmp = pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 650.0d0) then
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = (x ** (-0.5d0)) / ((((-0.125d0) + (0.0625d0 / x)) / x) + (1.5d0 - (x * (-2.0d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 650.0) {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
} else {
tmp = Math.pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 650.0: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) else: tmp = math.pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0))) return tmp
function code(x) tmp = 0.0 if (x <= 650.0) tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64((x ^ -0.5) / Float64(Float64(Float64(-0.125 + Float64(0.0625 / x)) / x) + Float64(1.5 - Float64(x * -2.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 650.0) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); else tmp = (x ^ -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 650.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[(N[(-0.125 + N[(0.0625 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(1.5 - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 650:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\frac{-0.125 + \frac{0.0625}{x}}{x} + \left(1.5 - x \cdot -2\right)}\\
\end{array}
\end{array}
if x < 650Initial program 99.6%
sub-neg99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
+-commutative100.0%
Applied egg-rr100.0%
remove-double-neg100.0%
distribute-neg-frac100.0%
metadata-eval100.0%
+-commutative100.0%
rem-exp-log100.0%
+-commutative100.0%
unpow-1100.0%
log-pow100.0%
unpow1/2100.0%
log-pow100.0%
log1p-def100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
metadata-eval100.0%
exp-prod100.0%
Simplified100.0%
if 650 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around -inf 0.0%
associate-+r+0.0%
+-commutative0.0%
Simplified99.8%
+-commutative99.8%
associate-+l-99.8%
flip--77.4%
metadata-eval77.4%
Applied egg-rr77.4%
associate--r+77.4%
associate-/l/77.4%
associate--r+77.4%
associate-/l/77.4%
associate--r+77.4%
associate-/l/77.4%
Simplified77.4%
metadata-eval77.4%
flip--99.8%
associate--l-99.8%
associate--r-99.8%
associate-/r*99.8%
div-inv99.8%
div-inv99.8%
distribute-rgt-in99.8%
+-commutative99.8%
associate-*l/99.8%
*-lft-identity99.8%
Applied egg-rr99.8%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 0.44) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (pow x -0.5) (+ (/ (+ -0.125 (/ 0.0625 x)) x) (- 1.5 (* x -2.0))))))
double code(double x) {
double tmp;
if (x <= 0.44) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.44d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) / ((((-0.125d0) + (0.0625d0 / x)) / x) + (1.5d0 - (x * (-2.0d0))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.44) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.44: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0))) return tmp
function code(x) tmp = 0.0 if (x <= 0.44) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(Float64(Float64(-0.125 + Float64(0.0625 / x)) / x) + Float64(1.5 - Float64(x * -2.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.44) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) / (((-0.125 + (0.0625 / x)) / x) + (1.5 - (x * -2.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.44], 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[(N[(-0.125 + N[(0.0625 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] + N[(1.5 - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.44:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\frac{-0.125 + \frac{0.0625}{x}}{x} + \left(1.5 - x \cdot -2\right)}\\
\end{array}
\end{array}
if x < 0.440000000000000002Initial program 99.6%
inv-pow99.6%
metadata-eval99.6%
sqr-pow99.2%
pow299.2%
sqrt-pow299.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 97.3%
*-lft-identity97.3%
fma-def97.3%
inv-pow97.3%
metadata-eval97.3%
sqrt-pow198.2%
metadata-eval98.2%
metadata-eval98.2%
*-commutative98.2%
Applied egg-rr98.2%
fma-udef98.2%
*-lft-identity98.2%
Simplified98.2%
if 0.440000000000000002 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around -inf 0.0%
associate-+r+0.0%
+-commutative0.0%
Simplified99.8%
+-commutative99.8%
associate-+l-99.8%
flip--77.4%
metadata-eval77.4%
Applied egg-rr77.4%
associate--r+77.4%
associate-/l/77.4%
associate--r+77.4%
associate-/l/77.4%
associate--r+77.4%
associate-/l/77.4%
Simplified77.4%
metadata-eval77.4%
flip--99.8%
associate--l-99.8%
associate--r-99.8%
associate-/r*99.8%
div-inv99.8%
div-inv99.8%
distribute-rgt-in99.8%
+-commutative99.8%
associate-*l/99.8%
*-lft-identity99.8%
Applied egg-rr99.8%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (<= x 0.42) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (pow x -0.5) (- (+ 1.5 (* x 2.0)) (/ 0.125 x)))))
double code(double x) {
double tmp;
if (x <= 0.42) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) / ((1.5 + (x * 2.0)) - (0.125 / x));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.42d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) / ((1.5d0 + (x * 2.0d0)) - (0.125d0 / x))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.42) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) / ((1.5 + (x * 2.0)) - (0.125 / x));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.42: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) / ((1.5 + (x * 2.0)) - (0.125 / x)) return tmp
function code(x) tmp = 0.0 if (x <= 0.42) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(Float64(1.5 + Float64(x * 2.0)) - Float64(0.125 / x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.42) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) / ((1.5 + (x * 2.0)) - (0.125 / x)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.42], 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[(1.5 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.42:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\left(1.5 + x \cdot 2\right) - \frac{0.125}{x}}\\
\end{array}
\end{array}
if x < 0.419999999999999984Initial program 99.6%
inv-pow99.6%
metadata-eval99.6%
sqr-pow99.2%
pow299.2%
sqrt-pow299.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 97.3%
*-lft-identity97.3%
fma-def97.3%
inv-pow97.3%
metadata-eval97.3%
sqrt-pow198.2%
metadata-eval98.2%
metadata-eval98.2%
*-commutative98.2%
Applied egg-rr98.2%
fma-udef98.2%
*-lft-identity98.2%
Simplified98.2%
if 0.419999999999999984 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 99.6%
+-commutative99.6%
*-commutative99.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (pow x -0.5) (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) / (x * 2.0);
}
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 = (x ** (-0.5d0)) / (x * 2.0d0)
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 = Math.pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) / (x * 2.0) 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((x ^ -0.5) / Float64(x * 2.0)); 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 = (x ^ -0.5) / (x * 2.0); 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[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0), $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}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
inv-pow99.6%
metadata-eval99.6%
sqr-pow99.2%
pow299.2%
sqrt-pow299.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 97.3%
*-lft-identity97.3%
fma-def97.3%
inv-pow97.3%
metadata-eval97.3%
sqrt-pow198.2%
metadata-eval98.2%
metadata-eval98.2%
*-commutative98.2%
Applied egg-rr98.2%
fma-udef98.2%
*-lft-identity98.2%
Simplified98.2%
if 1 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 97.3%
*-commutative97.3%
Simplified97.3%
Final simplification97.8%
(FPCore (x) :precision binary64 (if (<= x 0.41) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (/ (pow x -0.5) (- 1.5 (* x -2.0)))))
double code(double x) {
double tmp;
if (x <= 0.41) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = pow(x, -0.5) / (1.5 - (x * -2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.41d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) / (1.5d0 - (x * (-2.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.41) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.pow(x, -0.5) / (1.5 - (x * -2.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.41: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.pow(x, -0.5) / (1.5 - (x * -2.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.41) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(1.5 - Float64(x * -2.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.41) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = (x ^ -0.5) / (1.5 - (x * -2.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.41], 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[(1.5 - N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.41:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{1.5 - x \cdot -2}\\
\end{array}
\end{array}
if x < 0.409999999999999976Initial program 99.6%
inv-pow99.6%
metadata-eval99.6%
sqr-pow99.2%
pow299.2%
sqrt-pow299.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around 0 97.3%
*-lft-identity97.3%
fma-def97.3%
inv-pow97.3%
metadata-eval97.3%
sqrt-pow198.2%
metadata-eval98.2%
metadata-eval98.2%
*-commutative98.2%
Applied egg-rr98.2%
fma-udef98.2%
*-lft-identity98.2%
Simplified98.2%
if 0.409999999999999976 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around -inf 0.0%
mul-1-neg0.0%
unsub-neg0.0%
sub-neg0.0%
unpow20.0%
rem-square-sqrt99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= x 0.65) (+ (pow x -0.5) -1.0) (/ (pow x -0.5) (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 0.65) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.65d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (x ** (-0.5d0)) / (x * 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.65) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = Math.pow(x, -0.5) / (x * 2.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.65: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow(x, -0.5) / (x * 2.0) return tmp
function code(x) tmp = 0.0 if (x <= 0.65) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64((x ^ -0.5) / Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.65) tmp = (x ^ -0.5) + -1.0; else tmp = (x ^ -0.5) / (x * 2.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.65], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.65:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x \cdot 2}\\
\end{array}
\end{array}
if x < 0.650000000000000022Initial program 99.6%
Taylor expanded in x around 0 97.0%
div-inv97.0%
pow1/297.0%
pow-flip97.4%
metadata-eval97.4%
Applied egg-rr97.4%
*-lft-identity97.4%
Simplified97.4%
if 0.650000000000000022 < x Initial program 40.5%
frac-sub40.5%
associate-/r*40.5%
div-inv40.5%
associate-*r/40.5%
flip--41.3%
frac-times41.3%
Applied egg-rr43.6%
associate-/l*43.6%
associate--l+97.3%
+-inverses97.3%
metadata-eval97.3%
associate-/l*99.5%
*-lft-identity99.5%
*-commutative99.5%
+-commutative99.5%
distribute-lft-in99.5%
rem-square-sqrt99.6%
Simplified99.6%
Taylor expanded in x around inf 97.3%
*-commutative97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x) :precision binary64 (if (<= x 0.8) (+ (pow x -0.5) -1.0) (pow (* x x) -0.25)))
double code(double x) {
double tmp;
if (x <= 0.8) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = pow((x * x), -0.25);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.8d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = (x * x) ** (-0.25d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.8) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = Math.pow((x * x), -0.25);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.8: tmp = math.pow(x, -0.5) + -1.0 else: tmp = math.pow((x * x), -0.25) return tmp
function code(x) tmp = 0.0 if (x <= 0.8) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(x * x) ^ -0.25; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.8) tmp = (x ^ -0.5) + -1.0; else tmp = (x * x) ^ -0.25; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.8], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[N[(x * x), $MachinePrecision], -0.25], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.8:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 0.80000000000000004Initial program 99.6%
Taylor expanded in x around 0 97.0%
div-inv97.0%
pow1/297.0%
pow-flip97.4%
metadata-eval97.4%
Applied egg-rr97.4%
*-lft-identity97.4%
Simplified97.4%
if 0.80000000000000004 < x Initial program 40.5%
inv-pow40.5%
metadata-eval40.5%
sqr-pow23.3%
pow223.3%
sqrt-pow223.2%
metadata-eval23.2%
metadata-eval23.2%
metadata-eval23.2%
Applied egg-rr23.2%
Taylor expanded in x around inf 5.6%
inv-pow5.6%
metadata-eval5.6%
sqrt-pow15.6%
metadata-eval5.6%
metadata-eval5.6%
sqr-pow5.6%
pow-prod-down38.1%
metadata-eval38.1%
Applied egg-rr38.1%
Final simplification68.0%
(FPCore (x) :precision binary64 (+ (pow x -0.5) -1.0))
double code(double x) {
return pow(x, -0.5) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x ** (-0.5d0)) + (-1.0d0)
end function
public static double code(double x) {
return Math.pow(x, -0.5) + -1.0;
}
def code(x): return math.pow(x, -0.5) + -1.0
function code(x) return Float64((x ^ -0.5) + -1.0) end
function tmp = code(x) tmp = (x ^ -0.5) + -1.0; end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
{x}^{-0.5} + -1
\end{array}
Initial program 70.2%
Taylor expanded in x around 0 50.1%
div-inv50.1%
pow1/250.1%
pow-flip50.3%
metadata-eval50.3%
Applied egg-rr50.3%
*-lft-identity50.3%
Simplified50.3%
Final simplification50.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 70.2%
inv-pow70.2%
metadata-eval70.2%
sqr-pow61.5%
pow261.5%
sqrt-pow261.5%
metadata-eval61.5%
metadata-eval61.5%
metadata-eval61.5%
Applied egg-rr61.5%
Taylor expanded in x around inf 49.4%
*-lft-identity49.4%
inv-pow49.4%
metadata-eval49.4%
sqrt-pow149.9%
metadata-eval49.9%
metadata-eval49.9%
Applied egg-rr49.9%
*-lft-identity49.9%
Simplified49.9%
Final simplification49.9%
(FPCore (x) :precision binary64 (+ (* x 0.5) -1.0))
double code(double x) {
return (x * 0.5) + -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 0.5d0) + (-1.0d0)
end function
public static double code(double x) {
return (x * 0.5) + -1.0;
}
def code(x): return (x * 0.5) + -1.0
function code(x) return Float64(Float64(x * 0.5) + -1.0) end
function tmp = code(x) tmp = (x * 0.5) + -1.0; end
code[x_] := N[(N[(x * 0.5), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5 + -1
\end{array}
Initial program 70.2%
inv-pow70.2%
metadata-eval70.2%
sqr-pow61.5%
pow261.5%
sqrt-pow261.5%
metadata-eval61.5%
metadata-eval61.5%
metadata-eval61.5%
Applied egg-rr61.5%
Taylor expanded in x around 0 50.7%
Taylor expanded in x around inf 2.3%
*-commutative2.3%
Simplified2.3%
Final simplification2.3%
(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 70.2%
Taylor expanded in x around 0 50.1%
Taylor expanded in x around inf 1.9%
Final simplification1.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2023297
(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)))))