
(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 (* (/ (pow x -0.5) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))) (/ (pow x -0.5) (+ x 1.0))))
double code(double x) {
return (pow(x, -0.5) / (pow(x, -0.5) + pow((x + 1.0), -0.5))) * (pow(x, -0.5) / (x + 1.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x ** (-0.5d0)) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))) * ((x ** (-0.5d0)) / (x + 1.0d0))
end function
public static double code(double x) {
return (Math.pow(x, -0.5) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))) * (Math.pow(x, -0.5) / (x + 1.0));
}
def code(x): return (math.pow(x, -0.5) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))) * (math.pow(x, -0.5) / (x + 1.0))
function code(x) return Float64(Float64((x ^ -0.5) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))) * Float64((x ^ -0.5) / Float64(x + 1.0))) end
function tmp = code(x) tmp = ((x ^ -0.5) / ((x ^ -0.5) + ((x + 1.0) ^ -0.5))) * ((x ^ -0.5) / (x + 1.0)); end
code[x_] := N[(N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{{x}^{-0.5}}{x + 1}
\end{array}
Initial program 71.5%
flip--71.4%
frac-times62.4%
metadata-eval62.4%
add-sqr-sqrt61.4%
frac-times66.4%
metadata-eval66.4%
add-sqr-sqrt71.3%
+-commutative71.3%
pow1/271.3%
pow-flip71.2%
metadata-eval71.2%
inv-pow71.2%
sqrt-pow271.2%
+-commutative71.2%
metadata-eval71.2%
Applied egg-rr71.2%
frac-sub71.8%
associate-/r*71.8%
*-un-lft-identity71.8%
*-rgt-identity71.8%
associate--l+93.2%
Applied egg-rr93.2%
associate-/l/99.3%
+-inverses99.3%
metadata-eval99.3%
add-sqr-sqrt99.5%
times-frac99.7%
inv-pow99.7%
sqrt-pow199.8%
metadata-eval99.8%
+-commutative99.8%
inv-pow99.8%
sqrt-pow199.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ -1.0 (sqrt (+ x 1.0)))))
(if (<= (+ (/ 1.0 (sqrt x)) t_0) 2e-23)
(* 0.5 (/ (/ 1.0 x) (* (pow x -0.5) (+ x 1.0))))
(+ (pow x -0.5) t_0))))
double code(double x) {
double t_0 = -1.0 / sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + t_0) <= 2e-23) {
tmp = 0.5 * ((1.0 / x) / (pow(x, -0.5) * (x + 1.0)));
} else {
tmp = pow(x, -0.5) + t_0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = (-1.0d0) / sqrt((x + 1.0d0))
if (((1.0d0 / sqrt(x)) + t_0) <= 2d-23) then
tmp = 0.5d0 * ((1.0d0 / x) / ((x ** (-0.5d0)) * (x + 1.0d0)))
else
tmp = (x ** (-0.5d0)) + t_0
end if
code = tmp
end function
public static double code(double x) {
double t_0 = -1.0 / Math.sqrt((x + 1.0));
double tmp;
if (((1.0 / Math.sqrt(x)) + t_0) <= 2e-23) {
tmp = 0.5 * ((1.0 / x) / (Math.pow(x, -0.5) * (x + 1.0)));
} else {
tmp = Math.pow(x, -0.5) + t_0;
}
return tmp;
}
def code(x): t_0 = -1.0 / math.sqrt((x + 1.0)) tmp = 0 if ((1.0 / math.sqrt(x)) + t_0) <= 2e-23: tmp = 0.5 * ((1.0 / x) / (math.pow(x, -0.5) * (x + 1.0))) else: tmp = math.pow(x, -0.5) + t_0 return tmp
function code(x) t_0 = Float64(-1.0 / sqrt(Float64(x + 1.0))) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + t_0) <= 2e-23) tmp = Float64(0.5 * Float64(Float64(1.0 / x) / Float64((x ^ -0.5) * Float64(x + 1.0)))); else tmp = Float64((x ^ -0.5) + t_0); end return tmp end
function tmp_2 = code(x) t_0 = -1.0 / sqrt((x + 1.0)); tmp = 0.0; if (((1.0 / sqrt(x)) + t_0) <= 2e-23) tmp = 0.5 * ((1.0 / x) / ((x ^ -0.5) * (x + 1.0))); else tmp = (x ^ -0.5) + t_0; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(-1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], 2e-23], N[(0.5 * N[(N[(1.0 / x), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-1}{\sqrt{x + 1}}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + t_0 \leq 2 \cdot 10^{-23}:\\
\;\;\;\;0.5 \cdot \frac{\frac{1}{x}}{{x}^{-0.5} \cdot \left(x + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} + t_0\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 1.99999999999999992e-23Initial program 40.7%
flip--40.7%
frac-times22.3%
metadata-eval22.3%
add-sqr-sqrt19.9%
frac-times30.5%
metadata-eval30.5%
add-sqr-sqrt40.7%
+-commutative40.7%
pow1/240.7%
pow-flip40.7%
metadata-eval40.7%
inv-pow40.7%
sqrt-pow240.7%
+-commutative40.7%
metadata-eval40.7%
Applied egg-rr40.7%
Taylor expanded in x around inf 40.7%
*-un-lft-identity40.7%
times-frac40.7%
metadata-eval40.7%
clear-num40.7%
frac-sub41.9%
*-un-lft-identity41.9%
/-rgt-identity41.9%
*-rgt-identity41.9%
associate-+r-86.2%
+-inverses86.2%
metadata-eval86.2%
metadata-eval86.2%
frac-times86.6%
un-div-inv86.8%
/-rgt-identity86.8%
inv-pow86.8%
sqrt-pow186.7%
metadata-eval86.7%
Applied egg-rr86.7%
associate-/l/99.5%
Simplified99.5%
if 1.99999999999999992e-23 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.5%
expm1-log1p-u92.4%
expm1-udef92.4%
pow1/292.4%
pow-flip92.4%
metadata-eval92.4%
Applied egg-rr92.4%
expm1-def92.5%
expm1-log1p99.9%
Simplified99.9%
Final simplification99.7%
(FPCore (x) :precision binary64 (* (/ 1.0 x) (/ 1.0 (* (+ x 1.0) (+ (pow x -0.5) (pow (+ x 1.0) -0.5))))))
double code(double x) {
return (1.0 / x) * (1.0 / ((x + 1.0) * (pow(x, -0.5) + pow((x + 1.0), -0.5))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) * (1.0d0 / ((x + 1.0d0) * ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))))
end function
public static double code(double x) {
return (1.0 / x) * (1.0 / ((x + 1.0) * (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))));
}
def code(x): return (1.0 / x) * (1.0 / ((x + 1.0) * (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))))
function code(x) return Float64(Float64(1.0 / x) * Float64(1.0 / Float64(Float64(x + 1.0) * Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))))) end
function tmp = code(x) tmp = (1.0 / x) * (1.0 / ((x + 1.0) * ((x ^ -0.5) + ((x + 1.0) ^ -0.5)))); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / N[(N[(x + 1.0), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} \cdot \frac{1}{\left(x + 1\right) \cdot \left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right)}
\end{array}
Initial program 71.5%
flip--71.4%
frac-times62.4%
metadata-eval62.4%
add-sqr-sqrt61.4%
frac-times66.4%
metadata-eval66.4%
add-sqr-sqrt71.3%
+-commutative71.3%
pow1/271.3%
pow-flip71.2%
metadata-eval71.2%
inv-pow71.2%
sqrt-pow271.2%
+-commutative71.2%
metadata-eval71.2%
Applied egg-rr71.2%
frac-sub71.8%
associate-/r*71.8%
*-un-lft-identity71.8%
*-rgt-identity71.8%
associate--l+93.2%
Applied egg-rr93.2%
associate-/l/99.3%
+-inverses99.3%
metadata-eval99.3%
div-inv99.3%
+-commutative99.3%
Applied egg-rr99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (if (<= x 75000000.0) (- (pow x -0.5) (pow (+ x 1.0) -0.5)) (* 0.5 (/ (/ 1.0 x) (* (pow x -0.5) (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 75000000.0) {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
} else {
tmp = 0.5 * ((1.0 / x) / (pow(x, -0.5) * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 75000000.0d0) then
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = 0.5d0 * ((1.0d0 / x) / ((x ** (-0.5d0)) * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 75000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
} else {
tmp = 0.5 * ((1.0 / x) / (Math.pow(x, -0.5) * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 75000000.0: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) else: tmp = 0.5 * ((1.0 / x) / (math.pow(x, -0.5) * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 75000000.0) tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64(0.5 * Float64(Float64(1.0 / x) / Float64((x ^ -0.5) * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 75000000.0) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); else tmp = 0.5 * ((1.0 / x) / ((x ^ -0.5) * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 75000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(1.0 / x), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 75000000:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\frac{1}{x}}{{x}^{-0.5} \cdot \left(x + 1\right)}\\
\end{array}
\end{array}
if x < 7.5e7Initial program 99.5%
*-un-lft-identity99.5%
clear-num99.5%
associate-/r/99.5%
prod-diff99.5%
*-un-lft-identity99.5%
fma-neg99.5%
*-un-lft-identity99.5%
pow1/299.5%
pow-flip99.9%
metadata-eval99.9%
pow1/299.9%
pow-flip99.9%
+-commutative99.9%
metadata-eval99.9%
Applied egg-rr99.9%
+-commutative99.9%
sub-neg99.9%
fma-udef99.9%
distribute-lft1-in99.9%
metadata-eval99.9%
mul0-lft99.9%
+-commutative99.9%
associate-+r+99.9%
sub-neg99.9%
neg-sub099.9%
+-commutative99.9%
sub-neg99.9%
Simplified99.9%
if 7.5e7 < x Initial program 40.7%
flip--40.7%
frac-times22.3%
metadata-eval22.3%
add-sqr-sqrt19.9%
frac-times30.5%
metadata-eval30.5%
add-sqr-sqrt40.7%
+-commutative40.7%
pow1/240.7%
pow-flip40.7%
metadata-eval40.7%
inv-pow40.7%
sqrt-pow240.7%
+-commutative40.7%
metadata-eval40.7%
Applied egg-rr40.7%
Taylor expanded in x around inf 40.7%
*-un-lft-identity40.7%
times-frac40.7%
metadata-eval40.7%
clear-num40.7%
frac-sub41.9%
*-un-lft-identity41.9%
/-rgt-identity41.9%
*-rgt-identity41.9%
associate-+r-86.2%
+-inverses86.2%
metadata-eval86.2%
metadata-eval86.2%
frac-times86.6%
un-div-inv86.8%
/-rgt-identity86.8%
inv-pow86.8%
sqrt-pow186.7%
metadata-eval86.7%
Applied egg-rr86.7%
associate-/l/99.5%
Simplified99.5%
Final simplification99.7%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* 0.5 (/ (/ 1.0 x) (* (pow x -0.5) (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * ((1.0 / x) / (pow(x, -0.5) * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = 0.5d0 * ((1.0d0 / x) / ((x ** (-0.5d0)) * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = 0.5 * ((1.0 / x) / (Math.pow(x, -0.5) * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = 0.5 * ((1.0 / x) / (math.pow(x, -0.5) * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(0.5 * Float64(Float64(1.0 / x) / Float64((x ^ -0.5) * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = 0.5 * ((1.0 / x) / ((x ^ -0.5) * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(0.5 * N[(N[(1.0 / x), $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{\frac{1}{x}}{{x}^{-0.5} \cdot \left(x + 1\right)}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial 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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 0.680000000000000049 < x Initial program 41.1%
flip--41.0%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt20.5%
frac-times31.0%
metadata-eval31.0%
add-sqr-sqrt41.1%
+-commutative41.1%
pow1/241.1%
pow-flip41.1%
metadata-eval41.1%
inv-pow41.1%
sqrt-pow241.1%
+-commutative41.1%
metadata-eval41.1%
Applied egg-rr41.1%
Taylor expanded in x around inf 40.6%
*-un-lft-identity40.6%
times-frac40.6%
metadata-eval40.6%
clear-num40.6%
frac-sub41.8%
*-un-lft-identity41.8%
/-rgt-identity41.8%
*-rgt-identity41.8%
associate-+r-85.8%
+-inverses85.8%
metadata-eval85.8%
metadata-eval85.8%
frac-times86.2%
un-div-inv86.3%
/-rgt-identity86.3%
inv-pow86.3%
sqrt-pow186.3%
metadata-eval86.3%
Applied egg-rr86.3%
associate-/l/98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (+ (pow x -0.5) (* x 0.5)) -1.0) (* (sqrt x) (/ (/ -1.0 x) (* (+ x 1.0) -2.0)))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = (pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = sqrt(x) * ((-1.0 / x) / ((x + 1.0) * -2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = ((x ** (-0.5d0)) + (x * 0.5d0)) + (-1.0d0)
else
tmp = sqrt(x) * (((-1.0d0) / x) / ((x + 1.0d0) * (-2.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = (Math.pow(x, -0.5) + (x * 0.5)) + -1.0;
} else {
tmp = Math.sqrt(x) * ((-1.0 / x) / ((x + 1.0) * -2.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = (math.pow(x, -0.5) + (x * 0.5)) + -1.0 else: tmp = math.sqrt(x) * ((-1.0 / x) / ((x + 1.0) * -2.0)) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64(Float64((x ^ -0.5) + Float64(x * 0.5)) + -1.0); else tmp = Float64(sqrt(x) * Float64(Float64(-1.0 / x) / Float64(Float64(x + 1.0) * -2.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = ((x ^ -0.5) + (x * 0.5)) + -1.0; else tmp = sqrt(x) * ((-1.0 / x) / ((x + 1.0) * -2.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * N[(N[(-1.0 / x), $MachinePrecision] / N[(N[(x + 1.0), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot \frac{\frac{-1}{x}}{\left(x + 1\right) \cdot -2}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial 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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 0.680000000000000049 < x Initial program 41.1%
flip--41.0%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt20.5%
frac-times31.0%
metadata-eval31.0%
add-sqr-sqrt41.1%
+-commutative41.1%
pow1/241.1%
pow-flip41.1%
metadata-eval41.1%
inv-pow41.1%
sqrt-pow241.1%
+-commutative41.1%
metadata-eval41.1%
Applied egg-rr41.1%
Taylor expanded in x around inf 40.6%
expm1-log1p-u40.6%
expm1-udef40.3%
Applied egg-rr40.3%
expm1-def86.3%
expm1-log1p86.3%
associate-/l/86.3%
Simplified86.3%
Final simplification92.8%
(FPCore (x) :precision binary64 (if (<= x 0.82) (+ (pow x -0.5) -1.0) (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.82d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.82: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 0.82) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.82) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.82], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.82:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < 0.819999999999999951Initial 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%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
if 0.819999999999999951 < x Initial program 41.1%
flip--41.0%
frac-times22.8%
metadata-eval22.8%
add-sqr-sqrt20.5%
frac-times31.0%
metadata-eval31.0%
add-sqr-sqrt41.1%
+-commutative41.1%
pow1/241.1%
pow-flip41.1%
metadata-eval41.1%
inv-pow41.1%
sqrt-pow241.1%
+-commutative41.1%
metadata-eval41.1%
Applied egg-rr41.1%
Taylor expanded in x around 0 8.0%
distribute-rgt-in8.0%
*-lft-identity8.0%
pow-plus8.0%
metadata-eval8.0%
Simplified8.0%
Taylor expanded in x around inf 8.0%
Final simplification54.9%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (sqrt x))))
double code(double x) {
return 1.0 / (x + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (x + Math.sqrt(x));
}
def code(x): return 1.0 / (x + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(x + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (x + sqrt(x)); end
code[x_] := N[(1.0 / N[(x + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + \sqrt{x}}
\end{array}
Initial program 71.5%
flip--71.4%
frac-times62.4%
metadata-eval62.4%
add-sqr-sqrt61.4%
frac-times66.4%
metadata-eval66.4%
add-sqr-sqrt71.3%
+-commutative71.3%
pow1/271.3%
pow-flip71.2%
metadata-eval71.2%
inv-pow71.2%
sqrt-pow271.2%
+-commutative71.2%
metadata-eval71.2%
Applied egg-rr71.2%
Taylor expanded in x around 0 54.0%
distribute-rgt-in54.0%
*-lft-identity54.0%
pow-plus54.2%
metadata-eval54.2%
Simplified54.2%
expm1-log1p-u50.6%
expm1-udef66.1%
pow1/266.1%
Applied egg-rr66.1%
expm1-def50.6%
expm1-log1p54.2%
Simplified54.2%
Final simplification54.2%
(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 71.5%
inv-pow71.5%
add-sqr-sqrt63.7%
unpow-prod-down61.6%
pow1/261.6%
sqrt-pow161.7%
metadata-eval61.7%
pow1/261.7%
sqrt-pow160.9%
metadata-eval60.9%
Applied egg-rr60.9%
pow-sqr62.2%
metadata-eval62.2%
Simplified62.2%
Taylor expanded in x around inf 51.9%
inv-pow51.9%
sqrt-pow152.0%
metadata-eval52.0%
expm1-log1p-u48.3%
expm1-udef65.1%
Applied egg-rr65.1%
expm1-def48.3%
expm1-log1p52.0%
Simplified52.0%
Final simplification52.0%
(FPCore (x) :precision binary64 (* x 0.5))
double code(double x) {
return 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 x * 0.5;
}
def code(x): return x * 0.5
function code(x) return Float64(x * 0.5) end
function tmp = code(x) tmp = x * 0.5; end
code[x_] := N[(x * 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 0.5
\end{array}
Initial program 71.5%
Taylor expanded in x around 0 52.7%
Taylor expanded in x around inf 4.0%
*-commutative4.0%
Simplified4.0%
Final simplification4.0%
(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 71.5%
flip--71.4%
frac-times62.4%
metadata-eval62.4%
add-sqr-sqrt61.4%
frac-times66.4%
metadata-eval66.4%
add-sqr-sqrt71.3%
+-commutative71.3%
pow1/271.3%
pow-flip71.2%
metadata-eval71.2%
inv-pow71.2%
sqrt-pow271.2%
+-commutative71.2%
metadata-eval71.2%
Applied egg-rr71.2%
Taylor expanded in x around 0 54.0%
distribute-rgt-in54.0%
*-lft-identity54.0%
pow-plus54.2%
metadata-eval54.2%
Simplified54.2%
Taylor expanded in x around inf 7.5%
Final simplification7.5%
(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 71.5%
Taylor expanded in x around 0 52.0%
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 2023322
(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)))))