?

Average Error: 58.0 → 0.8
Time: 15.2s
Precision: binary64
Cost: 20032

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.0
Target0.3
Herbie0.8
\[\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 58.0

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

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

    [Start]58.0

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

    rational.json-simplify-13 [=>]58.0

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

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(-1 \cdot \left(\cos re \cdot im\right) + -0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right)\right)} \]
  4. Simplified0.8

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

    [Start]0.8

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

    rational.json-simplify-41 [=>]0.8

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

    rational.json-simplify-1 [=>]0.8

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

    rational.json-simplify-43 [=>]0.8

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

    rational.json-simplify-43 [=>]0.8

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

    rational.json-simplify-2 [=>]0.8

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

    rational.json-simplify-51 [=>]0.8

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

    rational.json-simplify-43 [=>]0.8

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

    rational.json-simplify-8 [<=]0.8

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

    rational.json-simplify-2 [=>]0.8

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

    rational.json-simplify-51 [=>]0.8

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

    rational.json-simplify-1 [=>]0.8

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

    \[\leadsto \color{blue}{\left(\left(-0.008333333333333333 \cdot {im}^{5} + -0.16666666666666666 \cdot {im}^{3}\right) - im\right) \cdot \cos re} \]
  6. Final simplification0.8

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

Alternatives

Alternative 1
Error0.9
Cost19904
\[\left(-im\right) \cdot \cos re + {im}^{3} \cdot \left(-0.16666666666666666 \cdot \cos re\right) \]
Alternative 2
Error0.9
Cost13312
\[\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re \]
Alternative 3
Error1.3
Cost6656
\[\left(-im\right) \cdot \cos re \]
Alternative 4
Error28.5
Cost128
\[-im \]

Error

Reproduce?

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