?

Average Accuracy: 9.2% → 99.3%
Time: 14.0s
Precision: binary64
Cost: 40068

?

\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
\[\begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;\left(\cos re \cdot 0.5\right) \cdot t_0 \leq -0.005:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (<= (* (* (cos re) 0.5) t_0) -0.005)
     (* (cos re) (* 0.5 t_0))
     (*
      (cos re)
      (*
       0.5
       (+
        (* im -2.0)
        (+
         (* (pow im 5.0) -0.016666666666666666)
         (* (pow im 3.0) -0.3333333333333333))))))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if (((cos(re) * 0.5) * t_0) <= -0.005) {
		tmp = cos(re) * (0.5 * t_0);
	} else {
		tmp = cos(re) * (0.5 * ((im * -2.0) + ((pow(im, 5.0) * -0.016666666666666666) + (pow(im, 3.0) * -0.3333333333333333))));
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = exp(-im) - exp(im)
    if (((cos(re) * 0.5d0) * t_0) <= (-0.005d0)) then
        tmp = cos(re) * (0.5d0 * t_0)
    else
        tmp = cos(re) * (0.5d0 * ((im * (-2.0d0)) + (((im ** 5.0d0) * (-0.016666666666666666d0)) + ((im ** 3.0d0) * (-0.3333333333333333d0)))))
    end if
    code = tmp
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) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if (((Math.cos(re) * 0.5) * t_0) <= -0.005) {
		tmp = Math.cos(re) * (0.5 * t_0);
	} else {
		tmp = Math.cos(re) * (0.5 * ((im * -2.0) + ((Math.pow(im, 5.0) * -0.016666666666666666) + (Math.pow(im, 3.0) * -0.3333333333333333))));
	}
	return tmp;
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if ((math.cos(re) * 0.5) * t_0) <= -0.005:
		tmp = math.cos(re) * (0.5 * t_0)
	else:
		tmp = math.cos(re) * (0.5 * ((im * -2.0) + ((math.pow(im, 5.0) * -0.016666666666666666) + (math.pow(im, 3.0) * -0.3333333333333333))))
	return tmp
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if (Float64(Float64(cos(re) * 0.5) * t_0) <= -0.005)
		tmp = Float64(cos(re) * Float64(0.5 * t_0));
	else
		tmp = Float64(cos(re) * Float64(0.5 * Float64(Float64(im * -2.0) + Float64(Float64((im ^ 5.0) * -0.016666666666666666) + Float64((im ^ 3.0) * -0.3333333333333333)))));
	end
	return tmp
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if (((cos(re) * 0.5) * t_0) <= -0.005)
		tmp = cos(re) * (0.5 * t_0);
	else
		tmp = cos(re) * (0.5 * ((im * -2.0) + (((im ^ 5.0) * -0.016666666666666666) + ((im ^ 3.0) * -0.3333333333333333))));
	end
	tmp_2 = tmp;
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_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * t$95$0), $MachinePrecision], -0.005], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(N[(im * -2.0), $MachinePrecision] + N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.016666666666666666), $MachinePrecision] + N[(N[Power[im, 3.0], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;\left(\cos re \cdot 0.5\right) \cdot t_0 \leq -0.005:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot t_0\right)\\

\mathbf{else}:\\
\;\;\;\;\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)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.2%
Target99.6%
Herbie99.3%
\[\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. Split input into 2 regimes
  2. if (*.f64 (*.f64 1/2 (cos.f64 re)) (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))) < -0.0050000000000000001

    1. Initial program 98.3%

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

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

      [Start]98.3

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

      *-commutative [=>]98.3

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

      associate-*l* [=>]98.3

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

      sub-neg [=>]98.3

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

      sub-neg [<=]98.3

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

      sub0-neg [=>]98.3

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

    if -0.0050000000000000001 < (*.f64 (*.f64 1/2 (cos.f64 re)) (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)))

    1. Initial program 8.6%

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

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

      [Start]8.6

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

      *-commutative [=>]8.6

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

      associate-*l* [=>]8.6

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

      sub-neg [=>]8.6

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

      sub-neg [<=]8.6

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

      sub0-neg [=>]8.6

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

      \[\leadsto \cos re \cdot \left(0.5 \cdot \color{blue}{\left(-2 \cdot im + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\cos re \cdot 0.5\right) \cdot \left(e^{-im} - e^{im}\right) \leq -0.005:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot \left(e^{-im} - e^{im}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.2%
Cost39492
\[\begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;\left(\cos re \cdot 0.5\right) \cdot t_0 \leq -0.001:\\ \;\;\;\;\cos re \cdot \left(0.5 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-2 + -0.3333333333333333 \cdot \left(im \cdot im\right)\right)\right)\right)\\ \end{array} \]
Alternative 2
Accuracy99.1%
Cost33280
\[\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right) + \cos re \cdot \left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right) \]
Alternative 3
Accuracy99.1%
Cost27008
\[0.5 \cdot \left(\cos re \cdot \left(im \cdot -2 + \left({im}^{7} \cdot -0.0003968253968253968 + \left({im}^{5} \cdot -0.016666666666666666 + {im}^{3} \cdot -0.3333333333333333\right)\right)\right)\right) \]
Alternative 4
Accuracy98.8%
Cost7232
\[0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-2 + -0.3333333333333333 \cdot \left(im \cdot im\right)\right)\right)\right) \]
Alternative 5
Accuracy98.2%
Cost6656
\[im \cdot \left(-\cos re\right) \]
Alternative 6
Accuracy54.9%
Cost128
\[-im \]

Error

Reproduce?

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