Average Error: 30.3 → 0.5
Time: 8.5s
Precision: 64
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.02421991371580364468818480361278488999233 \lor \neg \left(x \le 0.02129980552074291558217744579906138824299\right):\\ \;\;\;\;\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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]
\frac{1 - \cos x}{\sin x}
\begin{array}{l}
\mathbf{if}\;x \le -0.02421991371580364468818480361278488999233 \lor \neg \left(x \le 0.02129980552074291558217744579906138824299\right):\\
\;\;\;\;\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}}}\\

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

\end{array}
double f(double x) {
        double r65795 = 1.0;
        double r65796 = x;
        double r65797 = cos(r65796);
        double r65798 = r65795 - r65797;
        double r65799 = sin(r65796);
        double r65800 = r65798 / r65799;
        return r65800;
}

double f(double x) {
        double r65801 = x;
        double r65802 = -0.024219913715803645;
        bool r65803 = r65801 <= r65802;
        double r65804 = 0.021299805520742916;
        bool r65805 = r65801 <= r65804;
        double r65806 = !r65805;
        bool r65807 = r65803 || r65806;
        double r65808 = 1.0;
        double r65809 = r65808 * r65808;
        double r65810 = cos(r65801);
        double r65811 = r65810 * r65810;
        double r65812 = r65808 * r65810;
        double r65813 = r65811 + r65812;
        double r65814 = r65809 + r65813;
        double r65815 = 1.0;
        double r65816 = r65814 / r65815;
        double r65817 = sin(r65801);
        double r65818 = r65808 - r65810;
        double r65819 = r65810 + r65808;
        double r65820 = r65810 * r65819;
        double r65821 = r65820 + r65809;
        double r65822 = r65818 / r65821;
        double r65823 = r65817 / r65822;
        double r65824 = r65816 / r65823;
        double r65825 = 0.041666666666666664;
        double r65826 = 3.0;
        double r65827 = pow(r65801, r65826);
        double r65828 = r65825 * r65827;
        double r65829 = 0.004166666666666667;
        double r65830 = 5.0;
        double r65831 = pow(r65801, r65830);
        double r65832 = r65829 * r65831;
        double r65833 = 0.5;
        double r65834 = r65833 * r65801;
        double r65835 = r65832 + r65834;
        double r65836 = r65828 + r65835;
        double r65837 = r65807 ? r65824 : r65836;
        return r65837;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.024219913715803645 or 0.021299805520742916 < 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 *-un-lft-identity1.0

      \[\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.0

      \[\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.0

      \[\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}}}}\]

    if -0.024219913715803645 < x < 0.021299805520742916

    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)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.02421991371580364468818480361278488999233 \lor \neg \left(x \le 0.02129980552074291558217744579906138824299\right):\\ \;\;\;\;\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}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \end{array}\]

Reproduce

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

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

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