?

Average Accuracy: 31.9% → 98.6%
Time: 15.3s
Precision: binary64
Cost: 7104

?

\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
\[\sin re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right) \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (* (sin re) (* im (+ (* -0.16666666666666666 (* im im)) -1.0))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
	return sin(re) * (im * ((-0.16666666666666666 * (im * im)) + -1.0));
}
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 = sin(re) * (im * (((-0.16666666666666666d0) * (im * im)) + (-1.0d0)))
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 Math.sin(re) * (im * ((-0.16666666666666666 * (im * im)) + -1.0));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
def code(re, im):
	return math.sin(re) * (im * ((-0.16666666666666666 * (im * im)) + -1.0))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
end
function code(re, im)
	return Float64(sin(re) * Float64(im * Float64(Float64(-0.16666666666666666 * Float64(im * im)) + -1.0)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
end
function tmp = code(re, im)
	tmp = sin(re) * (im * ((-0.16666666666666666 * (im * im)) + -1.0));
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[Sin[re], $MachinePrecision] * N[(im * N[(N[(-0.16666666666666666 * N[(im * im), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\sin re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

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

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

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

    [Start]98.6

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

    mul-1-neg [=>]98.6

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

    unsub-neg [=>]98.6

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

    *-commutative [=>]98.6

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

    associate-*r* [=>]98.6

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

    *-commutative [=>]98.6

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

    distribute-rgt-out-- [=>]98.6

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

    *-commutative [=>]98.6

    \[ \sin re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right) \]
  4. Applied egg-rr98.6%

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

    [Start]98.6

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

    *-commutative [=>]98.6

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

    *-un-lft-identity [=>]98.6

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

    unpow3 [=>]98.6

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

    associate-*r* [=>]98.6

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

    distribute-rgt-out-- [=>]98.6

    \[ \sin re \cdot \color{blue}{\left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) - 1\right)\right)} \]
  5. Final simplification98.6%

    \[\leadsto \sin re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right) \]

Alternatives

Alternative 1
Accuracy98.0%
Cost6656
\[\sin re \cdot \left(-im\right) \]
Alternative 2
Accuracy51.3%
Cost576
\[\frac{re}{im \cdot 0.16666666666666666 + \frac{-1}{im}} \]
Alternative 3
Accuracy51.2%
Cost256
\[re \cdot \left(-im\right) \]
Alternative 4
Accuracy26.9%
Cost192
\[re \cdot im \]

Error

Reproduce?

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