
(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 11 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)))) 5e-17) (* (- (/ 0.5 x) (/ 0.375 (* x x))) (pow x -0.5)) (- (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 / x) - (0.375 / (x * x))) * pow(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) :: tmp
if (((1.0d0 / sqrt(x)) - (1.0d0 / sqrt((1.0d0 + x)))) <= 5d-17) then
tmp = ((0.5d0 / x) - (0.375d0 / (x * x))) * (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 tmp;
if (((1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((1.0 + x)))) <= 5e-17) {
tmp = ((0.5 / x) - (0.375 / (x * x))) * Math.pow(x, -0.5);
} 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 / x) - (0.375 / (x * x))) * math.pow(x, -0.5) 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(Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x))) * (x ^ -0.5)); 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 / x) - (0.375 / (x * x))) * (x ^ -0.5); 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[(N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[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}
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-17}:\\
\;\;\;\;\left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right) \cdot {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)))) < 4.9999999999999999e-17Initial program 27.5%
frac-sub27.5%
div-inv27.5%
*-un-lft-identity27.5%
+-commutative27.5%
*-rgt-identity27.5%
metadata-eval27.5%
frac-times27.5%
un-div-inv27.5%
pow1/227.5%
pow-flip27.5%
metadata-eval27.5%
+-commutative27.5%
Applied egg-rr27.5%
associate-*r/27.5%
*-rgt-identity27.5%
times-frac27.5%
div-sub27.5%
*-inverses27.5%
unpow127.5%
sqr-pow27.5%
metadata-eval27.5%
exp-to-pow5.0%
metadata-eval5.0%
exp-to-pow4.9%
hypot-1-def4.9%
exp-to-pow27.5%
unpow1/227.5%
/-rgt-identity27.5%
Simplified27.5%
*-un-lft-identity27.5%
hypot-1-def27.5%
add-sqr-sqrt27.5%
sqrt-undiv27.5%
Applied egg-rr27.5%
*-lft-identity27.5%
Simplified27.5%
Taylor expanded in x around inf 99.7%
associate-*r/99.7%
metadata-eval99.7%
associate-*r/99.7%
metadata-eval99.7%
unpow299.7%
Simplified99.7%
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%
inv-pow99.4%
sqrt-pow299.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
fma-udef99.8%
neg-mul-199.8%
rem-log-exp99.7%
log-rec99.7%
+-commutative99.7%
log-rec99.7%
rem-log-exp99.8%
sub-neg99.8%
+-inverses99.8%
+-rgt-identity99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.45) (+ (/ 1.0 (sqrt x)) (/ -1.0 (+ 1.0 (* x 0.5)))) (* (- (/ 0.5 x) (/ 0.375 (* x x))) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 1.45) {
tmp = (1.0 / sqrt(x)) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = ((0.5 / x) - (0.375 / (x * x))) * pow(x, -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.45d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = ((0.5d0 / x) - (0.375d0 / (x * x))) * (x ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.45) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = ((0.5 / x) - (0.375 / (x * x))) * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.45: tmp = (1.0 / math.sqrt(x)) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = ((0.5 / x) - (0.375 / (x * x))) * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 1.45) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x))) * (x ^ -0.5)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.45) tmp = (1.0 / sqrt(x)) + (-1.0 / (1.0 + (x * 0.5))); else tmp = ((0.5 / x) - (0.375 / (x * x))) * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.45], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.45:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{0.5}{x} - \frac{0.375}{x \cdot x}\right) \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 1.44999999999999996Initial program 99.6%
Taylor expanded in x around 0 98.3%
*-commutative98.3%
Simplified98.3%
if 1.44999999999999996 < x Initial program 29.6%
frac-sub29.6%
div-inv29.6%
*-un-lft-identity29.6%
+-commutative29.6%
*-rgt-identity29.6%
metadata-eval29.6%
frac-times29.7%
un-div-inv29.7%
pow1/229.7%
pow-flip29.7%
metadata-eval29.7%
+-commutative29.7%
Applied egg-rr29.7%
associate-*r/29.7%
*-rgt-identity29.7%
times-frac29.7%
div-sub29.6%
*-inverses29.6%
unpow129.6%
sqr-pow29.6%
metadata-eval29.6%
exp-to-pow7.9%
metadata-eval7.9%
exp-to-pow7.7%
hypot-1-def7.7%
exp-to-pow29.6%
unpow1/229.6%
/-rgt-identity29.6%
Simplified29.6%
*-un-lft-identity29.6%
hypot-1-def29.6%
add-sqr-sqrt29.6%
sqrt-undiv29.6%
Applied egg-rr29.6%
*-lft-identity29.6%
Simplified29.6%
Taylor expanded in x around inf 97.5%
associate-*r/97.5%
metadata-eval97.5%
associate-*r/97.5%
metadata-eval97.5%
unpow297.5%
Simplified97.5%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= x 1.7) (+ (/ 1.0 (sqrt x)) (/ -1.0 (+ 1.0 (* x 0.5)))) (/ (* 0.5 (pow x -0.5)) x)))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = (1.0 / sqrt(x)) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (0.5 * pow(x, -0.5)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) / (1.0d0 + (x * 0.5d0)))
else
tmp = (0.5d0 * (x ** (-0.5d0))) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 / (1.0 + (x * 0.5)));
} else {
tmp = (0.5 * Math.pow(x, -0.5)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = (1.0 / math.sqrt(x)) + (-1.0 / (1.0 + (x * 0.5))) else: tmp = (0.5 * math.pow(x, -0.5)) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / Float64(1.0 + Float64(x * 0.5)))); else tmp = Float64(Float64(0.5 * (x ^ -0.5)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = (1.0 / sqrt(x)) + (-1.0 / (1.0 + (x * 0.5))); else tmp = (0.5 * (x ^ -0.5)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(1.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \frac{-1}{1 + x \cdot 0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot {x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.6%
Taylor expanded in x around 0 98.3%
*-commutative98.3%
Simplified98.3%
if 1.69999999999999996 < x Initial program 29.6%
frac-sub29.6%
div-inv29.6%
*-un-lft-identity29.6%
+-commutative29.6%
*-rgt-identity29.6%
metadata-eval29.6%
frac-times29.7%
un-div-inv29.7%
pow1/229.7%
pow-flip29.7%
metadata-eval29.7%
+-commutative29.7%
Applied egg-rr29.7%
associate-*r/29.7%
*-rgt-identity29.7%
times-frac29.7%
div-sub29.6%
*-inverses29.6%
unpow129.6%
sqr-pow29.6%
metadata-eval29.6%
exp-to-pow7.9%
metadata-eval7.9%
exp-to-pow7.7%
hypot-1-def7.7%
exp-to-pow29.6%
unpow1/229.6%
/-rgt-identity29.6%
Simplified29.6%
*-un-lft-identity29.6%
hypot-1-def29.6%
add-sqr-sqrt29.6%
sqrt-undiv29.6%
Applied egg-rr29.6%
*-lft-identity29.6%
Simplified29.6%
Taylor expanded in x around inf 97.1%
associate-*l/97.1%
Applied egg-rr97.1%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (/ 1.0 (sqrt x)) (- -1.0 (* x -0.5))) (/ (* 0.5 (pow x -0.5)) x)))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (1.0 / sqrt(x)) + (-1.0 - (x * -0.5));
} else {
tmp = (0.5 * pow(x, -0.5)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) - (x * (-0.5d0)))
else
tmp = (0.5d0 * (x ** (-0.5d0))) / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 - (x * -0.5));
} else {
tmp = (0.5 * Math.pow(x, -0.5)) / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (1.0 / math.sqrt(x)) + (-1.0 - (x * -0.5)) else: tmp = (0.5 * math.pow(x, -0.5)) / x return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 - Float64(x * -0.5))); else tmp = Float64(Float64(0.5 * (x ^ -0.5)) / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = (1.0 / sqrt(x)) + (-1.0 - (x * -0.5)); else tmp = (0.5 * (x ^ -0.5)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 - x \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot {x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
Taylor expanded in x around 0 98.2%
if 1 < x Initial program 29.6%
frac-sub29.6%
div-inv29.6%
*-un-lft-identity29.6%
+-commutative29.6%
*-rgt-identity29.6%
metadata-eval29.6%
frac-times29.7%
un-div-inv29.7%
pow1/229.7%
pow-flip29.7%
metadata-eval29.7%
+-commutative29.7%
Applied egg-rr29.7%
associate-*r/29.7%
*-rgt-identity29.7%
times-frac29.7%
div-sub29.6%
*-inverses29.6%
unpow129.6%
sqr-pow29.6%
metadata-eval29.6%
exp-to-pow7.9%
metadata-eval7.9%
exp-to-pow7.7%
hypot-1-def7.7%
exp-to-pow29.6%
unpow1/229.6%
/-rgt-identity29.6%
Simplified29.6%
*-un-lft-identity29.6%
hypot-1-def29.6%
add-sqr-sqrt29.6%
sqrt-undiv29.6%
Applied egg-rr29.6%
*-lft-identity29.6%
Simplified29.6%
Taylor expanded in x around inf 97.1%
associate-*l/97.1%
Applied egg-rr97.1%
Final simplification97.7%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (* (/ 0.5 x) (pow x -0.5))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 / x) * pow(x, -0.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) * (x ** (-0.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 / x) * Math.pow(x, -0.5);
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = (0.5 / x) * math.pow(x, -0.5) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 / x) * (x ^ -0.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) * (x ^ -0.5); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 / x), $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} \cdot {x}^{-0.5}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
Taylor expanded in x around 0 97.5%
add-log-exp5.4%
*-un-lft-identity5.4%
log-prod5.4%
metadata-eval5.4%
add-log-exp97.5%
pow1/297.5%
pow-flip97.9%
metadata-eval97.9%
Applied egg-rr97.9%
+-lft-identity97.9%
Simplified97.9%
if 0.680000000000000049 < x Initial program 29.6%
frac-sub29.6%
div-inv29.6%
*-un-lft-identity29.6%
+-commutative29.6%
*-rgt-identity29.6%
metadata-eval29.6%
frac-times29.7%
un-div-inv29.7%
pow1/229.7%
pow-flip29.7%
metadata-eval29.7%
+-commutative29.7%
Applied egg-rr29.7%
associate-*r/29.7%
*-rgt-identity29.7%
times-frac29.7%
div-sub29.6%
*-inverses29.6%
unpow129.6%
sqr-pow29.6%
metadata-eval29.6%
exp-to-pow7.9%
metadata-eval7.9%
exp-to-pow7.7%
hypot-1-def7.7%
exp-to-pow29.6%
unpow1/229.6%
/-rgt-identity29.6%
Simplified29.6%
*-un-lft-identity29.6%
hypot-1-def29.6%
add-sqr-sqrt29.6%
sqrt-undiv29.6%
Applied egg-rr29.6%
*-lft-identity29.6%
Simplified29.6%
Taylor expanded in x around inf 97.1%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (/ (* 0.5 (pow x -0.5)) x)))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = (0.5 * pow(x, -0.5)) / x;
}
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 ** (-0.5d0))) / x
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, -0.5)) / x;
}
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, -0.5)) / x return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(Float64(0.5 * (x ^ -0.5)) / x); 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 ^ -0.5)) / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 \cdot {x}^{-0.5}}{x}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
Taylor expanded in x around 0 97.5%
add-log-exp5.4%
*-un-lft-identity5.4%
log-prod5.4%
metadata-eval5.4%
add-log-exp97.5%
pow1/297.5%
pow-flip97.9%
metadata-eval97.9%
Applied egg-rr97.9%
+-lft-identity97.9%
Simplified97.9%
if 0.680000000000000049 < x Initial program 29.6%
frac-sub29.6%
div-inv29.6%
*-un-lft-identity29.6%
+-commutative29.6%
*-rgt-identity29.6%
metadata-eval29.6%
frac-times29.7%
un-div-inv29.7%
pow1/229.7%
pow-flip29.7%
metadata-eval29.7%
+-commutative29.7%
Applied egg-rr29.7%
associate-*r/29.7%
*-rgt-identity29.7%
times-frac29.7%
div-sub29.6%
*-inverses29.6%
unpow129.6%
sqr-pow29.6%
metadata-eval29.6%
exp-to-pow7.9%
metadata-eval7.9%
exp-to-pow7.7%
hypot-1-def7.7%
exp-to-pow29.6%
unpow1/229.6%
/-rgt-identity29.6%
Simplified29.6%
*-un-lft-identity29.6%
hypot-1-def29.6%
add-sqr-sqrt29.6%
sqrt-undiv29.6%
Applied egg-rr29.6%
*-lft-identity29.6%
Simplified29.6%
Taylor expanded in x around inf 97.1%
associate-*l/97.1%
Applied egg-rr97.1%
Final simplification97.5%
(FPCore (x) :precision binary64 (if (<= x 4.0) (+ (pow x -0.5) -1.0) (- (pow (* x x) -0.25))))
double code(double x) {
double tmp;
if (x <= 4.0) {
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 <= 4.0d0) 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 <= 4.0) {
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 <= 4.0: 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 <= 4.0) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(-(Float64(x * x) ^ -0.25)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 4.0) tmp = (x ^ -0.5) + -1.0; else tmp = -((x * x) ^ -0.25); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 4.0], 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 4:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;-{\left(x \cdot x\right)}^{-0.25}\\
\end{array}
\end{array}
if x < 4Initial program 99.6%
Taylor expanded in x around 0 96.7%
add-log-exp5.4%
*-un-lft-identity5.4%
log-prod5.4%
metadata-eval5.4%
add-log-exp96.7%
pow1/296.7%
pow-flip97.1%
metadata-eval97.1%
Applied egg-rr97.1%
+-lft-identity97.1%
Simplified97.1%
if 4 < x Initial program 29.0%
pow1/229.0%
pow-to-exp6.9%
+-commutative6.9%
log1p-udef6.9%
Applied egg-rr6.9%
Taylor expanded in x around inf 3.1%
mul-1-neg3.1%
Simplified3.1%
inv-pow3.1%
sqrt-pow13.1%
metadata-eval3.1%
sqr-pow3.1%
pow-prod-down25.2%
metadata-eval25.2%
Applied egg-rr25.2%
Final simplification61.7%
(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 64.9%
Taylor expanded in x around 0 50.4%
add-log-exp4.0%
*-un-lft-identity4.0%
log-prod4.0%
metadata-eval4.0%
add-log-exp50.4%
pow1/250.4%
pow-flip50.6%
metadata-eval50.6%
Applied egg-rr50.6%
+-lft-identity50.6%
Simplified50.6%
Final simplification50.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 Float64(-(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 64.9%
inv-pow64.9%
pow1/264.9%
pow-pow62.1%
add-exp-log53.9%
+-commutative53.9%
log1p-udef53.9%
pow-exp53.9%
metadata-eval53.9%
Applied egg-rr53.9%
Taylor expanded in x around inf 2.1%
mul-1-neg2.1%
unpow1/22.1%
exp-to-pow2.1%
log-rec2.1%
distribute-lft-neg-out2.1%
distribute-rgt-neg-in2.1%
metadata-eval2.1%
exp-to-pow2.1%
Simplified2.1%
Final simplification2.1%
(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 64.9%
frac-sub64.9%
div-inv64.9%
*-un-lft-identity64.9%
+-commutative64.9%
*-rgt-identity64.9%
metadata-eval64.9%
frac-times64.9%
un-div-inv64.9%
pow1/264.9%
pow-flip65.1%
metadata-eval65.1%
+-commutative65.1%
Applied egg-rr65.1%
associate-*r/65.1%
*-rgt-identity65.1%
times-frac65.1%
div-sub65.1%
*-inverses65.1%
unpow165.1%
sqr-pow65.1%
metadata-eval65.1%
exp-to-pow54.3%
metadata-eval54.3%
exp-to-pow54.2%
hypot-1-def54.2%
exp-to-pow65.1%
unpow1/265.1%
/-rgt-identity65.1%
Simplified65.1%
Taylor expanded in x around 0 50.2%
Final simplification50.2%
(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 64.9%
add-cube-cbrt55.2%
associate-*l*55.2%
fma-neg53.1%
pow1/253.1%
pow-flip53.1%
metadata-eval53.1%
cbrt-unprod53.5%
frac-times53.5%
metadata-eval53.5%
add-sqr-sqrt53.5%
distribute-neg-frac53.5%
metadata-eval53.5%
+-commutative53.5%
Applied egg-rr53.5%
Taylor expanded in x around 0 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 2023285
(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)))))