Average Error: 29.7 → 0.3
Time: 14.2s
Precision: 64
\[\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right) \cdot 2\]
\[\begin{array}{l} \mathbf{if}\;\frac{a}{2} \le -3.285641068493750260870456258999183773994:\\ \;\;\;\;\log \left(e^{\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)}\right) \cdot 2\\ \mathbf{elif}\;\frac{a}{2} \le 0.7732621658960961985584958711115177720785:\\ \;\;\;\;\left|\left(\left(\frac{a}{2}\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right| \cdot 2\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)\right)} \cdot 2\\ \end{array}\]
\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right) \cdot 2
\begin{array}{l}
\mathbf{if}\;\frac{a}{2} \le -3.285641068493750260870456258999183773994:\\
\;\;\;\;\log \left(e^{\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)}\right) \cdot 2\\

\mathbf{elif}\;\frac{a}{2} \le 0.7732621658960961985584958711115177720785:\\
\;\;\;\;\left|\left(\left(\frac{a}{2}\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right| \cdot 2\\

\mathbf{else}:\\
\;\;\;\;e^{\log \left(\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)\right)} \cdot 2\\

\end{array}
double f(double a) {
        double r296656 = a;
        double r296657 = 2.0;
        double r296658 = r296656 / r296657;
        double r296659 = cos(r296658);
        double r296660 = acos(r296659);
        double r296661 = r296660 * r296657;
        return r296661;
}

double f(double a) {
        double r296662 = a;
        double r296663 = 2.0;
        double r296664 = r296662 / r296663;
        double r296665 = -3.2856410684937503;
        bool r296666 = r296664 <= r296665;
        double r296667 = cos(r296664);
        double r296668 = acos(r296667);
        double r296669 = exp(r296668);
        double r296670 = log(r296669);
        double r296671 = r296670 * r296663;
        double r296672 = 0.7732621658960962;
        bool r296673 = r296664 <= r296672;
        double r296674 = 2.0;
        double r296675 = atan2(1.0, 0.0);
        double r296676 = r296674 * r296675;
        double r296677 = remainder(r296664, r296676);
        double r296678 = fabs(r296677);
        double r296679 = r296678 * r296663;
        double r296680 = log(r296668);
        double r296681 = exp(r296680);
        double r296682 = r296681 * r296663;
        double r296683 = r296673 ? r296679 : r296682;
        double r296684 = r296666 ? r296671 : r296683;
        return r296684;
}

Error

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if (/ a 2.0) < -3.2856410684937503

    1. Initial program 0.6

      \[\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right) \cdot 2\]
    2. Using strategy rm
    3. Applied add-log-exp0.7

      \[\leadsto \color{blue}{\log \left(e^{\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)}\right)} \cdot 2\]

    if -3.2856410684937503 < (/ a 2.0) < 0.7732621658960962

    1. Initial program 59.2

      \[\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right) \cdot 2\]
    2. Using strategy rm
    3. Applied acos-cos0.0

      \[\leadsto \color{blue}{\left|\left(\left(\frac{a}{2}\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right|} \cdot 2\]

    if 0.7732621658960962 < (/ a 2.0)

    1. Initial program 0.6

      \[\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right) \cdot 2\]
    2. Using strategy rm
    3. Applied add-exp-log0.6

      \[\leadsto \color{blue}{e^{\log \left(\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)\right)}} \cdot 2\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a}{2} \le -3.285641068493750260870456258999183773994:\\ \;\;\;\;\log \left(e^{\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)}\right) \cdot 2\\ \mathbf{elif}\;\frac{a}{2} \le 0.7732621658960961985584958711115177720785:\\ \;\;\;\;\left|\left(\left(\frac{a}{2}\right) \mathsf{rem} \left(2 \cdot \pi\right)\right)\right| \cdot 2\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left(\cos^{-1} \left(\cos \left(\frac{a}{2}\right)\right)\right)} \cdot 2\\ \end{array}\]

Reproduce

herbie shell --seed 1 
(FPCore (a)
  :name "acos(cos(a / 2)) * 2"
  :precision binary64
  (* (acos (cos (/ a 2))) 2))