Average Error: 29.7 → 0.3
Time: 17.6s
Precision: 64
$\cos^{-1} \left(\cos x\right)$
$\begin{array}{l} \mathbf{if}\;x \le -3.303620912214833005293712631100788712502:\\ \;\;\;\;\log \left(e^{\cos^{-1} \left(\cos x\right)}\right)\\ \mathbf{elif}\;x \le 0.7650912543039395385946477290417533367872:\\ \;\;\;\;\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\cos^{-1} \left(\cos x\right)\right)}\\ \end{array}$
\cos^{-1} \left(\cos x\right)
\begin{array}{l}
\mathbf{if}\;x \le -3.303620912214833005293712631100788712502:\\
\;\;\;\;\log \left(e^{\cos^{-1} \left(\cos x\right)}\right)\\

\mathbf{elif}\;x \le 0.7650912543039395385946477290417533367872:\\
\;\;\;\;\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\

\mathbf{else}:\\
\;\;\;\;e^{\log \left(\cos^{-1} \left(\cos x\right)\right)}\\

\end{array}
double f(double x) {
double r350571 = x;
double r350572 = cos(r350571);
double r350573 = acos(r350572);
return r350573;
}


double f(double x) {
double r350574 = x;
double r350575 = -3.303620912214833;
bool r350576 = r350574 <= r350575;
double r350577 = cos(r350574);
double r350578 = acos(r350577);
double r350579 = exp(r350578);
double r350580 = log(r350579);
double r350581 = 0.7650912543039395;
bool r350582 = r350574 <= r350581;
double r350583 = 2.0;
double r350584 = atan2(1.0, 0.0);
double r350585 = r350583 * r350584;
double r350586 = remainder(r350574, r350585);
double r350587 = fabs(r350586);
double r350588 = log(r350578);
double r350589 = exp(r350588);
double r350590 = r350582 ? r350587 : r350589;
double r350591 = r350576 ? r350580 : r350590;
return r350591;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

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

1. Initial program 0.6

$\cos^{-1} \left(\cos x\right)$
2. Using strategy rm

$\leadsto \color{blue}{\log \left(e^{\cos^{-1} \left(\cos x\right)}\right)}$

## if -3.303620912214833 < x < 0.7650912543039395

1. Initial program 59.2

$\cos^{-1} \left(\cos x\right)$
2. Using strategy rm
3. Applied acos-cos0

$\leadsto \color{blue}{\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|}$

## if 0.7650912543039395 < x

1. Initial program 0.6

$\cos^{-1} \left(\cos x\right)$
2. Using strategy rm

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

$\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.303620912214833005293712631100788712502:\\ \;\;\;\;\log \left(e^{\cos^{-1} \left(\cos x\right)}\right)\\ \mathbf{elif}\;x \le 0.7650912543039395385946477290417533367872:\\ \;\;\;\;\left|\left(x \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\cos^{-1} \left(\cos x\right)\right)}\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (x)
:name "acos(cos(x))"
:precision binary64
(acos (cos x)))