(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
:precision binary64
(if (<= x -1.6606336791038125)
(* (pow x -2.0) (- 1.0 (cos x)))
(if (<= x 0.00033956055970997177)
(fma
0.001388888888888889
(pow x 4.0)
(fma -0.041666666666666664 (* x x) 0.5))
(- (pow x -2.0) (* (pow x -2.0) (cos x))))))double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
double tmp;
if (x <= -1.6606336791038125) {
tmp = pow(x, -2.0) * (1.0 - cos(x));
} else if (x <= 0.00033956055970997177) {
tmp = fma(0.001388888888888889, pow(x, 4.0), fma(-0.041666666666666664, (x * x), 0.5));
} else {
tmp = pow(x, -2.0) - (pow(x, -2.0) * cos(x));
}
return tmp;
}
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function code(x) tmp = 0.0 if (x <= -1.6606336791038125) tmp = Float64((x ^ -2.0) * Float64(1.0 - cos(x))); elseif (x <= 0.00033956055970997177) tmp = fma(0.001388888888888889, (x ^ 4.0), fma(-0.041666666666666664, Float64(x * x), 0.5)); else tmp = Float64((x ^ -2.0) - Float64((x ^ -2.0) * cos(x))); end return tmp end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -1.6606336791038125], N[(N[Power[x, -2.0], $MachinePrecision] * N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.00033956055970997177], N[(0.001388888888888889 * N[Power[x, 4.0], $MachinePrecision] + N[(-0.041666666666666664 * N[(x * x), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -2.0], $MachinePrecision] - N[(N[Power[x, -2.0], $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -1.6606336791038125:\\
\;\;\;\;{x}^{-2} \cdot \left(1 - \cos x\right)\\
\mathbf{elif}\;x \leq 0.00033956055970997177:\\
\;\;\;\;\mathsf{fma}\left(0.001388888888888889, {x}^{4}, \mathsf{fma}\left(-0.041666666666666664, x \cdot x, 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{-2} - {x}^{-2} \cdot \cos x\\
\end{array}
if x < -1.6606336791038125Initial program 1.1
Applied egg-rr1.2
Applied egg-rr0.6
Taylor expanded in x around -inf 1.2
Applied egg-rr0.5
if -1.6606336791038125 < x < 3.3956055970997177e-4Initial program 62.4
Taylor expanded in x around 0 0.1
Simplified0.1
if 3.3956055970997177e-4 < x Initial program 1.3
Applied egg-rr0.6
Final simplification0.3
herbie shell --seed 2022210
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))