Average Error: 29.5 → 0.6
Time: 55.5s
Precision: 64
Internal precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.859884253300168 \cdot 10^{-07}:\\ \;\;\;\;\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)\\ \mathbf{if}\;x \le 3.0084490837019413 \cdot 10^{-50}:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\sin x \cdot \sin x}{1 + \cos x}}{\sin x}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes.
  2. if x < -3.859884253300168e-07

    1. Initial program 1.3

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied add-log-exp 1.4

      \[\leadsto \color{blue}{\log \left(e^{\frac{1 - \cos x}{\sin x}}\right)}\]

    if -3.859884253300168e-07 < x < 3.0084490837019413e-50

    1. Initial program 60.3

      \[\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 3.0084490837019413e-50 < x

    1. Initial program 7.8

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

      \[\leadsto \frac{\color{blue}{\frac{1 \cdot 1 - \cos x \cdot \cos x}{1 + \cos x}}}{\sin x}\]
    4. Applied simplify 0.8

      \[\leadsto \frac{\frac{\color{blue}{\sin x \cdot \sin x}}{1 + \cos x}}{\sin x}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 55.5s) Debug log

Please include this information when filing a bug report:

herbie shell --seed '#(2329929097 3210370195 3111198779 2406363002 3511342718 2136436390)'
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 1

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

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