?

Average Error: 43.6 → 0.8
Time: 11.9s
Precision: binary64
Cost: 26752

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original43.6
Target0.3
Herbie0.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 43.6

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Taylor expanded in im around 0 0.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. Simplified0.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]0.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+ [=>]0.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 [=>]0.8

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

    *-commutative [=>]0.8

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

    associate-*l* [=>]0.8

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

    *-commutative [=>]0.8

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

    associate-*l* [=>]0.8

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

    *-commutative [<=]0.8

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

    distribute-lft-out [=>]0.8

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

    *-commutative [=>]0.8

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

    associate-*r* [=>]0.8

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

    *-commutative [=>]0.8

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

    associate-*r* [=>]0.8

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

    distribute-rgt-out [=>]0.8

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

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

Alternatives

Alternative 1
Error0.8
Cost20032
\[\sin re \cdot \left({im}^{5} \cdot -0.008333333333333333 + \left({im}^{3} \cdot -0.16666666666666666 - im\right)\right) \]
Alternative 2
Error1.0
Cost19840
\[{im}^{3} \cdot \left(\sin re \cdot -0.16666666666666666\right) - \sin re \cdot im \]
Alternative 3
Error1.0
Cost13312
\[\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right) \]
Alternative 4
Error1.4
Cost6656
\[\sin re \cdot \left(-im\right) \]
Alternative 5
Error32.0
Cost256
\[re \cdot \left(-im\right) \]
Alternative 6
Error46.9
Cost192
\[re \cdot im \]

Error

Reproduce?

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