?

Average Accuracy: 31.2% → 98.7%
Time: 11.5s
Precision: binary64
Cost: 20032

?

\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
\[\left(\left(-0.008333333333333333 \cdot {im}^{5} + -0.16666666666666666 \cdot {im}^{3}\right) - im\right) \cdot \sin re \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (*
  (-
   (+
    (* -0.008333333333333333 (pow im 5.0))
    (* -0.16666666666666666 (pow im 3.0)))
   im)
  (sin re)))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
	return (((-0.008333333333333333 * pow(im, 5.0)) + (-0.16666666666666666 * pow(im, 3.0))) - im) * sin(re);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
end function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = ((((-0.008333333333333333d0) * (im ** 5.0d0)) + ((-0.16666666666666666d0) * (im ** 3.0d0))) - im) * sin(re)
end function
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
public static double code(double re, double im) {
	return (((-0.008333333333333333 * Math.pow(im, 5.0)) + (-0.16666666666666666 * Math.pow(im, 3.0))) - im) * Math.sin(re);
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
def code(re, im):
	return (((-0.008333333333333333 * math.pow(im, 5.0)) + (-0.16666666666666666 * math.pow(im, 3.0))) - im) * math.sin(re)
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
end
function code(re, im)
	return Float64(Float64(Float64(Float64(-0.008333333333333333 * (im ^ 5.0)) + Float64(-0.16666666666666666 * (im ^ 3.0))) - im) * sin(re))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
end
function tmp = code(re, im)
	tmp = (((-0.008333333333333333 * (im ^ 5.0)) + (-0.16666666666666666 * (im ^ 3.0))) - im) * sin(re);
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[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision] * N[Sin[re], $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left(\left(-0.008333333333333333 \cdot {im}^{5} + -0.16666666666666666 \cdot {im}^{3}\right) - im\right) \cdot \sin re

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.2%
Target99.6%
Herbie98.7%
\[\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.2%

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

    \[\leadsto \color{blue}{-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)} \]
  3. Simplified98.7%

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

    [Start]98.7

    \[ -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) \]

    +-commutative [=>]98.7

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

    associate-+r+ [=>]98.7

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

    +-commutative [=>]98.7

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

    mul-1-neg [=>]98.7

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

    *-commutative [=>]98.7

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

    distribute-lft-neg-in [=>]98.7

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

    *-commutative [=>]98.7

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

    associate-*r* [=>]98.7

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

    distribute-rgt-out [=>]98.7

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

    associate-*r* [=>]98.7

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

    *-commutative [=>]98.7

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

    associate-*l* [=>]98.7

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

    distribute-lft-out [=>]98.7

    \[ \color{blue}{\sin re \cdot \left(\left(\left(-im\right) + -0.16666666666666666 \cdot {im}^{3}\right) + -0.008333333333333333 \cdot {im}^{5}\right)} \]
  4. Taylor expanded in re around inf 98.7%

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

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

Alternatives

Alternative 1
Accuracy98.7%
Cost20032
\[\sin re \cdot \left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\right) \]
Alternative 2
Accuracy98.5%
Cost13312
\[\sin re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right) \]
Alternative 3
Accuracy98.2%
Cost6976
\[\frac{\sin re}{im \cdot 0.16666666666666666 + \frac{-1}{im}} \]
Alternative 4
Accuracy98.0%
Cost6656
\[im \cdot \left(-\sin re\right) \]
Alternative 5
Accuracy49.4%
Cost256
\[im \cdot \left(-re\right) \]
Alternative 6
Accuracy3.6%
Cost64
\[-0.25 \]
Alternative 7
Accuracy27.3%
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023151 
(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))))