Average Error: 30.9 → 0.5
Time: 16.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.01939010062697287678501467667047108989209:\\ \;\;\;\;\frac{1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\\ \mathbf{elif}\;x \le 0.02404792443261856427216827114534680731595:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1}}{\sin x}\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.01939010062697287678501467667047108989209:\\
\;\;\;\;\frac{1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\\

\mathbf{elif}\;x \le 0.02404792443261856427216827114534680731595:\\
\;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1}}{\sin x}\\

\end{array}
double f(double x) {
        double r54739 = 1.0;
        double r54740 = x;
        double r54741 = cos(r54740);
        double r54742 = r54739 - r54741;
        double r54743 = sin(r54740);
        double r54744 = r54742 / r54743;
        return r54744;
}

double f(double x) {
        double r54745 = x;
        double r54746 = -0.019390100626972877;
        bool r54747 = r54745 <= r54746;
        double r54748 = 1.0;
        double r54749 = r54748 * r54748;
        double r54750 = cos(r54745);
        double r54751 = 2.0;
        double r54752 = pow(r54750, r54751);
        double r54753 = r54752 - r54749;
        double r54754 = r54752 * r54753;
        double r54755 = r54750 - r54748;
        double r54756 = r54750 * r54755;
        double r54757 = r54754 / r54756;
        double r54758 = r54749 + r54757;
        double r54759 = sin(r54745);
        double r54760 = r54748 - r54750;
        double r54761 = r54750 + r54748;
        double r54762 = r54750 * r54761;
        double r54763 = r54762 + r54749;
        double r54764 = r54760 / r54763;
        double r54765 = r54759 / r54764;
        double r54766 = r54758 / r54765;
        double r54767 = 0.024047924432618564;
        bool r54768 = r54745 <= r54767;
        double r54769 = 0.041666666666666664;
        double r54770 = 3.0;
        double r54771 = pow(r54745, r54770);
        double r54772 = r54769 * r54771;
        double r54773 = 0.004166666666666667;
        double r54774 = 5.0;
        double r54775 = pow(r54745, r54774);
        double r54776 = r54773 * r54775;
        double r54777 = 0.5;
        double r54778 = r54777 * r54745;
        double r54779 = r54776 + r54778;
        double r54780 = r54772 + r54779;
        double r54781 = pow(r54748, r54770);
        double r54782 = pow(r54750, r54770);
        double r54783 = r54781 - r54782;
        double r54784 = r54753 / r54755;
        double r54785 = r54750 * r54784;
        double r54786 = r54785 + r54749;
        double r54787 = r54783 / r54786;
        double r54788 = r54787 / r54759;
        double r54789 = r54768 ? r54780 : r54788;
        double r54790 = r54747 ? r54766 : r54789;
        return r54790;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.9
Target0.0
Herbie0.5
\[\tan \left(\frac{x}{2}\right)\]

Derivation

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

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--1.1

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{\sin x}\]
    4. Simplified1.1

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity1.1

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}}{\sin x}\]
    7. Applied difference-cubes1.0

      \[\leadsto \frac{\frac{\color{blue}{\left(1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)\right) \cdot \left(1 - \cos x\right)}}{1 \cdot \left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right)}}{\sin x}\]
    8. Applied times-frac1.1

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1} \cdot \frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    9. Applied associate-/l*1.1

      \[\leadsto \color{blue}{\frac{\frac{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}{1}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}}\]
    10. Using strategy rm
    11. Applied flip-+1.1

      \[\leadsto \frac{\frac{1 \cdot 1 + \color{blue}{\frac{\left(\cos x \cdot \cos x\right) \cdot \left(\cos x \cdot \cos x\right) - \left(1 \cdot \cos x\right) \cdot \left(1 \cdot \cos x\right)}{\cos x \cdot \cos x - 1 \cdot \cos x}}}{1}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\]
    12. Simplified1.1

      \[\leadsto \frac{\frac{1 \cdot 1 + \frac{\color{blue}{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}}{\cos x \cdot \cos x - 1 \cdot \cos x}}{1}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\]
    13. Simplified1.1

      \[\leadsto \frac{\frac{1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\color{blue}{\cos x \cdot \left(\cos x - 1\right)}}}{1}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\]

    if -0.019390100626972877 < x < 0.024047924432618564

    1. Initial program 59.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Taylor expanded around 0 0.0

      \[\leadsto \color{blue}{\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)}\]

    if 0.024047924432618564 < x

    1. Initial program 0.9

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied flip3--1.0

      \[\leadsto \frac{\color{blue}{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}}{\sin x}\]
    4. Simplified1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}{\sin x}\]
    5. Using strategy rm
    6. Applied flip-+1.0

      \[\leadsto \frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \color{blue}{\frac{\cos x \cdot \cos x - 1 \cdot 1}{\cos x - 1}} + 1 \cdot 1}}{\sin x}\]
    7. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.01939010062697287678501467667047108989209:\\ \;\;\;\;\frac{1 \cdot 1 + \frac{{\left(\cos x\right)}^{2} \cdot \left({\left(\cos x\right)}^{2} - 1 \cdot 1\right)}{\cos x \cdot \left(\cos x - 1\right)}}{\frac{\sin x}{\frac{1 - \cos x}{\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1}}}\\ \mathbf{elif}\;x \le 0.02404792443261856427216827114534680731595:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\cos x \cdot \frac{{\left(\cos x\right)}^{2} - 1 \cdot 1}{\cos x - 1} + 1 \cdot 1}}{\sin x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019350 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :precision binary64
  :herbie-expected 2

  :herbie-target
  (tan (/ x 2))

  (/ (- 1 (cos x)) (sin x)))