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

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

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

\end{array}
double f(double x) {
        double r4117657 = 1.0;
        double r4117658 = x;
        double r4117659 = cos(r4117658);
        double r4117660 = r4117657 - r4117659;
        double r4117661 = sin(r4117658);
        double r4117662 = r4117660 / r4117661;
        return r4117662;
}

double f(double x) {
        double r4117663 = x;
        double r4117664 = -0.0230098474062637;
        bool r4117665 = r4117663 <= r4117664;
        double r4117666 = 1.0;
        double r4117667 = r4117666 * r4117666;
        double r4117668 = r4117666 * r4117667;
        double r4117669 = r4117663 + r4117663;
        double r4117670 = cos(r4117669);
        double r4117671 = 1.0;
        double r4117672 = r4117670 + r4117671;
        double r4117673 = 2.0;
        double r4117674 = r4117672 / r4117673;
        double r4117675 = cos(r4117663);
        double r4117676 = r4117674 * r4117675;
        double r4117677 = r4117668 - r4117676;
        double r4117678 = r4117675 * r4117675;
        double r4117679 = r4117675 * r4117666;
        double r4117680 = r4117678 + r4117679;
        double r4117681 = r4117680 + r4117667;
        double r4117682 = r4117677 / r4117681;
        double r4117683 = sin(r4117663);
        double r4117684 = r4117682 / r4117683;
        double r4117685 = 0.015436630540337124;
        bool r4117686 = r4117663 <= r4117685;
        double r4117687 = 0.041666666666666664;
        double r4117688 = r4117663 * r4117663;
        double r4117689 = r4117687 * r4117688;
        double r4117690 = r4117689 * r4117663;
        double r4117691 = 0.5;
        double r4117692 = r4117663 * r4117691;
        double r4117693 = r4117690 + r4117692;
        double r4117694 = 0.004166666666666667;
        double r4117695 = 5.0;
        double r4117696 = pow(r4117663, r4117695);
        double r4117697 = r4117694 * r4117696;
        double r4117698 = r4117693 + r4117697;
        double r4117699 = r4117686 ? r4117698 : r4117684;
        double r4117700 = r4117665 ? r4117684 : r4117699;
        return r4117700;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.0230098474062637 or 0.015436630540337124 < 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{\color{blue}{1 \cdot \left(1 \cdot 1\right) - \left(\cos x \cdot \cos x\right) \cdot \cos x}}{1 \cdot 1 + \left(\cos x \cdot \cos x + 1 \cdot \cos x\right)}}{\sin x}\]
    5. Using strategy rm
    6. Applied cos-mult1.0

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

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

    if -0.0230098474062637 < x < 0.015436630540337124

    1. Initial program 59.9

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

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

      \[\leadsto \color{blue}{\frac{1}{240} \cdot {x}^{5} + x \cdot \left(\frac{1}{2} + \frac{1}{24} \cdot \left(x \cdot x\right)\right)}\]
    4. Using strategy rm
    5. Applied distribute-lft-in0.0

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

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

Reproduce

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

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

  (/ (- 1.0 (cos x)) (sin x)))