| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13376 |
\[\frac{\tan \left(x \cdot 0.5\right)}{x \cdot \frac{x}{\sin x}}
\]
(FPCore (x) :precision binary64 (/ (- 1.0 (cos x)) (* x x)))
(FPCore (x)
:precision binary64
(if (<= x -0.0042)
(/ (/ (- 1.0 (cos x)) x) x)
(if (<= x 0.004)
(+ 0.5 (* -0.041666666666666664 (* x x)))
(/ (* (+ (cos x) -1.0) (/ -1.0 x)) x))))double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
double tmp;
if (x <= -0.0042) {
tmp = ((1.0 - cos(x)) / x) / x;
} else if (x <= 0.004) {
tmp = 0.5 + (-0.041666666666666664 * (x * x));
} else {
tmp = ((cos(x) + -1.0) * (-1.0 / x)) / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 - cos(x)) / (x * x)
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-0.0042d0)) then
tmp = ((1.0d0 - cos(x)) / x) / x
else if (x <= 0.004d0) then
tmp = 0.5d0 + ((-0.041666666666666664d0) * (x * x))
else
tmp = ((cos(x) + (-1.0d0)) * ((-1.0d0) / x)) / x
end if
code = tmp
end function
public static double code(double x) {
return (1.0 - Math.cos(x)) / (x * x);
}
public static double code(double x) {
double tmp;
if (x <= -0.0042) {
tmp = ((1.0 - Math.cos(x)) / x) / x;
} else if (x <= 0.004) {
tmp = 0.5 + (-0.041666666666666664 * (x * x));
} else {
tmp = ((Math.cos(x) + -1.0) * (-1.0 / x)) / x;
}
return tmp;
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
def code(x): tmp = 0 if x <= -0.0042: tmp = ((1.0 - math.cos(x)) / x) / x elif x <= 0.004: tmp = 0.5 + (-0.041666666666666664 * (x * x)) else: tmp = ((math.cos(x) + -1.0) * (-1.0 / x)) / 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 <= -0.0042) tmp = Float64(Float64(Float64(1.0 - cos(x)) / x) / x); elseif (x <= 0.004) tmp = Float64(0.5 + Float64(-0.041666666666666664 * Float64(x * x))); else tmp = Float64(Float64(Float64(cos(x) + -1.0) * Float64(-1.0 / x)) / x); end return tmp end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -0.0042) tmp = ((1.0 - cos(x)) / x) / x; elseif (x <= 0.004) tmp = 0.5 + (-0.041666666666666664 * (x * x)); else tmp = ((cos(x) + -1.0) * (-1.0 / x)) / x; end tmp_2 = tmp; end
code[x_] := N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, -0.0042], N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision], If[LessEqual[x, 0.004], N[(0.5 + N[(-0.041666666666666664 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cos[x], $MachinePrecision] + -1.0), $MachinePrecision] * N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
\mathbf{if}\;x \leq -0.0042:\\
\;\;\;\;\frac{\frac{1 - \cos x}{x}}{x}\\
\mathbf{elif}\;x \leq 0.004:\\
\;\;\;\;0.5 + -0.041666666666666664 \cdot \left(x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\cos x + -1\right) \cdot \frac{-1}{x}}{x}\\
\end{array}
Results
if x < -0.00419999999999999974Initial program 1.1
Applied egg-rr1.1
Applied egg-rr0.5
if -0.00419999999999999974 < x < 0.0040000000000000001Initial program 62.3
Taylor expanded in x around 0 0.0
Simplified0.0
[Start]0.0 | \[ 0.5 + -0.041666666666666664 \cdot {x}^{2}
\] |
|---|---|
unpow2 [=>]0.0 | \[ 0.5 + -0.041666666666666664 \cdot \color{blue}{\left(x \cdot x\right)}
\] |
if 0.0040000000000000001 < x Initial program 1.2
Applied egg-rr1.2
Applied egg-rr0.5
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13376 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Error | 13.6 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 13.6 |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 13.7 |
| Cost | 704 |
| Alternative 7 | |
|---|---|
| Error | 13.8 |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Error | 15.3 |
| Cost | 328 |
| Alternative 9 | |
|---|---|
| Error | 46.3 |
| Cost | 64 |
herbie shell --seed 2023045
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))