Average Error: 43.3 → 0.9
Time: 30.4s
Precision: 64
Internal Precision: 1408
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
\[\left(-\sin re\right) \cdot (\left(im \cdot 0.16666666666666666\right) \cdot \left(im \cdot im\right) + \left(im \cdot 1.0\right))_*\]

Error

Bits error versus re

Bits error versus im

Target

Original43.3
Target0.3
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;\left|im\right| \lt 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(\frac{1}{6} \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(\frac{1}{120} \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Initial program 43.3

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\]
  2. Taylor expanded around 0 0.8

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-\left(\frac{1}{60} \cdot {im}^{5} + \left(2 \cdot im + \frac{1}{3} \cdot {im}^{3}\right)\right)\right)}\]
  3. Applied simplify0.8

    \[\leadsto \color{blue}{\left(\left(-0.5\right) \cdot \sin re\right) \cdot (im \cdot \left((\left(\frac{1}{3} \cdot im\right) \cdot im + 2)_*\right) + \left({im}^{5} \cdot \frac{1}{60}\right))_*}\]
  4. Taylor expanded around inf 0.9

    \[\leadsto \color{blue}{-\left(1.0 \cdot \left(\sin re \cdot im\right) + 0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\right)}\]
  5. Applied simplify0.9

    \[\leadsto \color{blue}{\left(-\sin re\right) \cdot (\left(im \cdot 0.16666666666666666\right) \cdot \left(im \cdot im\right) + \left(im \cdot 1.0\right))_*}\]

Runtime

Time bar (total: 30.4s)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' +o rules:numerics
(FPCore (re im)
  :name "math.cos on complex, imaginary part"

  :herbie-target
  (if (< (fabs im) 1) (- (* (sin re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

  (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))