?

Average Accuracy: 8.9% → 99.0%
Time: 15.1s
Precision: binary64
Cost: 26752

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.9%
Target99.6%
Herbie99.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 8.9%

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

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

    [Start]8.9

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

    *-commutative [=>]8.9

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

    associate-*l* [=>]8.9

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

    sub-neg [=>]8.9

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

    sub-neg [<=]8.9

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

    sub0-neg [=>]8.9

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

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(-1 \cdot \left(\cos re \cdot im\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right)\right)} \]
  4. Simplified99.0%

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

    [Start]99.0

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

    associate-+r+ [=>]99.0

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

    *-commutative [=>]99.0

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

    associate-*l* [=>]99.0

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

    *-commutative [=>]99.0

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

    associate-*l* [=>]99.0

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

    *-commutative [<=]99.0

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

    distribute-lft-out [=>]99.0

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

    +-commutative [=>]99.0

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

    *-commutative [=>]99.0

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

    associate-*l* [=>]99.0

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

    *-commutative [=>]99.0

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

    associate-*l* [=>]99.0

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

    distribute-lft-out [=>]99.0

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

    distribute-lft-out [=>]99.0

    \[ \color{blue}{\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 + -1 \cdot im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{5} \cdot -0.008333333333333333\right)\right)} \]
  5. Final simplification99.0%

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

Alternatives

Alternative 1
Accuracy98.9%
Cost20288
\[\cos re \cdot \left(0.5 \cdot \left(im \cdot -2 + \left({im}^{5} \cdot -0.016666666666666666 + {im}^{3} \cdot -0.3333333333333333\right)\right)\right) \]
Alternative 2
Accuracy98.9%
Cost20032
\[\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 + \left({im}^{5} \cdot -0.008333333333333333 - im\right)\right) \]
Alternative 3
Accuracy98.8%
Cost19840
\[{im}^{3} \cdot \left(\cos re \cdot -0.16666666666666666\right) - \cos re \cdot im \]
Alternative 4
Accuracy98.8%
Cost13632
\[\cos re \cdot \left(im \cdot \left(\left(\mathsf{fma}\left(-0.16666666666666666, im \cdot im, 1\right) + -1\right) + -1\right)\right) \]
Alternative 5
Accuracy98.8%
Cost7104
\[\cos re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right) \]
Alternative 6
Accuracy98.8%
Cost7104
\[\cos re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right)\right) - im\right) \]
Alternative 7
Accuracy98.4%
Cost6976
\[\frac{\cos re}{im \cdot 0.16666666666666666 + \frac{-1}{im}} \]
Alternative 8
Accuracy98.3%
Cost6656
\[im \cdot \left(-\cos re\right) \]
Alternative 9
Accuracy54.7%
Cost128
\[-im \]
Alternative 10
Accuracy3.9%
Cost64
\[-1.5 \]

Error

Reproduce?

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