| 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
(let* ((t_0 (- 1.0 (cos x))))
(if (<= x -0.00013)
(* (pow x -2.0) t_0)
(if (<= x 0.00018) 0.5 (/ (/ t_0 x) x)))))double code(double x) {
return (1.0 - cos(x)) / (x * x);
}
double code(double x) {
double t_0 = 1.0 - cos(x);
double tmp;
if (x <= -0.00013) {
tmp = pow(x, -2.0) * t_0;
} else if (x <= 0.00018) {
tmp = 0.5;
} else {
tmp = (t_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) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - cos(x)
if (x <= (-0.00013d0)) then
tmp = (x ** (-2.0d0)) * t_0
else if (x <= 0.00018d0) then
tmp = 0.5d0
else
tmp = (t_0 / 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 t_0 = 1.0 - Math.cos(x);
double tmp;
if (x <= -0.00013) {
tmp = Math.pow(x, -2.0) * t_0;
} else if (x <= 0.00018) {
tmp = 0.5;
} else {
tmp = (t_0 / x) / x;
}
return tmp;
}
def code(x): return (1.0 - math.cos(x)) / (x * x)
def code(x): t_0 = 1.0 - math.cos(x) tmp = 0 if x <= -0.00013: tmp = math.pow(x, -2.0) * t_0 elif x <= 0.00018: tmp = 0.5 else: tmp = (t_0 / x) / x return tmp
function code(x) return Float64(Float64(1.0 - cos(x)) / Float64(x * x)) end
function code(x) t_0 = Float64(1.0 - cos(x)) tmp = 0.0 if (x <= -0.00013) tmp = Float64((x ^ -2.0) * t_0); elseif (x <= 0.00018) tmp = 0.5; else tmp = Float64(Float64(t_0 / x) / x); end return tmp end
function tmp = code(x) tmp = (1.0 - cos(x)) / (x * x); end
function tmp_2 = code(x) t_0 = 1.0 - cos(x); tmp = 0.0; if (x <= -0.00013) tmp = (x ^ -2.0) * t_0; elseif (x <= 0.00018) tmp = 0.5; else tmp = (t_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_] := Block[{t$95$0 = N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.00013], N[(N[Power[x, -2.0], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[x, 0.00018], 0.5, N[(N[(t$95$0 / x), $MachinePrecision] / x), $MachinePrecision]]]]
\frac{1 - \cos x}{x \cdot x}
\begin{array}{l}
t_0 := 1 - \cos x\\
\mathbf{if}\;x \leq -0.00013:\\
\;\;\;\;{x}^{-2} \cdot t_0\\
\mathbf{elif}\;x \leq 0.00018:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t_0}{x}}{x}\\
\end{array}
Results
if x < -1.29999999999999989e-4Initial program 1.2
Applied egg-rr0.7
if -1.29999999999999989e-4 < x < 1.80000000000000011e-4Initial program 62.6
Taylor expanded in x around 0 0.1
if 1.80000000000000011e-4 < x Initial program 1.1
Applied egg-rr0.6
Applied egg-rr0.6
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13376 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 7113 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 7113 |
| Alternative 4 | |
|---|---|
| Error | 13.8 |
| Cost | 832 |
| Alternative 5 | |
|---|---|
| Error | 13.8 |
| Cost | 768 |
| Alternative 6 | |
|---|---|
| Error | 13.9 |
| Cost | 585 |
| Alternative 7 | |
|---|---|
| Error | 15.4 |
| Cost | 328 |
| Alternative 8 | |
|---|---|
| Error | 46.8 |
| Cost | 64 |
herbie shell --seed 2023066
(FPCore (x)
:name "cos2 (problem 3.4.1)"
:precision binary64
(/ (- 1.0 (cos x)) (* x x)))