?

Average Accuracy: 9.7% → 98.0%
Time: 10.5s
Precision: binary64
Cost: 6656

?

\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
\[im \cdot \left(-\cos re\right) \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im) :precision binary64 (* im (- (cos re))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
double code(double re, double im) {
	return im * -cos(re);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = im * -cos(re)
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
public static double code(double re, double im) {
	return im * -Math.cos(re);
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
def code(re, im):
	return im * -math.cos(re)
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function code(re, im)
	return Float64(im * Float64(-cos(re)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
function tmp = code(re, im)
	tmp = im * -cos(re);
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
im \cdot \left(-\cos re\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.7%
Target99.6%
Herbie98.0%
\[\begin{array}{l} \mathbf{if}\;\left|im\right| < 1:\\ \;\;\;\;-\cos 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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \end{array} \]

Derivation?

  1. Initial program 9.7%

    \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
  2. Simplified9.7%

    \[\leadsto \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{-im} - e^{im}\right)\right)} \]
    Proof

    [Start]9.7

    \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]

    *-commutative [=>]9.7

    \[ \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]

    associate-*l* [=>]9.7

    \[ \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{0 - im} - e^{im}\right)\right)} \]

    sub-neg [=>]9.7

    \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right) \]

    sub-neg [<=]9.7

    \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} - e^{im}\right)}\right) \]

    sub0-neg [=>]9.7

    \[ \cos re \cdot \left(0.5 \cdot \left(e^{\color{blue}{-im}} - e^{im}\right)\right) \]
  3. Taylor expanded in im around 0 98.0%

    \[\leadsto \color{blue}{-1 \cdot \left(\cos re \cdot im\right)} \]
  4. Simplified98.0%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \cos re} \]
    Proof

    [Start]98.0

    \[ -1 \cdot \left(\cos re \cdot im\right) \]

    *-commutative [=>]98.0

    \[ -1 \cdot \color{blue}{\left(im \cdot \cos re\right)} \]

    associate-*r* [=>]98.0

    \[ \color{blue}{\left(-1 \cdot im\right) \cdot \cos re} \]

    mul-1-neg [=>]98.0

    \[ \color{blue}{\left(-im\right)} \cdot \cos re \]
  5. Final simplification98.0%

    \[\leadsto im \cdot \left(-\cos re\right) \]

Alternatives

Alternative 1
Accuracy59.7%
Cost7364
\[\begin{array}{l} \mathbf{if}\;\cos re \leq -0.002:\\ \;\;\;\;im\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(im \cdot -2 + \left(im \cdot im\right) \cdot \left(im \cdot -0.3333333333333333\right)\right)\\ \end{array} \]
Alternative 2
Accuracy55.1%
Cost128
\[-im \]
Alternative 3
Accuracy8.2%
Cost64
\[im \]

Error

Reproduce?

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

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

  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))