Average Error: 58.6 → 0.2
Time: 18.7s
Precision: 64
Internal precision: 1408
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
⬇
\[\begin{array}{l}
\mathbf{if}\;im \le 1.9183430624335127:\\
\;\;\;\;\left(-\left(\frac{1}{60} \cdot {im}^{5} + \left(2 \cdot im + \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)\\
\mathbf{else}:\\
\;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)\\
\end{array}\]
Target
| Original | 58.6 |
| Comparison | 5.4 |
| Herbie | 0.2 |
\[ \begin{array}{l}
\mathbf{if}\;\left|im\right| \lt 1:\\
\;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\end{array} \]
Derivation
- Split input into 2 regimes.
-
if im < 1.9183430624335127
Initial program 58.8
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
Applied simplify 58.8
\[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)}\]
Applied taylor 0.2
\[\leadsto \left(-\left(\frac{1}{60} \cdot {im}^{5} + \left(2 \cdot im + \frac{1}{3} \cdot {im}^{3}\right)\right)\right) \cdot \left(0.5 \cdot \cos re\right)\]
Taylor expanded around 0 0.2
\[\leadsto \color{blue}{\left(-\left(\frac{1}{60} \cdot {im}^{5} + \left(2 \cdot im + \frac{1}{3} \cdot {im}^{3}\right)\right)\right)} \cdot \left(0.5 \cdot \cos re\right)\]
if 1.9183430624335127 < im
Initial program 0.1
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
Applied simplify 0.1
\[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \cos re\right)}\]
- Recombined 2 regimes into one program.
- Removed slow pow expressions
Runtime
Please include this information when filing a bug report:
herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:target
(if (< (fabs im) 1) (- (* (cos re) (+ (+ im (* (* (* 1/6 im) im) im)) (* (* (* (* (* 1/120 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))
(* (* 0.5 (cos re)) (- (exp (- 0 im)) (exp im))))