
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - \cos x}{x \cdot x}
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0001) (+ 0.5 (* (pow x_m 2.0) -0.041666666666666664)) (/ (/ 1.0 x_m) (/ x_m (* (sin x_m) (tan (/ x_m 2.0)))))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.0001) {
tmp = 0.5 + (pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = (1.0 / x_m) / (x_m / (sin(x_m) * tan((x_m / 2.0))));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.0001d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (-0.041666666666666664d0))
else
tmp = (1.0d0 / x_m) / (x_m / (sin(x_m) * tan((x_m / 2.0d0))))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.0001) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = (1.0 / x_m) / (x_m / (Math.sin(x_m) * Math.tan((x_m / 2.0))));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.0001: tmp = 0.5 + (math.pow(x_m, 2.0) * -0.041666666666666664) else: tmp = (1.0 / x_m) / (x_m / (math.sin(x_m) * math.tan((x_m / 2.0)))) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.0001) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * -0.041666666666666664)); else tmp = Float64(Float64(1.0 / x_m) / Float64(x_m / Float64(sin(x_m) * tan(Float64(x_m / 2.0))))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.0001) tmp = 0.5 + ((x_m ^ 2.0) * -0.041666666666666664); else tmp = (1.0 / x_m) / (x_m / (sin(x_m) * tan((x_m / 2.0)))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.0001], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(x$95$m / N[(N[Sin[x$95$m], $MachinePrecision] * N[Tan[N[(x$95$m / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0001:\\
\;\;\;\;0.5 + {x_m}^{2} \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x_m}}{\frac{x_m}{\sin x_m \cdot \tan \left(\frac{x_m}{2}\right)}}\\
\end{array}
\end{array}
if x < 1.00000000000000005e-4Initial program 34.6%
Taylor expanded in x around 0 67.4%
*-commutative67.4%
Simplified67.4%
if 1.00000000000000005e-4 < x Initial program 98.9%
associate-/r*99.5%
div-inv99.3%
Applied egg-rr99.3%
*-commutative99.3%
clear-num99.3%
un-div-inv99.4%
Applied egg-rr99.4%
flip--99.0%
metadata-eval99.0%
1-sub-cos98.9%
associate-/r/98.9%
pow298.9%
Applied egg-rr98.9%
associate-*l/98.7%
associate-/l*98.9%
unpow298.9%
associate-*r/98.7%
hang-0p-tan99.5%
Simplified99.5%
Final simplification77.1%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.03)
(+
0.5
(+
(* (pow x_m 2.0) -0.041666666666666664)
(* 0.001388888888888889 (pow x_m 4.0))))
(/ (/ (- 1.0 (cos x_m)) x_m) x_m)))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = 0.5 + ((pow(x_m, 2.0) * -0.041666666666666664) + (0.001388888888888889 * pow(x_m, 4.0)));
} else {
tmp = ((1.0 - cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.03d0) then
tmp = 0.5d0 + (((x_m ** 2.0d0) * (-0.041666666666666664d0)) + (0.001388888888888889d0 * (x_m ** 4.0d0)))
else
tmp = ((1.0d0 - cos(x_m)) / x_m) / x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = 0.5 + ((Math.pow(x_m, 2.0) * -0.041666666666666664) + (0.001388888888888889 * Math.pow(x_m, 4.0)));
} else {
tmp = ((1.0 - Math.cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.03: tmp = 0.5 + ((math.pow(x_m, 2.0) * -0.041666666666666664) + (0.001388888888888889 * math.pow(x_m, 4.0))) else: tmp = ((1.0 - math.cos(x_m)) / x_m) / x_m return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.03) tmp = Float64(0.5 + Float64(Float64((x_m ^ 2.0) * -0.041666666666666664) + Float64(0.001388888888888889 * (x_m ^ 4.0)))); else tmp = Float64(Float64(Float64(1.0 - cos(x_m)) / x_m) / x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.03) tmp = 0.5 + (((x_m ^ 2.0) * -0.041666666666666664) + (0.001388888888888889 * (x_m ^ 4.0))); else tmp = ((1.0 - cos(x_m)) / x_m) / x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.03], N[(0.5 + N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x$95$m, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision] / x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.03:\\
\;\;\;\;0.5 + \left({x_m}^{2} \cdot -0.041666666666666664 + 0.001388888888888889 \cdot {x_m}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x_m}{x_m}}{x_m}\\
\end{array}
\end{array}
if x < 0.029999999999999999Initial program 34.6%
Taylor expanded in x around 0 67.5%
if 0.029999999999999999 < x Initial program 98.9%
associate-/r*99.5%
div-inv99.3%
Applied egg-rr99.3%
un-div-inv99.5%
Applied egg-rr99.5%
Final simplification77.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ 1.0 x_m) (* (/ 1.0 (sin x_m)) (/ x_m (tan (* x_m 0.5))))))
x_m = fabs(x);
double code(double x_m) {
return (1.0 / x_m) / ((1.0 / sin(x_m)) * (x_m / tan((x_m * 0.5))));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (1.0d0 / x_m) / ((1.0d0 / sin(x_m)) * (x_m / tan((x_m * 0.5d0))))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (1.0 / x_m) / ((1.0 / Math.sin(x_m)) * (x_m / Math.tan((x_m * 0.5))));
}
x_m = math.fabs(x) def code(x_m): return (1.0 / x_m) / ((1.0 / math.sin(x_m)) * (x_m / math.tan((x_m * 0.5))))
x_m = abs(x) function code(x_m) return Float64(Float64(1.0 / x_m) / Float64(Float64(1.0 / sin(x_m)) * Float64(x_m / tan(Float64(x_m * 0.5))))) end
x_m = abs(x); function tmp = code(x_m) tmp = (1.0 / x_m) / ((1.0 / sin(x_m)) * (x_m / tan((x_m * 0.5)))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(1.0 / N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] * N[(x$95$m / N[Tan[N[(x$95$m * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{1}{x_m}}{\frac{1}{\sin x_m} \cdot \frac{x_m}{\tan \left(x_m \cdot 0.5\right)}}
\end{array}
Initial program 54.2%
associate-/r*55.6%
div-inv55.5%
Applied egg-rr55.5%
*-commutative55.5%
clear-num55.5%
un-div-inv55.5%
Applied egg-rr55.5%
flip--55.3%
metadata-eval55.3%
1-sub-cos77.5%
associate-/r/77.5%
pow277.5%
Applied egg-rr77.5%
associate-*l/77.5%
associate-/l*77.5%
unpow277.5%
associate-*r/77.5%
hang-0p-tan77.8%
Simplified77.8%
*-un-lft-identity77.8%
times-frac99.7%
div-inv99.7%
metadata-eval99.7%
Applied egg-rr99.7%
Final simplification99.7%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* (/ (sin x_m) x_m) (/ (/ 1.0 (/ 1.0 (tan (* x_m 0.5)))) x_m)))
x_m = fabs(x);
double code(double x_m) {
return (sin(x_m) / x_m) * ((1.0 / (1.0 / tan((x_m * 0.5)))) / x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (sin(x_m) / x_m) * ((1.0d0 / (1.0d0 / tan((x_m * 0.5d0)))) / x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (Math.sin(x_m) / x_m) * ((1.0 / (1.0 / Math.tan((x_m * 0.5)))) / x_m);
}
x_m = math.fabs(x) def code(x_m): return (math.sin(x_m) / x_m) * ((1.0 / (1.0 / math.tan((x_m * 0.5)))) / x_m)
x_m = abs(x) function code(x_m) return Float64(Float64(sin(x_m) / x_m) * Float64(Float64(1.0 / Float64(1.0 / tan(Float64(x_m * 0.5)))) / x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = (sin(x_m) / x_m) * ((1.0 / (1.0 / tan((x_m * 0.5)))) / x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(N[Sin[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision] * N[(N[(1.0 / N[(1.0 / N[Tan[N[(x$95$m * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\sin x_m}{x_m} \cdot \frac{\frac{1}{\frac{1}{\tan \left(x_m \cdot 0.5\right)}}}{x_m}
\end{array}
Initial program 54.2%
add-exp-log54.2%
sub-neg54.2%
log1p-def54.2%
Applied egg-rr54.2%
log1p-udef54.2%
add-exp-log54.2%
sub-neg54.2%
flip--53.9%
metadata-eval53.9%
1-sub-cos76.8%
associate-/l*76.7%
frac-2neg76.7%
Applied egg-rr76.7%
*-lft-identity76.7%
associate-/l*76.7%
hang-0p-tan77.0%
Simplified77.0%
div-inv77.0%
times-frac99.7%
add-sqr-sqrt52.4%
sqrt-unprod53.1%
sqr-neg53.1%
sqrt-unprod10.7%
add-sqr-sqrt24.9%
Applied egg-rr99.7%
Final simplification99.7%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ 1.0 x_m) (/ (/ x_m (sin x_m)) (tan (* x_m 0.5)))))
x_m = fabs(x);
double code(double x_m) {
return (1.0 / x_m) / ((x_m / sin(x_m)) / tan((x_m * 0.5)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (1.0d0 / x_m) / ((x_m / sin(x_m)) / tan((x_m * 0.5d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (1.0 / x_m) / ((x_m / Math.sin(x_m)) / Math.tan((x_m * 0.5)));
}
x_m = math.fabs(x) def code(x_m): return (1.0 / x_m) / ((x_m / math.sin(x_m)) / math.tan((x_m * 0.5)))
x_m = abs(x) function code(x_m) return Float64(Float64(1.0 / x_m) / Float64(Float64(x_m / sin(x_m)) / tan(Float64(x_m * 0.5)))) end
x_m = abs(x); function tmp = code(x_m) tmp = (1.0 / x_m) / ((x_m / sin(x_m)) / tan((x_m * 0.5))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(x$95$m / N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision] / N[Tan[N[(x$95$m * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{1}{x_m}}{\frac{\frac{x_m}{\sin x_m}}{\tan \left(x_m \cdot 0.5\right)}}
\end{array}
Initial program 54.2%
associate-/r*55.6%
div-inv55.5%
Applied egg-rr55.5%
*-commutative55.5%
clear-num55.5%
un-div-inv55.5%
Applied egg-rr55.5%
flip--55.3%
metadata-eval55.3%
1-sub-cos77.5%
associate-/r/77.5%
pow277.5%
Applied egg-rr77.5%
associate-*l/77.5%
associate-/l*77.5%
unpow277.5%
associate-*r/77.5%
hang-0p-tan77.8%
Simplified77.8%
expm1-log1p-u40.8%
expm1-udef40.8%
*-commutative40.8%
div-inv40.8%
metadata-eval40.8%
Applied egg-rr40.8%
expm1-def40.8%
expm1-log1p77.8%
*-lft-identity77.8%
times-frac99.7%
associate-*l/99.7%
*-lft-identity99.7%
Simplified99.7%
Final simplification99.7%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.03)
(/
(/ 1.0 x_m)
(+
(* 0.008333333333333333 (pow x_m 3.0))
(+ (* x_m 0.16666666666666666) (* (/ 1.0 x_m) 2.0))))
(/ (/ (- 1.0 (cos x_m)) x_m) x_m)))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = (1.0 / x_m) / ((0.008333333333333333 * pow(x_m, 3.0)) + ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0)));
} else {
tmp = ((1.0 - cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.03d0) then
tmp = (1.0d0 / x_m) / ((0.008333333333333333d0 * (x_m ** 3.0d0)) + ((x_m * 0.16666666666666666d0) + ((1.0d0 / x_m) * 2.0d0)))
else
tmp = ((1.0d0 - cos(x_m)) / x_m) / x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.03) {
tmp = (1.0 / x_m) / ((0.008333333333333333 * Math.pow(x_m, 3.0)) + ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0)));
} else {
tmp = ((1.0 - Math.cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.03: tmp = (1.0 / x_m) / ((0.008333333333333333 * math.pow(x_m, 3.0)) + ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0))) else: tmp = ((1.0 - math.cos(x_m)) / x_m) / x_m return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.03) tmp = Float64(Float64(1.0 / x_m) / Float64(Float64(0.008333333333333333 * (x_m ^ 3.0)) + Float64(Float64(x_m * 0.16666666666666666) + Float64(Float64(1.0 / x_m) * 2.0)))); else tmp = Float64(Float64(Float64(1.0 - cos(x_m)) / x_m) / x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.03) tmp = (1.0 / x_m) / ((0.008333333333333333 * (x_m ^ 3.0)) + ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0))); else tmp = ((1.0 - cos(x_m)) / x_m) / x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.03], N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(0.008333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(x$95$m * 0.16666666666666666), $MachinePrecision] + N[(N[(1.0 / x$95$m), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision] / x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.03:\\
\;\;\;\;\frac{\frac{1}{x_m}}{0.008333333333333333 \cdot {x_m}^{3} + \left(x_m \cdot 0.16666666666666666 + \frac{1}{x_m} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x_m}{x_m}}{x_m}\\
\end{array}
\end{array}
if x < 0.029999999999999999Initial program 34.6%
associate-/r*36.3%
div-inv36.3%
Applied egg-rr36.3%
*-commutative36.3%
clear-num36.3%
un-div-inv36.3%
Applied egg-rr36.3%
Taylor expanded in x around 0 81.5%
if 0.029999999999999999 < x Initial program 98.9%
associate-/r*99.5%
div-inv99.3%
Applied egg-rr99.3%
un-div-inv99.5%
Applied egg-rr99.5%
Final simplification87.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0042) (+ 0.5 (* (pow x_m 2.0) -0.041666666666666664)) (/ (- 1.0 (cos x_m)) (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.0042) {
tmp = 0.5 + (pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = (1.0 - cos(x_m)) / (x_m * x_m);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.0042d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (-0.041666666666666664d0))
else
tmp = (1.0d0 - cos(x_m)) / (x_m * x_m)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.0042) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = (1.0 - Math.cos(x_m)) / (x_m * x_m);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.0042: tmp = 0.5 + (math.pow(x_m, 2.0) * -0.041666666666666664) else: tmp = (1.0 - math.cos(x_m)) / (x_m * x_m) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.0042) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * -0.041666666666666664)); else tmp = Float64(Float64(1.0 - cos(x_m)) / Float64(x_m * x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.0042) tmp = 0.5 + ((x_m ^ 2.0) * -0.041666666666666664); else tmp = (1.0 - cos(x_m)) / (x_m * x_m); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.0042], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0042:\\
\;\;\;\;0.5 + {x_m}^{2} \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x_m}{x_m \cdot x_m}\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 34.6%
Taylor expanded in x around 0 67.4%
*-commutative67.4%
Simplified67.4%
if 0.00419999999999999974 < x Initial program 98.9%
Final simplification77.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.0042) (+ 0.5 (* (pow x_m 2.0) -0.041666666666666664)) (/ (/ (- 1.0 (cos x_m)) x_m) x_m)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.0042) {
tmp = 0.5 + (pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = ((1.0 - cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.0042d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (-0.041666666666666664d0))
else
tmp = ((1.0d0 - cos(x_m)) / x_m) / x_m
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.0042) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = ((1.0 - Math.cos(x_m)) / x_m) / x_m;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.0042: tmp = 0.5 + (math.pow(x_m, 2.0) * -0.041666666666666664) else: tmp = ((1.0 - math.cos(x_m)) / x_m) / x_m return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.0042) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * -0.041666666666666664)); else tmp = Float64(Float64(Float64(1.0 - cos(x_m)) / x_m) / x_m); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.0042) tmp = 0.5 + ((x_m ^ 2.0) * -0.041666666666666664); else tmp = ((1.0 - cos(x_m)) / x_m) / x_m; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.0042], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision] / x$95$m), $MachinePrecision] / x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 0.0042:\\
\;\;\;\;0.5 + {x_m}^{2} \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x_m}{x_m}}{x_m}\\
\end{array}
\end{array}
if x < 0.00419999999999999974Initial program 34.6%
Taylor expanded in x around 0 67.4%
*-commutative67.4%
Simplified67.4%
if 0.00419999999999999974 < x Initial program 98.9%
associate-/r*99.5%
div-inv99.3%
Applied egg-rr99.3%
un-div-inv99.5%
Applied egg-rr99.5%
Final simplification77.1%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ 1.0 x_m) (+ (* x_m 0.16666666666666666) (* (/ 1.0 x_m) 2.0))))
x_m = fabs(x);
double code(double x_m) {
return (1.0 / x_m) / ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (1.0d0 / x_m) / ((x_m * 0.16666666666666666d0) + ((1.0d0 / x_m) * 2.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (1.0 / x_m) / ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0));
}
x_m = math.fabs(x) def code(x_m): return (1.0 / x_m) / ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0))
x_m = abs(x) function code(x_m) return Float64(Float64(1.0 / x_m) / Float64(Float64(x_m * 0.16666666666666666) + Float64(Float64(1.0 / x_m) * 2.0))) end
x_m = abs(x); function tmp = code(x_m) tmp = (1.0 / x_m) / ((x_m * 0.16666666666666666) + ((1.0 / x_m) * 2.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(x$95$m * 0.16666666666666666), $MachinePrecision] + N[(N[(1.0 / x$95$m), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{1}{x_m}}{x_m \cdot 0.16666666666666666 + \frac{1}{x_m} \cdot 2}
\end{array}
Initial program 54.2%
associate-/r*55.6%
div-inv55.5%
Applied egg-rr55.5%
*-commutative55.5%
clear-num55.5%
un-div-inv55.5%
Applied egg-rr55.5%
Taylor expanded in x around 0 74.3%
Final simplification74.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 3.5) 0.5 (/ (/ 1.0 x_m) (* x_m 0.16666666666666666))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 3.5) {
tmp = 0.5;
} else {
tmp = (1.0 / x_m) / (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 3.5d0) then
tmp = 0.5d0
else
tmp = (1.0d0 / x_m) / (x_m * 0.16666666666666666d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 3.5) {
tmp = 0.5;
} else {
tmp = (1.0 / x_m) / (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 3.5: tmp = 0.5 else: tmp = (1.0 / x_m) / (x_m * 0.16666666666666666) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 3.5) tmp = 0.5; else tmp = Float64(Float64(1.0 / x_m) / Float64(x_m * 0.16666666666666666)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 3.5) tmp = 0.5; else tmp = (1.0 / x_m) / (x_m * 0.16666666666666666); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 3.5], 0.5, N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(x$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 3.5:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x_m}}{x_m \cdot 0.16666666666666666}\\
\end{array}
\end{array}
if x < 3.5Initial program 34.6%
Taylor expanded in x around 0 67.6%
if 3.5 < x Initial program 98.9%
associate-/r*99.5%
div-inv99.3%
Applied egg-rr99.3%
*-commutative99.3%
clear-num99.3%
un-div-inv99.4%
Applied egg-rr99.4%
Taylor expanded in x around 0 54.4%
Taylor expanded in x around inf 54.4%
*-commutative54.4%
Simplified54.4%
Final simplification63.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 0.5)
x_m = fabs(x);
double code(double x_m) {
return 0.5;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.5d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.5;
}
x_m = math.fabs(x) def code(x_m): return 0.5
x_m = abs(x) function code(x_m) return 0.5 end
x_m = abs(x); function tmp = code(x_m) tmp = 0.5; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 0.5
\begin{array}{l}
x_m = \left|x\right|
\\
0.5
\end{array}
Initial program 54.2%
Taylor expanded in x around 0 48.3%
Final simplification48.3%
herbie shell --seed 2024024
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))