Average Error: 31.2 → 0.7
Time: 1.2m
Precision: 64
Internal Precision: 2432
\[\frac{1 - \cos x}{\sin x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le -2.2245851660549705 \cdot 10^{-16}:\\ \;\;\;\;\frac{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \mathbf{if}\;\frac{1 - \cos x}{\sin x} \le 1.525723687674933 \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{e^{\log \left(1 - \cos x\right)}}{\sin x}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/ (- 1 (cos x)) (sin x)) < -2.2245851660549705e-16

    1. Initial program 1.6

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

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

    if -2.2245851660549705e-16 < (/ (- 1 (cos x)) (sin x)) < 1.525723687674933e-07

    1. Initial program 60.5

      \[\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 1.525723687674933e-07 < (/ (- 1 (cos x)) (sin x))

    1. Initial program 1.3

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

      \[\leadsto \frac{\color{blue}{e^{\log \left(1 - \cos x\right)}}}{\sin x}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 1.2m)Debug log

herbie shell --seed '#(212267722 3993171362 1093346726 3605783651 2106536041 3335990851)' 
(FPCore (x)
  :name "tanhf (example 3.4)"
  :herbie-expected 2

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

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