Average Error: 40.0 → 0.4
Time: 8.0s
Precision: binary64
\[\cos \left(x + \varepsilon\right) - \cos x \]
\[\begin{array}{l} t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\ t_1 := 0.5 \cdot \left(x + x\right)\\ -2 \cdot \left(t_0 \cdot \left(\sin t_1 \cdot \cos \left(0.5 \cdot \varepsilon\right) + t_0 \cdot \cos t_1\right)\right) \end{array} \]
(FPCore (x eps) :precision binary64 (- (cos (+ x eps)) (cos x)))
(FPCore (x eps)
 :precision binary64
 (let* ((t_0 (sin (* 0.5 eps))) (t_1 (* 0.5 (+ x x))))
   (* -2.0 (* t_0 (+ (* (sin t_1) (cos (* 0.5 eps))) (* t_0 (cos t_1)))))))
double code(double x, double eps) {
	return cos((x + eps)) - cos(x);
}
double code(double x, double eps) {
	double t_0 = sin((0.5 * eps));
	double t_1 = 0.5 * (x + x);
	return -2.0 * (t_0 * ((sin(t_1) * cos((0.5 * eps))) + (t_0 * cos(t_1))));
}
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    code = cos((x + eps)) - cos(x)
end function
real(8) function code(x, eps)
    real(8), intent (in) :: x
    real(8), intent (in) :: eps
    real(8) :: t_0
    real(8) :: t_1
    t_0 = sin((0.5d0 * eps))
    t_1 = 0.5d0 * (x + x)
    code = (-2.0d0) * (t_0 * ((sin(t_1) * cos((0.5d0 * eps))) + (t_0 * cos(t_1))))
end function
public static double code(double x, double eps) {
	return Math.cos((x + eps)) - Math.cos(x);
}
public static double code(double x, double eps) {
	double t_0 = Math.sin((0.5 * eps));
	double t_1 = 0.5 * (x + x);
	return -2.0 * (t_0 * ((Math.sin(t_1) * Math.cos((0.5 * eps))) + (t_0 * Math.cos(t_1))));
}
def code(x, eps):
	return math.cos((x + eps)) - math.cos(x)
def code(x, eps):
	t_0 = math.sin((0.5 * eps))
	t_1 = 0.5 * (x + x)
	return -2.0 * (t_0 * ((math.sin(t_1) * math.cos((0.5 * eps))) + (t_0 * math.cos(t_1))))
function code(x, eps)
	return Float64(cos(Float64(x + eps)) - cos(x))
end
function code(x, eps)
	t_0 = sin(Float64(0.5 * eps))
	t_1 = Float64(0.5 * Float64(x + x))
	return Float64(-2.0 * Float64(t_0 * Float64(Float64(sin(t_1) * cos(Float64(0.5 * eps))) + Float64(t_0 * cos(t_1)))))
end
function tmp = code(x, eps)
	tmp = cos((x + eps)) - cos(x);
end
function tmp = code(x, eps)
	t_0 = sin((0.5 * eps));
	t_1 = 0.5 * (x + x);
	tmp = -2.0 * (t_0 * ((sin(t_1) * cos((0.5 * eps))) + (t_0 * cos(t_1))));
end
code[x_, eps_] := N[(N[Cos[N[(x + eps), $MachinePrecision]], $MachinePrecision] - N[Cos[x], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := Block[{t$95$0 = N[Sin[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(x + x), $MachinePrecision]), $MachinePrecision]}, N[(-2.0 * N[(t$95$0 * N[(N[(N[Sin[t$95$1], $MachinePrecision] * N[Cos[N[(0.5 * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\cos \left(x + \varepsilon\right) - \cos x
\begin{array}{l}
t_0 := \sin \left(0.5 \cdot \varepsilon\right)\\
t_1 := 0.5 \cdot \left(x + x\right)\\
-2 \cdot \left(t_0 \cdot \left(\sin t_1 \cdot \cos \left(0.5 \cdot \varepsilon\right) + t_0 \cdot \cos t_1\right)\right)
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 40.0

    \[\cos \left(x + \varepsilon\right) - \cos x \]
  2. Applied egg-rr15.1

    \[\leadsto \color{blue}{\left(-2 \cdot \sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right)\right) \cdot \sin \left(\left(x + \left(x + \varepsilon\right)\right) \cdot 0.5\right)} \]
  3. Applied egg-rr15.0

    \[\leadsto \left(-2 \cdot \sin \left(\left(\varepsilon + \left(x - x\right)\right) \cdot 0.5\right)\right) \cdot \color{blue}{\left(\sin \left(0.5 \cdot x\right) \cdot \cos \left(0.5 \cdot \left(x + \varepsilon\right)\right) + \cos \left(0.5 \cdot x\right) \cdot \sin \left(0.5 \cdot \left(x + \varepsilon\right)\right)\right)} \]
  4. Applied egg-rr15.1

    \[\leadsto \color{blue}{{\left(-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \sin \left(0.5 \cdot \left(x + \left(x + \varepsilon\right)\right)\right)\right)\right)}^{1}} \]
  5. Applied egg-rr0.4

    \[\leadsto {\left(-2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \color{blue}{\left(\sin \left(0.5 \cdot \left(x + x\right)\right) \cdot \cos \left(0.5 \cdot \varepsilon\right) + \cos \left(0.5 \cdot \left(x + x\right)\right) \cdot \sin \left(0.5 \cdot \varepsilon\right)\right)}\right)\right)}^{1} \]
  6. Final simplification0.4

    \[\leadsto -2 \cdot \left(\sin \left(0.5 \cdot \varepsilon\right) \cdot \left(\sin \left(0.5 \cdot \left(x + x\right)\right) \cdot \cos \left(0.5 \cdot \varepsilon\right) + \sin \left(0.5 \cdot \varepsilon\right) \cdot \cos \left(0.5 \cdot \left(x + x\right)\right)\right)\right) \]

Reproduce

herbie shell --seed 2022210 
(FPCore (x eps)
  :name "2cos (problem 3.3.5)"
  :precision binary64
  (- (cos (+ x eps)) (cos x)))