Average Error: 30.2 → 0.5
Time: 50.5s
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.023971988296824055:\\ \;\;\;\;\left(1 - \cos x\right) \cdot \frac{1}{\sin x}\\ \mathbf{if}\;x \le 2.1644985647405667 \cdot 10^{-07}:\\ \;\;\;\;\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

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

Derivation

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

    1. Initial program 1.0

      \[\frac{1 - \cos x}{\sin x}\]
    2. Using strategy rm
    3. Applied div-inv1.0

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

    if -0.023971988296824055 < x < 2.1644985647405667e-07

    1. Initial program 60.1

      \[\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 2.1644985647405667e-07 < x

    1. Initial program 1.3

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

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

      \[\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: 50.5s)Debug logProfile

herbie shell --seed '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)' 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 1

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

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