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

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

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

\end{array}
double f(double x) {
        double r65631 = 1.0;
        double r65632 = x;
        double r65633 = cos(r65632);
        double r65634 = r65631 - r65633;
        double r65635 = sin(r65632);
        double r65636 = r65634 / r65635;
        return r65636;
}

double f(double x) {
        double r65637 = x;
        double r65638 = -0.022842957444596936;
        bool r65639 = r65637 <= r65638;
        double r65640 = cos(r65637);
        double r65641 = 1.0;
        double r65642 = r65640 + r65641;
        double r65643 = r65640 * r65642;
        double r65644 = r65641 * r65641;
        double r65645 = r65643 + r65644;
        double r65646 = r65641 - r65640;
        double r65647 = r65645 * r65646;
        double r65648 = 3.0;
        double r65649 = pow(r65640, r65648);
        double r65650 = pow(r65641, r65648);
        double r65651 = r65649 + r65650;
        double r65652 = r65641 * r65646;
        double r65653 = 2.0;
        double r65654 = pow(r65640, r65653);
        double r65655 = r65652 + r65654;
        double r65656 = r65651 / r65655;
        double r65657 = r65640 * r65656;
        double r65658 = r65657 + r65644;
        double r65659 = sin(r65637);
        double r65660 = r65658 * r65659;
        double r65661 = r65647 / r65660;
        double r65662 = 0.02290180043346201;
        bool r65663 = r65637 <= r65662;
        double r65664 = 0.041666666666666664;
        double r65665 = pow(r65637, r65648);
        double r65666 = r65664 * r65665;
        double r65667 = 0.004166666666666667;
        double r65668 = 5.0;
        double r65669 = pow(r65637, r65668);
        double r65670 = r65667 * r65669;
        double r65671 = 0.5;
        double r65672 = r65671 * r65637;
        double r65673 = r65670 + r65672;
        double r65674 = r65666 + r65673;
        double r65675 = r65654 * r65640;
        double r65676 = r65650 - r65675;
        double r65677 = r65645 * r65659;
        double r65678 = r65676 / r65677;
        double r65679 = r65663 ? r65674 : r65678;
        double r65680 = r65639 ? r65661 : r65679;
        return r65680;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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. Applied associate-/l/1.0

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

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

      \[\leadsto \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)}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    8. Simplified1.0

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

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

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

    if -0.022842957444596936 < x < 0.02290180043346201

    1. Initial program 59.8

      \[\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.02290180043346201 < 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. Applied associate-/l/1.0

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

      \[\leadsto \frac{{1}^{3} - {\left(\cos x\right)}^{3}}{\color{blue}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}}\]
    6. Using strategy rm
    7. Applied add-cube-cbrt1.8

      \[\leadsto \frac{{1}^{3} - {\color{blue}{\left(\left(\sqrt[3]{\cos x} \cdot \sqrt[3]{\cos x}\right) \cdot \sqrt[3]{\cos x}\right)}}^{3}}{\left(\cos x \cdot \left(\cos x + 1\right) + 1 \cdot 1\right) \cdot \sin x}\]
    8. Applied unpow-prod-down1.8

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

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

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

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

Reproduce

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

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

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