
(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 10 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 2.6e-8) 0.5 (* (tan (/ x_m 2.0)) (/ (sin x_m) (pow x_m 2.0)))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.6e-8) {
tmp = 0.5;
} else {
tmp = tan((x_m / 2.0)) * (sin(x_m) / pow(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 <= 2.6d-8) then
tmp = 0.5d0
else
tmp = tan((x_m / 2.0d0)) * (sin(x_m) / (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 <= 2.6e-8) {
tmp = 0.5;
} else {
tmp = Math.tan((x_m / 2.0)) * (Math.sin(x_m) / Math.pow(x_m, 2.0));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.6e-8: tmp = 0.5 else: tmp = math.tan((x_m / 2.0)) * (math.sin(x_m) / math.pow(x_m, 2.0)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.6e-8) tmp = 0.5; else tmp = Float64(tan(Float64(x_m / 2.0)) * Float64(sin(x_m) / (x_m ^ 2.0))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 2.6e-8) tmp = 0.5; else tmp = tan((x_m / 2.0)) * (sin(x_m) / (x_m ^ 2.0)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.6e-8], 0.5, N[(N[Tan[N[(x$95$m / 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[x$95$m], $MachinePrecision] / N[Power[x$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.6 \cdot 10^{-8}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\tan \left(\frac{x\_m}{2}\right) \cdot \frac{\sin x\_m}{{x\_m}^{2}}\\
\end{array}
\end{array}
if x < 2.6000000000000001e-8Initial program 38.9%
Taylor expanded in x around 0 63.6%
if 2.6000000000000001e-8 < x Initial program 99.3%
clear-num99.3%
inv-pow99.3%
flip--98.9%
associate-/r/98.9%
unpow-prod-down98.8%
pow298.8%
metadata-eval98.8%
pow298.8%
inv-pow98.8%
Applied egg-rr98.8%
associate-*r/98.9%
*-rgt-identity98.9%
unpow-198.9%
Simplified98.9%
unpow298.9%
1-sub-cos99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 98.9%
unpow298.9%
*-commutative98.9%
times-frac98.9%
hang-0p-tan99.6%
Simplified99.6%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.032)
(+
0.5
(*
(pow x_m 2.0)
(- (* (pow x_m 2.0) 0.001388888888888889) 0.041666666666666664)))
(- (pow x_m -2.0) (* (cos x_m) (pow x_m -2.0)))))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.032) {
tmp = 0.5 + (pow(x_m, 2.0) * ((pow(x_m, 2.0) * 0.001388888888888889) - 0.041666666666666664));
} else {
tmp = pow(x_m, -2.0) - (cos(x_m) * pow(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.032d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (((x_m ** 2.0d0) * 0.001388888888888889d0) - 0.041666666666666664d0))
else
tmp = (x_m ** (-2.0d0)) - (cos(x_m) * (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.032) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * ((Math.pow(x_m, 2.0) * 0.001388888888888889) - 0.041666666666666664));
} else {
tmp = Math.pow(x_m, -2.0) - (Math.cos(x_m) * Math.pow(x_m, -2.0));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.032: tmp = 0.5 + (math.pow(x_m, 2.0) * ((math.pow(x_m, 2.0) * 0.001388888888888889) - 0.041666666666666664)) else: tmp = math.pow(x_m, -2.0) - (math.cos(x_m) * math.pow(x_m, -2.0)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.032) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * Float64(Float64((x_m ^ 2.0) * 0.001388888888888889) - 0.041666666666666664))); else tmp = Float64((x_m ^ -2.0) - Float64(cos(x_m) * (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.032) tmp = 0.5 + ((x_m ^ 2.0) * (((x_m ^ 2.0) * 0.001388888888888889) - 0.041666666666666664)); else tmp = (x_m ^ -2.0) - (cos(x_m) * (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.032], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.001388888888888889), $MachinePrecision] - 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x$95$m, -2.0], $MachinePrecision] - N[(N[Cos[x$95$m], $MachinePrecision] * N[Power[x$95$m, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.032:\\
\;\;\;\;0.5 + {x\_m}^{2} \cdot \left({x\_m}^{2} \cdot 0.001388888888888889 - 0.041666666666666664\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{-2} - \cos x\_m \cdot {x\_m}^{-2}\\
\end{array}
\end{array}
if x < 0.032000000000000001Initial program 38.9%
Taylor expanded in x around 0 63.2%
if 0.032000000000000001 < x Initial program 99.3%
div-sub99.3%
pow299.3%
pow-flip99.1%
metadata-eval99.1%
div-inv99.1%
pow299.1%
pow-flip99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Final simplification72.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (/ 1.0 (pow (/ x_m (sin x_m)) 2.0)) (+ 1.0 (cos x_m))))
x_m = fabs(x);
double code(double x_m) {
return (1.0 / pow((x_m / sin(x_m)), 2.0)) / (1.0 + cos(x_m));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (1.0d0 / ((x_m / sin(x_m)) ** 2.0d0)) / (1.0d0 + cos(x_m))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return (1.0 / Math.pow((x_m / Math.sin(x_m)), 2.0)) / (1.0 + Math.cos(x_m));
}
x_m = math.fabs(x) def code(x_m): return (1.0 / math.pow((x_m / math.sin(x_m)), 2.0)) / (1.0 + math.cos(x_m))
x_m = abs(x) function code(x_m) return Float64(Float64(1.0 / (Float64(x_m / sin(x_m)) ^ 2.0)) / Float64(1.0 + cos(x_m))) end
x_m = abs(x); function tmp = code(x_m) tmp = (1.0 / ((x_m / sin(x_m)) ^ 2.0)) / (1.0 + cos(x_m)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[(1.0 / N[Power[N[(x$95$m / N[Sin[x$95$m], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Cos[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{\frac{1}{{\left(\frac{x\_m}{\sin x\_m}\right)}^{2}}}{1 + \cos x\_m}
\end{array}
Initial program 54.2%
clear-num54.2%
inv-pow54.2%
flip--54.0%
associate-/r/54.0%
unpow-prod-down54.0%
pow254.0%
metadata-eval54.0%
pow254.0%
inv-pow54.0%
Applied egg-rr54.0%
associate-*r/54.1%
*-rgt-identity54.1%
unpow-154.1%
Simplified54.1%
unpow254.1%
1-sub-cos76.1%
Applied egg-rr76.1%
Taylor expanded in x around inf 76.1%
unpow276.1%
unpow276.1%
times-frac99.5%
unpow299.5%
Simplified99.5%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (/ (pow (/ (sin x_m) x_m) 2.0) (- (cos x_m) -1.0)))
x_m = fabs(x);
double code(double x_m) {
return pow((sin(x_m) / x_m), 2.0) / (cos(x_m) - -1.0);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = ((sin(x_m) / x_m) ** 2.0d0) / (cos(x_m) - (-1.0d0))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow((Math.sin(x_m) / x_m), 2.0) / (Math.cos(x_m) - -1.0);
}
x_m = math.fabs(x) def code(x_m): return math.pow((math.sin(x_m) / x_m), 2.0) / (math.cos(x_m) - -1.0)
x_m = abs(x) function code(x_m) return Float64((Float64(sin(x_m) / x_m) ^ 2.0) / Float64(cos(x_m) - -1.0)) end
x_m = abs(x); function tmp = code(x_m) tmp = ((sin(x_m) / x_m) ^ 2.0) / (cos(x_m) - -1.0); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[N[(N[Sin[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision], 2.0], $MachinePrecision] / N[(N[Cos[x$95$m], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
\frac{{\left(\frac{\sin x\_m}{x\_m}\right)}^{2}}{\cos x\_m - -1}
\end{array}
Initial program 54.2%
clear-num54.2%
inv-pow54.2%
flip--54.0%
associate-/r/54.0%
unpow-prod-down54.0%
pow254.0%
metadata-eval54.0%
pow254.0%
inv-pow54.0%
Applied egg-rr54.0%
associate-*r/54.1%
*-rgt-identity54.1%
unpow-154.1%
Simplified54.1%
unpow254.1%
1-sub-cos76.1%
Applied egg-rr76.1%
frac-2neg76.1%
div-inv76.1%
add-sqr-sqrt76.0%
pow276.0%
associate-/r/74.8%
pow-flip74.8%
metadata-eval74.8%
sqrt-prod74.8%
sqrt-pow176.3%
metadata-eval76.3%
inv-pow76.3%
sqrt-prod49.0%
add-sqr-sqrt99.3%
Applied egg-rr99.3%
associate-*r/99.3%
*-rgt-identity99.3%
associate-*l/99.5%
*-lft-identity99.5%
distribute-neg-in99.5%
metadata-eval99.5%
unsub-neg99.5%
Simplified99.5%
Final simplification99.5%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.031)
(+
0.5
(*
(pow x_m 2.0)
(- (* (pow x_m 2.0) 0.001388888888888889) 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.031) {
tmp = 0.5 + (pow(x_m, 2.0) * ((pow(x_m, 2.0) * 0.001388888888888889) - 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.031d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (((x_m ** 2.0d0) * 0.001388888888888889d0) - 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.031) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * ((Math.pow(x_m, 2.0) * 0.001388888888888889) - 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.031: tmp = 0.5 + (math.pow(x_m, 2.0) * ((math.pow(x_m, 2.0) * 0.001388888888888889) - 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.031) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * Float64(Float64((x_m ^ 2.0) * 0.001388888888888889) - 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.031) tmp = 0.5 + ((x_m ^ 2.0) * (((x_m ^ 2.0) * 0.001388888888888889) - 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.031], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.001388888888888889), $MachinePrecision] - 0.041666666666666664), $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.031:\\
\;\;\;\;0.5 + {x\_m}^{2} \cdot \left({x\_m}^{2} \cdot 0.001388888888888889 - 0.041666666666666664\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x\_m}{x\_m}}{x\_m}\\
\end{array}
\end{array}
if x < 0.031Initial program 38.9%
Taylor expanded in x around 0 63.2%
if 0.031 < x Initial program 99.3%
add-cbrt-cube70.8%
pow1/369.6%
pow369.5%
add-sqr-sqrt69.5%
pow269.5%
pow-pow69.5%
sqrt-div69.6%
sqrt-prod69.6%
add-sqr-sqrt69.6%
metadata-eval69.6%
Applied egg-rr69.6%
pow-pow99.1%
metadata-eval99.1%
pow299.1%
frac-times99.1%
add-sqr-sqrt99.3%
rem-log-exp99.1%
rem-log-exp99.3%
associate-/r*99.3%
Applied egg-rr99.3%
Final simplification72.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.00014) 0.5 (/ (/ (- 1.0 (cos x_m)) x_m) x_m)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.00014) {
tmp = 0.5;
} 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.00014d0) then
tmp = 0.5d0
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.00014) {
tmp = 0.5;
} 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.00014: tmp = 0.5 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.00014) tmp = 0.5; 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.00014) tmp = 0.5; 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.00014], 0.5, 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.00014:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 - \cos x\_m}{x\_m}}{x\_m}\\
\end{array}
\end{array}
if x < 1.3999999999999999e-4Initial program 38.9%
Taylor expanded in x around 0 63.6%
if 1.3999999999999999e-4 < x Initial program 99.3%
add-cbrt-cube70.8%
pow1/369.6%
pow369.5%
add-sqr-sqrt69.5%
pow269.5%
pow-pow69.5%
sqrt-div69.6%
sqrt-prod69.6%
add-sqr-sqrt69.6%
metadata-eval69.6%
Applied egg-rr69.6%
pow-pow99.1%
metadata-eval99.1%
pow299.1%
frac-times99.1%
add-sqr-sqrt99.3%
rem-log-exp99.1%
rem-log-exp99.3%
associate-/r*99.3%
Applied egg-rr99.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 0.00014) 0.5 (/ (- 1.0 (cos x_m)) (* x_m x_m))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.00014) {
tmp = 0.5;
} 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.00014d0) then
tmp = 0.5d0
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.00014) {
tmp = 0.5;
} 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.00014: tmp = 0.5 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.00014) tmp = 0.5; 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.00014) tmp = 0.5; 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.00014], 0.5, 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.00014:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - \cos x\_m}{x\_m \cdot x\_m}\\
\end{array}
\end{array}
if x < 1.3999999999999999e-4Initial program 38.9%
Taylor expanded in x around 0 63.6%
if 1.3999999999999999e-4 < x Initial program 99.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 3.35) (+ 0.5 (* (pow x_m 2.0) -0.041666666666666664)) (* (pow x_m -4.0) 120.0)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 3.35) {
tmp = 0.5 + (pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = pow(x_m, -4.0) * 120.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 <= 3.35d0) then
tmp = 0.5d0 + ((x_m ** 2.0d0) * (-0.041666666666666664d0))
else
tmp = (x_m ** (-4.0d0)) * 120.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 3.35) {
tmp = 0.5 + (Math.pow(x_m, 2.0) * -0.041666666666666664);
} else {
tmp = Math.pow(x_m, -4.0) * 120.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 3.35: tmp = 0.5 + (math.pow(x_m, 2.0) * -0.041666666666666664) else: tmp = math.pow(x_m, -4.0) * 120.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 3.35) tmp = Float64(0.5 + Float64((x_m ^ 2.0) * -0.041666666666666664)); else tmp = Float64((x_m ^ -4.0) * 120.0); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 3.35) tmp = 0.5 + ((x_m ^ 2.0) * -0.041666666666666664); else tmp = (x_m ^ -4.0) * 120.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 3.35], N[(0.5 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[Power[x$95$m, -4.0], $MachinePrecision] * 120.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 3.35:\\
\;\;\;\;0.5 + {x\_m}^{2} \cdot -0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{-4} \cdot 120\\
\end{array}
\end{array}
if x < 3.35000000000000009Initial program 39.2%
Taylor expanded in x around 0 62.6%
if 3.35000000000000009 < x Initial program 99.3%
associate-/r*99.3%
clear-num99.3%
inv-pow99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 49.5%
*-commutative49.5%
Simplified49.5%
Taylor expanded in x around inf 49.5%
*-un-lft-identity49.5%
pow149.5%
pow149.5%
div-inv49.5%
pow-flip49.5%
metadata-eval49.5%
Applied egg-rr49.5%
*-lft-identity49.5%
*-commutative49.5%
Simplified49.5%
Final simplification59.4%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 4.0) 0.5 (* (pow x_m -4.0) 120.0)))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 4.0) {
tmp = 0.5;
} else {
tmp = pow(x_m, -4.0) * 120.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 <= 4.0d0) then
tmp = 0.5d0
else
tmp = (x_m ** (-4.0d0)) * 120.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 4.0) {
tmp = 0.5;
} else {
tmp = Math.pow(x_m, -4.0) * 120.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 4.0: tmp = 0.5 else: tmp = math.pow(x_m, -4.0) * 120.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 4.0) tmp = 0.5; else tmp = Float64((x_m ^ -4.0) * 120.0); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 4.0) tmp = 0.5; else tmp = (x_m ^ -4.0) * 120.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 4.0], 0.5, N[(N[Power[x$95$m, -4.0], $MachinePrecision] * 120.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 4:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{-4} \cdot 120\\
\end{array}
\end{array}
if x < 4Initial program 39.2%
Taylor expanded in x around 0 63.4%
if 4 < x Initial program 99.3%
associate-/r*99.3%
clear-num99.3%
inv-pow99.3%
Applied egg-rr99.3%
Taylor expanded in x around 0 49.5%
*-commutative49.5%
Simplified49.5%
Taylor expanded in x around inf 49.5%
*-un-lft-identity49.5%
pow149.5%
pow149.5%
div-inv49.5%
pow-flip49.5%
metadata-eval49.5%
Applied egg-rr49.5%
*-lft-identity49.5%
*-commutative49.5%
Simplified49.5%
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.7%
herbie shell --seed 2024096
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))