?

Average Accuracy: 31.3% → 98.8%
Time: 16.6s
Precision: binary64
Cost: 45824

?

\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
\[\mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, {im}^{7} \cdot -0.0001984126984126984\right)\right) \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (fma
  (- (* (pow im 5.0) -0.008333333333333333) im)
  (sin re)
  (*
   (sin re)
   (fma
    (pow im 3.0)
    -0.16666666666666666
    (* (pow im 7.0) -0.0001984126984126984)))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
	return fma(((pow(im, 5.0) * -0.008333333333333333) - im), sin(re), (sin(re) * fma(pow(im, 3.0), -0.16666666666666666, (pow(im, 7.0) * -0.0001984126984126984))));
}
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
end
function code(re, im)
	return fma(Float64(Float64((im ^ 5.0) * -0.008333333333333333) - im), sin(re), Float64(sin(re) * fma((im ^ 3.0), -0.16666666666666666, Float64((im ^ 7.0) * -0.0001984126984126984))))
end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[(N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] - im), $MachinePrecision] * N[Sin[re], $MachinePrecision] + N[(N[Sin[re], $MachinePrecision] * N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666 + N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, {im}^{7} \cdot -0.0001984126984126984\right)\right)

Error?

Target

Original31.3%
Target99.5%
Herbie98.8%
\[\begin{array}{l} \mathbf{if}\;\left|im\right| < 1:\\ \;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \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 31.3%

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

    \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right) + \left(-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right)\right)} \]
  3. Simplified98.8%

    \[\leadsto \color{blue}{\sin re \cdot \left(\left({im}^{5} \cdot -0.008333333333333333 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right)} \]
    Proof

    [Start]98.8

    \[ -0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right) + \left(-0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right)\right) \]

    associate-+r+ [=>]98.8

    \[ \color{blue}{\left(-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right) + -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right)} \]

    *-commutative [=>]98.8

    \[ \left(\color{blue}{\left(\sin re \cdot {im}^{7}\right) \cdot -0.0001984126984126984} + -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    associate-*l* [=>]98.8

    \[ \left(\color{blue}{\sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)} + -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    *-commutative [=>]98.8

    \[ \left(\sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right) + \color{blue}{\left(\sin re \cdot {im}^{3}\right) \cdot -0.16666666666666666}\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    associate-*l* [=>]98.8

    \[ \left(\sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right) + \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666\right)}\right) + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    distribute-lft-out [=>]98.8

    \[ \color{blue}{\sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)} + \left(-0.008333333333333333 \cdot \left(\sin re \cdot {im}^{5}\right) + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    *-commutative [=>]98.8

    \[ \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \left(-0.008333333333333333 \cdot \color{blue}{\left({im}^{5} \cdot \sin re\right)} + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    associate-*r* [=>]98.8

    \[ \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\color{blue}{\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re} + -1 \cdot \left(\sin re \cdot im\right)\right) \]

    *-commutative [=>]98.8

    \[ \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re + -1 \cdot \color{blue}{\left(im \cdot \sin re\right)}\right) \]

    associate-*r* [=>]98.8

    \[ \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re + \color{blue}{\left(-1 \cdot im\right) \cdot \sin re}\right) \]

    distribute-rgt-out [=>]98.8

    \[ \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\sin re \cdot \left(-0.008333333333333333 \cdot {im}^{5} + -1 \cdot im\right)} \]

    distribute-lft-out [=>]98.8

    \[ \color{blue}{\sin re \cdot \left(\left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) + \left(-0.008333333333333333 \cdot {im}^{5} + -1 \cdot im\right)\right)} \]
  4. Applied egg-rr98.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, {im}^{7} \cdot -0.0001984126984126984\right)\right)} \]
    Proof

    [Start]98.8

    \[ \sin re \cdot \left(\left({im}^{5} \cdot -0.008333333333333333 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right) \]

    distribute-lft-in [=>]98.8

    \[ \color{blue}{\sin re \cdot \left({im}^{5} \cdot -0.008333333333333333 - im\right) + \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)} \]

    *-commutative [=>]98.8

    \[ \color{blue}{\left({im}^{5} \cdot -0.008333333333333333 - im\right) \cdot \sin re} + \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right) \]

    fma-def [=>]98.8

    \[ \color{blue}{\mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right)} \]

    +-commutative [=>]98.8

    \[ \mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \color{blue}{\left({im}^{3} \cdot -0.16666666666666666 + {im}^{7} \cdot -0.0001984126984126984\right)}\right) \]

    fma-def [=>]98.8

    \[ \mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \color{blue}{\mathsf{fma}\left({im}^{3}, -0.16666666666666666, {im}^{7} \cdot -0.0001984126984126984\right)}\right) \]
  5. Final simplification98.8%

    \[\leadsto \mathsf{fma}\left({im}^{5} \cdot -0.008333333333333333 - im, \sin re, \sin re \cdot \mathsf{fma}\left({im}^{3}, -0.16666666666666666, {im}^{7} \cdot -0.0001984126984126984\right)\right) \]

Alternatives

Alternative 1
Accuracy98.8%
Cost26752
\[\sin re \cdot \left(\left({im}^{5} \cdot -0.008333333333333333 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{3} \cdot -0.16666666666666666\right)\right) \]
Alternative 2
Accuracy98.5%
Cost13504
\[im \cdot \left(\left(\sin re \cdot -0.16666666666666666\right) \cdot \left(im \cdot im\right) - \sin re\right) \]
Alternative 3
Accuracy98.5%
Cost7104
\[\sin re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right) \]
Alternative 4
Accuracy98.5%
Cost7104
\[\sin re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right)\right) - im\right) \]
Alternative 5
Accuracy98.0%
Cost6656
\[\sin re \cdot \left(-im\right) \]
Alternative 6
Accuracy50.2%
Cost704
\[re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right) \]
Alternative 7
Accuracy49.9%
Cost256
\[im \cdot \left(-re\right) \]
Alternative 8
Accuracy3.6%
Cost64
\[-3 \]
Alternative 9
Accuracy3.6%
Cost64
\[-1 \]
Alternative 10
Accuracy27.5%
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023137 
(FPCore (re im)
  :name "math.cos on complex, imaginary part"
  :precision binary64

  :herbie-target
  (if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))

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