Average Error: 55.3 → 0.5
Time: 17.3s
Precision: 64
$\cos \left(x + 1\right) - \cos 1$
$\begin{array}{l} \mathbf{if}\;x \le -17243517846109498:\\ \;\;\;\;\cos x \cdot \cos 1 - \left(\cos 1 + \sin x \cdot \sin 1\right)\\ \mathbf{elif}\;x \le 401435.715085908654145896434783935546875:\\ \;\;\;\;-2 \cdot \left(\sin \left(\frac{x}{2}\right) \cdot \sin \left(\frac{1 + \left(x + 1\right)}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos x \cdot \cos 1 - \sin x \cdot \sin 1\right) - \cos 1\\ \end{array}$
\cos \left(x + 1\right) - \cos 1
\begin{array}{l}
\mathbf{if}\;x \le -17243517846109498:\\
\;\;\;\;\cos x \cdot \cos 1 - \left(\cos 1 + \sin x \cdot \sin 1\right)\\

\mathbf{elif}\;x \le 401435.715085908654145896434783935546875:\\
\;\;\;\;-2 \cdot \left(\sin \left(\frac{x}{2}\right) \cdot \sin \left(\frac{1 + \left(x + 1\right)}{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\cos x \cdot \cos 1 - \sin x \cdot \sin 1\right) - \cos 1\\

\end{array}
double f(double x) {
double r42592769 = x;
double r42592770 = 1.0;
double r42592771 = r42592769 + r42592770;
double r42592772 = cos(r42592771);
double r42592773 = cos(r42592770);
double r42592774 = r42592772 - r42592773;
return r42592774;
}


double f(double x) {
double r42592775 = x;
double r42592776 = -17243517846109498.0;
bool r42592777 = r42592775 <= r42592776;
double r42592778 = cos(r42592775);
double r42592779 = 1.0;
double r42592780 = cos(r42592779);
double r42592781 = r42592778 * r42592780;
double r42592782 = sin(r42592775);
double r42592783 = sin(r42592779);
double r42592784 = r42592782 * r42592783;
double r42592785 = r42592780 + r42592784;
double r42592786 = r42592781 - r42592785;
double r42592787 = 401435.71508590865;
bool r42592788 = r42592775 <= r42592787;
double r42592789 = -2.0;
double r42592790 = 2.0;
double r42592791 = r42592775 / r42592790;
double r42592792 = sin(r42592791);
double r42592793 = r42592775 + r42592779;
double r42592794 = r42592779 + r42592793;
double r42592795 = r42592794 / r42592790;
double r42592796 = sin(r42592795);
double r42592797 = r42592792 * r42592796;
double r42592798 = r42592789 * r42592797;
double r42592799 = r42592781 - r42592784;
double r42592800 = r42592799 - r42592780;
double r42592801 = r42592788 ? r42592798 : r42592800;
double r42592802 = r42592777 ? r42592786 : r42592801;
return r42592802;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 3 regimes
2. ## if x < -17243517846109498.0

1. Initial program 55.2

$\cos \left(x + 1\right) - \cos 1$
2. Using strategy rm
3. Applied cos-sum0.9

$\leadsto \color{blue}{\left(\cos x \cdot \cos 1 - \sin x \cdot \sin 1\right)} - \cos 1$
4. Applied associate--l-0.9

$\leadsto \color{blue}{\cos x \cdot \cos 1 - \left(\sin x \cdot \sin 1 + \cos 1\right)}$

## if -17243517846109498.0 < x < 401435.71508590865

1. Initial program 56.3

$\cos \left(x + 1\right) - \cos 1$
2. Using strategy rm
3. Applied diff-cos56.3

$\leadsto \color{blue}{-2 \cdot \left(\sin \left(\frac{\left(x + 1\right) - 1}{2}\right) \cdot \sin \left(\frac{\left(x + 1\right) + 1}{2}\right)\right)}$
4. Simplified0.1

$\leadsto -2 \cdot \color{blue}{\left(\sin \left(\frac{x}{2}\right) \cdot \sin \left(\frac{1 + \left(x + 1\right)}{2}\right)\right)}$

## if 401435.71508590865 < x

1. Initial program 53.1

$\cos \left(x + 1\right) - \cos 1$
2. Using strategy rm
3. Applied cos-sum0.9

$\leadsto \color{blue}{\left(\cos x \cdot \cos 1 - \sin x \cdot \sin 1\right)} - \cos 1$
3. Recombined 3 regimes into one program.
4. Final simplification0.5

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -17243517846109498:\\ \;\;\;\;\cos x \cdot \cos 1 - \left(\cos 1 + \sin x \cdot \sin 1\right)\\ \mathbf{elif}\;x \le 401435.715085908654145896434783935546875:\\ \;\;\;\;-2 \cdot \left(\sin \left(\frac{x}{2}\right) \cdot \sin \left(\frac{1 + \left(x + 1\right)}{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos x \cdot \cos 1 - \sin x \cdot \sin 1\right) - \cos 1\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x)
:name "cos(x+1)-cos(1)"
(- (cos (+ x 1.0)) (cos 1.0)))