Average Error: 30.0 → 0.5
Time: 2.2m
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.024894411913591076:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \mathbf{if}\;x \le 0.023314860336167698:\\ \;\;\;\;\frac{1}{24} \cdot {x}^{3} + \left(\frac{1}{240} \cdot {x}^{5} + \frac{1}{2} \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -0.024894411913591076 or 0.023314860336167698 < x

    1. Initial program 0.9

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

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

    if -0.024894411913591076 < x < 0.023314860336167698

    1. Initial program 59.7

      \[\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. Removed slow pow expressions.

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed '#(1063154770 1824007522 645063331 41291047 494775821 1237684644)' 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 1

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

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