math.cos on complex, imaginary part

Percentage Accurate: 65.9% → 99.8%
Time: 8.5s
Alternatives: 10
Speedup: 2.8×

Specification

?
\[\begin{array}{l} \\ \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
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
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 65.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
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
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\end{array}

Alternative 1: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := 0.5 \cdot \sin re\\ \mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.02\right):\\ \;\;\;\;t_0 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* 0.5 (sin re))))
   (if (or (<= t_0 -100.0) (not (<= t_0 0.02)))
     (* t_0 t_1)
     (*
      t_1
      (+
       (* im -2.0)
       (+
        (* -0.3333333333333333 (pow im 3.0))
        (+
         (* -0.016666666666666666 (pow im 5.0))
         (* -0.0003968253968253968 (pow im 7.0)))))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = 0.5 * sin(re);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.02)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * pow(im, 3.0)) + ((-0.016666666666666666 * pow(im, 5.0)) + (-0.0003968253968253968 * pow(im, 7.0)))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-im) - exp(im)
    t_1 = 0.5d0 * sin(re)
    if ((t_0 <= (-100.0d0)) .or. (.not. (t_0 <= 0.02d0))) then
        tmp = t_0 * t_1
    else
        tmp = t_1 * ((im * (-2.0d0)) + (((-0.3333333333333333d0) * (im ** 3.0d0)) + (((-0.016666666666666666d0) * (im ** 5.0d0)) + ((-0.0003968253968253968d0) * (im ** 7.0d0)))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = 0.5 * Math.sin(re);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.02)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * Math.pow(im, 3.0)) + ((-0.016666666666666666 * Math.pow(im, 5.0)) + (-0.0003968253968253968 * Math.pow(im, 7.0)))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = 0.5 * math.sin(re)
	tmp = 0
	if (t_0 <= -100.0) or not (t_0 <= 0.02):
		tmp = t_0 * t_1
	else:
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * math.pow(im, 3.0)) + ((-0.016666666666666666 * math.pow(im, 5.0)) + (-0.0003968253968253968 * math.pow(im, 7.0)))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(0.5 * sin(re))
	tmp = 0.0
	if ((t_0 <= -100.0) || !(t_0 <= 0.02))
		tmp = Float64(t_0 * t_1);
	else
		tmp = Float64(t_1 * Float64(Float64(im * -2.0) + Float64(Float64(-0.3333333333333333 * (im ^ 3.0)) + Float64(Float64(-0.016666666666666666 * (im ^ 5.0)) + Float64(-0.0003968253968253968 * (im ^ 7.0))))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = 0.5 * sin(re);
	tmp = 0.0;
	if ((t_0 <= -100.0) || ~((t_0 <= 0.02)))
		tmp = t_0 * t_1;
	else
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * (im ^ 3.0)) + ((-0.016666666666666666 * (im ^ 5.0)) + (-0.0003968253968253968 * (im ^ 7.0)))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -100.0], N[Not[LessEqual[t$95$0, 0.02]], $MachinePrecision]], N[(t$95$0 * t$95$1), $MachinePrecision], N[(t$95$1 * N[(N[(im * -2.0), $MachinePrecision] + N[(N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0003968253968253968 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := 0.5 \cdot \sin re\\
\mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.02\right):\\
\;\;\;\;t_0 \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -100 or 0.0200000000000000004 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 100.0%

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

    if -100 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 0.0200000000000000004

    1. Initial program 40.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -100 \lor \neg \left(e^{-im} - e^{im} \leq 0.02\right):\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)\\ \end{array} \]

Alternative 2: 99.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ t_1 := 0.5 \cdot \sin re\\ \mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.02\right):\\ \;\;\;\;t_0 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))) (t_1 (* 0.5 (sin re))))
   (if (or (<= t_0 -100.0) (not (<= t_0 0.02)))
     (* t_0 t_1)
     (*
      t_1
      (+
       (* im -2.0)
       (+
        (* -0.3333333333333333 (pow im 3.0))
        (* -0.016666666666666666 (pow im 5.0))))))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double t_1 = 0.5 * sin(re);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.02)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * pow(im, 3.0)) + (-0.016666666666666666 * pow(im, 5.0))));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = exp(-im) - exp(im)
    t_1 = 0.5d0 * sin(re)
    if ((t_0 <= (-100.0d0)) .or. (.not. (t_0 <= 0.02d0))) then
        tmp = t_0 * t_1
    else
        tmp = t_1 * ((im * (-2.0d0)) + (((-0.3333333333333333d0) * (im ** 3.0d0)) + ((-0.016666666666666666d0) * (im ** 5.0d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double t_1 = 0.5 * Math.sin(re);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.02)) {
		tmp = t_0 * t_1;
	} else {
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * Math.pow(im, 3.0)) + (-0.016666666666666666 * Math.pow(im, 5.0))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	t_1 = 0.5 * math.sin(re)
	tmp = 0
	if (t_0 <= -100.0) or not (t_0 <= 0.02):
		tmp = t_0 * t_1
	else:
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * math.pow(im, 3.0)) + (-0.016666666666666666 * math.pow(im, 5.0))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	t_1 = Float64(0.5 * sin(re))
	tmp = 0.0
	if ((t_0 <= -100.0) || !(t_0 <= 0.02))
		tmp = Float64(t_0 * t_1);
	else
		tmp = Float64(t_1 * Float64(Float64(im * -2.0) + Float64(Float64(-0.3333333333333333 * (im ^ 3.0)) + Float64(-0.016666666666666666 * (im ^ 5.0)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	t_1 = 0.5 * sin(re);
	tmp = 0.0;
	if ((t_0 <= -100.0) || ~((t_0 <= 0.02)))
		tmp = t_0 * t_1;
	else
		tmp = t_1 * ((im * -2.0) + ((-0.3333333333333333 * (im ^ 3.0)) + (-0.016666666666666666 * (im ^ 5.0))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -100.0], N[Not[LessEqual[t$95$0, 0.02]], $MachinePrecision]], N[(t$95$0 * t$95$1), $MachinePrecision], N[(t$95$1 * N[(N[(im * -2.0), $MachinePrecision] + N[(N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
t_1 := 0.5 \cdot \sin re\\
\mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.02\right):\\
\;\;\;\;t_0 \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -100 or 0.0200000000000000004 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 100.0%

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

    if -100 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 0.0200000000000000004

    1. Initial program 40.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -100 \lor \neg \left(e^{-im} - e^{im} \leq 0.02\right):\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot -2 + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)\\ \end{array} \]

Alternative 3: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.0001\right):\\ \;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (or (<= t_0 -100.0) (not (<= t_0 0.0001)))
     (* t_0 (* 0.5 (sin re)))
     (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.0001)) {
		tmp = t_0 * (0.5 * sin(re));
	} else {
		tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
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 ((t_0 <= (-100.0d0)) .or. (.not. (t_0 <= 0.0001d0))) then
        tmp = t_0 * (0.5d0 * sin(re))
    else
        tmp = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_0 <= -100.0) || !(t_0 <= 0.0001)) {
		tmp = t_0 * (0.5 * Math.sin(re));
	} else {
		tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_0 <= -100.0) or not (t_0 <= 0.0001):
		tmp = t_0 * (0.5 * math.sin(re))
	else:
		tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_0 <= -100.0) || !(t_0 <= 0.0001))
		tmp = Float64(t_0 * Float64(0.5 * sin(re)));
	else
		tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_0 <= -100.0) || ~((t_0 <= 0.0001)))
		tmp = t_0 * (0.5 * sin(re));
	else
		tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -100.0], N[Not[LessEqual[t$95$0, 0.0001]], $MachinePrecision]], N[(t$95$0 * N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -100 \lor \neg \left(t_0 \leq 0.0001\right):\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\

\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -100 or 1.00000000000000005e-4 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 99.9%

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

    if -100 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 1.00000000000000005e-4

    1. Initial program 39.9%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)} \]
    3. Taylor expanded in im around 0 99.9%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    4. Step-by-step derivation
      1. +-commutative99.9%

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

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

        \[\leadsto \color{blue}{\left(\sin re \cdot {im}^{3}\right)} \cdot -0.16666666666666666 + -1 \cdot \left(im \cdot \sin re\right) \]
      4. associate-*r*99.9%

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

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

        \[\leadsto \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) + \left(-\color{blue}{\sin re \cdot im}\right) \]
      7. sub-neg99.9%

        \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) - \sin re \cdot im} \]
      8. distribute-lft-out--99.9%

        \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
    5. Simplified99.9%

      \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -100 \lor \neg \left(e^{-im} - e^{im} \leq 0.0001\right):\\ \;\;\;\;\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 4: 93.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{-im} - e^{im}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0.02\right):\\ \;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (- (exp (- im)) (exp im))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 0.02)))
     (* -0.0001984126984126984 (* (sin re) (pow im 7.0)))
     (* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
	double t_0 = exp(-im) - exp(im);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 0.02)) {
		tmp = -0.0001984126984126984 * (sin(re) * pow(im, 7.0));
	} else {
		tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(-im) - Math.exp(im);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 0.02)) {
		tmp = -0.0001984126984126984 * (Math.sin(re) * Math.pow(im, 7.0));
	} else {
		tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(-im) - math.exp(im)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 0.02):
		tmp = -0.0001984126984126984 * (math.sin(re) * math.pow(im, 7.0))
	else:
		tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
	return tmp
function code(re, im)
	t_0 = Float64(exp(Float64(-im)) - exp(im))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 0.02))
		tmp = Float64(-0.0001984126984126984 * Float64(sin(re) * (im ^ 7.0)));
	else
		tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(-im) - exp(im);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 0.02)))
		tmp = -0.0001984126984126984 * (sin(re) * (im ^ 7.0));
	else
		tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 0.02]], $MachinePrecision]], N[(-0.0001984126984126984 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 0.02\right):\\
\;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\

\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -inf.0 or 0.0200000000000000004 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)} \]
    3. Taylor expanded in im around inf 89.3%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot \sin re\right)} \]

    if -inf.0 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 0.0200000000000000004

    1. Initial program 41.2%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)} \]
    3. Taylor expanded in im around 0 98.9%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \sin re\right)} \]
    4. Step-by-step derivation
      1. +-commutative98.9%

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

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

        \[\leadsto \color{blue}{\left(\sin re \cdot {im}^{3}\right)} \cdot -0.16666666666666666 + -1 \cdot \left(im \cdot \sin re\right) \]
      4. associate-*r*98.9%

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

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

        \[\leadsto \sin re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) + \left(-\color{blue}{\sin re \cdot im}\right) \]
      7. sub-neg98.9%

        \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) - \sin re \cdot im} \]
      8. distribute-lft-out--98.9%

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

      \[\leadsto \color{blue}{\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq -\infty \lor \neg \left(e^{-im} - e^{im} \leq 0.02\right):\\ \;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\ \end{array} \]

Alternative 5: 93.1% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -4.1 \lor \neg \left(im \leq 4.1\right):\\ \;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -4.1) (not (<= im 4.1)))
   (* -0.0001984126984126984 (* (sin re) (pow im 7.0)))
   (* im (- (sin re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -4.1) || !(im <= 4.1)) {
		tmp = -0.0001984126984126984 * (sin(re) * pow(im, 7.0));
	} else {
		tmp = im * -sin(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-4.1d0)) .or. (.not. (im <= 4.1d0))) then
        tmp = (-0.0001984126984126984d0) * (sin(re) * (im ** 7.0d0))
    else
        tmp = im * -sin(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -4.1) || !(im <= 4.1)) {
		tmp = -0.0001984126984126984 * (Math.sin(re) * Math.pow(im, 7.0));
	} else {
		tmp = im * -Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -4.1) or not (im <= 4.1):
		tmp = -0.0001984126984126984 * (math.sin(re) * math.pow(im, 7.0))
	else:
		tmp = im * -math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -4.1) || !(im <= 4.1))
		tmp = Float64(-0.0001984126984126984 * Float64(sin(re) * (im ^ 7.0)));
	else
		tmp = Float64(im * Float64(-sin(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -4.1) || ~((im <= 4.1)))
		tmp = -0.0001984126984126984 * (sin(re) * (im ^ 7.0));
	else
		tmp = im * -sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -4.1], N[Not[LessEqual[im, 4.1]], $MachinePrecision]], N[(-0.0001984126984126984 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -4.1 \lor \neg \left(im \leq 4.1\right):\\
\;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -4.0999999999999996 or 4.0999999999999996 < im

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)} \]
    3. Taylor expanded in im around inf 88.7%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot \sin re\right)} \]

    if -4.0999999999999996 < im < 4.0999999999999996

    1. Initial program 40.8%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*98.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-198.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified98.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -4.1 \lor \neg \left(im \leq 4.1\right):\\ \;\;\;\;-0.0001984126984126984 \cdot \left(\sin re \cdot {im}^{7}\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \]

Alternative 6: 90.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \sin re \cdot \left({im}^{5} \cdot -0.008333333333333333 - im\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (sin re) (- (* (pow im 5.0) -0.008333333333333333) im)))
double code(double re, double im) {
	return sin(re) * ((pow(im, 5.0) * -0.008333333333333333) - im);
}
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)
end function
public static double code(double re, double im) {
	return Math.sin(re) * ((Math.pow(im, 5.0) * -0.008333333333333333) - im);
}
def code(re, im):
	return math.sin(re) * ((math.pow(im, 5.0) * -0.008333333333333333) - im)
function code(re, im)
	return Float64(sin(re) * Float64(Float64((im ^ 5.0) * -0.008333333333333333) - im))
end
function tmp = code(re, im)
	tmp = sin(re) * (((im ^ 5.0) * -0.008333333333333333) - im);
end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sin re \cdot \left({im}^{5} \cdot -0.008333333333333333 - im\right)
\end{array}
Derivation
  1. Initial program 69.5%

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

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + -0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
  3. Taylor expanded in im around inf 92.0%

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(-2 \cdot im + \color{blue}{-0.016666666666666666 \cdot {im}^{5}}\right) \]
  4. Taylor expanded in im around 0 92.0%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right) + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right)} \]
  5. Step-by-step derivation
    1. associate-*r*92.0%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right) \]
    2. neg-mul-192.0%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re + -0.008333333333333333 \cdot \left({im}^{5} \cdot \sin re\right) \]
    3. associate-*r*92.0%

      \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5}\right) \cdot \sin re} \]
    4. metadata-eval92.0%

      \[\leadsto \left(-im\right) \cdot \sin re + \left(\color{blue}{\left(0.5 \cdot -0.016666666666666666\right)} \cdot {im}^{5}\right) \cdot \sin re \]
    5. associate-*r*92.0%

      \[\leadsto \left(-im\right) \cdot \sin re + \color{blue}{\left(0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\right)} \cdot \sin re \]
    6. distribute-rgt-out92.0%

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + 0.5 \cdot \left(-0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
    7. associate-*r*92.0%

      \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{\left(0.5 \cdot -0.016666666666666666\right) \cdot {im}^{5}}\right) \]
    8. metadata-eval92.0%

      \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{-0.008333333333333333} \cdot {im}^{5}\right) \]
    9. *-commutative92.0%

      \[\leadsto \sin re \cdot \left(\left(-im\right) + \color{blue}{{im}^{5} \cdot -0.008333333333333333}\right) \]
  6. Simplified92.0%

    \[\leadsto \color{blue}{\sin re \cdot \left(\left(-im\right) + {im}^{5} \cdot -0.008333333333333333\right)} \]
  7. Taylor expanded in re around inf 92.0%

    \[\leadsto \color{blue}{\sin re \cdot \left(-0.008333333333333333 \cdot {im}^{5} - im\right)} \]
  8. Step-by-step derivation
    1. *-commutative92.0%

      \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} - im\right) \cdot \sin re} \]
  9. Simplified92.0%

    \[\leadsto \color{blue}{\left(-0.008333333333333333 \cdot {im}^{5} - im\right) \cdot \sin re} \]
  10. Final simplification92.0%

    \[\leadsto \sin re \cdot \left({im}^{5} \cdot -0.008333333333333333 - im\right) \]

Alternative 7: 82.9% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -7 \lor \neg \left(im \leq 5 \cdot 10^{+40}\right):\\ \;\;\;\;re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -7.0) (not (<= im 5e+40)))
   (* re (* (pow im 7.0) -0.0001984126984126984))
   (* im (- (sin re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -7.0) || !(im <= 5e+40)) {
		tmp = re * (pow(im, 7.0) * -0.0001984126984126984);
	} else {
		tmp = im * -sin(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-7.0d0)) .or. (.not. (im <= 5d+40))) then
        tmp = re * ((im ** 7.0d0) * (-0.0001984126984126984d0))
    else
        tmp = im * -sin(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -7.0) || !(im <= 5e+40)) {
		tmp = re * (Math.pow(im, 7.0) * -0.0001984126984126984);
	} else {
		tmp = im * -Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -7.0) or not (im <= 5e+40):
		tmp = re * (math.pow(im, 7.0) * -0.0001984126984126984)
	else:
		tmp = im * -math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -7.0) || !(im <= 5e+40))
		tmp = Float64(re * Float64((im ^ 7.0) * -0.0001984126984126984));
	else
		tmp = Float64(im * Float64(-sin(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -7.0) || ~((im <= 5e+40)))
		tmp = re * ((im ^ 7.0) * -0.0001984126984126984);
	else
		tmp = im * -sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -7.0], N[Not[LessEqual[im, 5e+40]], $MachinePrecision]], N[(re * N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -7 \lor \neg \left(im \leq 5 \cdot 10^{+40}\right):\\
\;\;\;\;re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -7 or 5.00000000000000003e40 < im

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(-2 \cdot im + \left(-0.3333333333333333 \cdot {im}^{3} + \left(-0.016666666666666666 \cdot {im}^{5} + -0.0003968253968253968 \cdot {im}^{7}\right)\right)\right)} \]
    3. Taylor expanded in im around inf 95.2%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot \sin re\right)} \]
    4. Taylor expanded in re around 0 73.3%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot \left({im}^{7} \cdot re\right)} \]
    5. Step-by-step derivation
      1. associate-*r*73.3%

        \[\leadsto \color{blue}{\left(-0.0001984126984126984 \cdot {im}^{7}\right) \cdot re} \]
      2. *-commutative73.3%

        \[\leadsto \color{blue}{\left({im}^{7} \cdot -0.0001984126984126984\right)} \cdot re \]
      3. *-commutative73.3%

        \[\leadsto \color{blue}{re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)} \]
    6. Simplified73.3%

      \[\leadsto \color{blue}{re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)} \]

    if -7 < im < 5.00000000000000003e40

    1. Initial program 44.6%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*92.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-192.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified92.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -7 \lor \neg \left(im \leq 5 \cdot 10^{+40}\right):\\ \;\;\;\;re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \]

Alternative 8: 57.6% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -2.75 \cdot 10^{+73} \lor \neg \left(im \leq 4.8 \cdot 10^{+48}\right):\\ \;\;\;\;im \cdot \left(-re\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im -2.75e+73) (not (<= im 4.8e+48)))
   (* im (- re))
   (* im (- (sin re)))))
double code(double re, double im) {
	double tmp;
	if ((im <= -2.75e+73) || !(im <= 4.8e+48)) {
		tmp = im * -re;
	} else {
		tmp = im * -sin(re);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= (-2.75d+73)) .or. (.not. (im <= 4.8d+48))) then
        tmp = im * -re
    else
        tmp = im * -sin(re)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= -2.75e+73) || !(im <= 4.8e+48)) {
		tmp = im * -re;
	} else {
		tmp = im * -Math.sin(re);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= -2.75e+73) or not (im <= 4.8e+48):
		tmp = im * -re
	else:
		tmp = im * -math.sin(re)
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= -2.75e+73) || !(im <= 4.8e+48))
		tmp = Float64(im * Float64(-re));
	else
		tmp = Float64(im * Float64(-sin(re)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= -2.75e+73) || ~((im <= 4.8e+48)))
		tmp = im * -re;
	else
		tmp = im * -sin(re);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, -2.75e+73], N[Not[LessEqual[im, 4.8e+48]], $MachinePrecision]], N[(im * (-re)), $MachinePrecision], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -2.75 \cdot 10^{+73} \lor \neg \left(im \leq 4.8 \cdot 10^{+48}\right):\\
\;\;\;\;im \cdot \left(-re\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < -2.7500000000000001e73 or 4.8000000000000002e48 < im

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*4.8%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-14.8%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified4.8%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
    5. Taylor expanded in re around 0 16.5%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot re\right)} \]
    6. Step-by-step derivation
      1. associate-*r*16.5%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot re} \]
      2. neg-mul-116.5%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot re \]
    7. Simplified16.5%

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

    if -2.7500000000000001e73 < im < 4.8000000000000002e48

    1. Initial program 48.9%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right)} \]
    3. Step-by-step derivation
      1. associate-*r*85.7%

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. neg-mul-185.7%

        \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
    4. Simplified85.7%

      \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification57.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq -2.75 \cdot 10^{+73} \lor \neg \left(im \leq 4.8 \cdot 10^{+48}\right):\\ \;\;\;\;im \cdot \left(-re\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \left(-\sin re\right)\\ \end{array} \]

Alternative 9: 33.7% accurate, 77.0× speedup?

\[\begin{array}{l} \\ im \cdot \left(-re\right) \end{array} \]
(FPCore (re im) :precision binary64 (* im (- re)))
double code(double re, double im) {
	return im * -re;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = im * -re
end function
public static double code(double re, double im) {
	return im * -re;
}
def code(re, im):
	return im * -re
function code(re, im)
	return Float64(im * Float64(-re))
end
function tmp = code(re, im)
	tmp = im * -re;
end
code[re_, im_] := N[(im * (-re)), $MachinePrecision]
\begin{array}{l}

\\
im \cdot \left(-re\right)
\end{array}
Derivation
  1. Initial program 69.5%

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

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \sin re\right)} \]
  3. Step-by-step derivation
    1. associate-*r*53.2%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
    2. neg-mul-153.2%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot \sin re \]
  4. Simplified53.2%

    \[\leadsto \color{blue}{\left(-im\right) \cdot \sin re} \]
  5. Taylor expanded in re around 0 38.9%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot re\right)} \]
  6. Step-by-step derivation
    1. associate-*r*38.9%

      \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot re} \]
    2. neg-mul-138.9%

      \[\leadsto \color{blue}{\left(-im\right)} \cdot re \]
  7. Simplified38.9%

    \[\leadsto \color{blue}{\left(-im\right) \cdot re} \]
  8. Final simplification38.9%

    \[\leadsto im \cdot \left(-re\right) \]

Alternative 10: 15.7% accurate, 308.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
	return 0.0;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 0.0d0
end function
public static double code(double re, double im) {
	return 0.0;
}
def code(re, im):
	return 0.0
function code(re, im)
	return 0.0
end
function tmp = code(re, im)
	tmp = 0.0;
end
code[re_, im_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 69.5%

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

    \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
  3. Step-by-step derivation
    1. associate-*r*56.2%

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    2. *-commutative56.2%

      \[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)} \]
  4. Simplified56.2%

    \[\leadsto \color{blue}{\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)} \]
  5. Step-by-step derivation
    1. expm1-log1p-u39.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)\right)} \]
    2. expm1-udef37.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(e^{-im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1} \]
    3. add-sqr-sqrt20.3%

      \[\leadsto e^{\mathsf{log1p}\left(\left(e^{\color{blue}{\sqrt{-im} \cdot \sqrt{-im}}} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1 \]
    4. sqrt-unprod30.3%

      \[\leadsto e^{\mathsf{log1p}\left(\left(e^{\color{blue}{\sqrt{\left(-im\right) \cdot \left(-im\right)}}} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1 \]
    5. sqr-neg30.3%

      \[\leadsto e^{\mathsf{log1p}\left(\left(e^{\sqrt{\color{blue}{im \cdot im}}} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1 \]
    6. sqrt-unprod10.0%

      \[\leadsto e^{\mathsf{log1p}\left(\left(e^{\color{blue}{\sqrt{im} \cdot \sqrt{im}}} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1 \]
    7. add-sqr-sqrt19.7%

      \[\leadsto e^{\mathsf{log1p}\left(\left(e^{\color{blue}{im}} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1 \]
  6. Applied egg-rr19.7%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\left(e^{im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)} - 1} \]
  7. Step-by-step derivation
    1. expm1-def19.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(e^{im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)\right)\right)} \]
    2. expm1-log1p19.7%

      \[\leadsto \color{blue}{\left(e^{im} - e^{im}\right) \cdot \left(0.5 \cdot re\right)} \]
    3. +-inverses20.0%

      \[\leadsto \color{blue}{0} \cdot \left(0.5 \cdot re\right) \]
    4. mul0-lft20.0%

      \[\leadsto \color{blue}{0} \]
  8. Simplified20.0%

    \[\leadsto \color{blue}{0} \]
  9. Final simplification20.0%

    \[\leadsto 0 \]

Developer target: 99.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (re im)
 :precision binary64
 (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)))))
double code(double re, double im) {
	double tmp;
	if (fabs(im) < 1.0) {
		tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	} else {
		tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (abs(im) < 1.0d0) then
        tmp = -(sin(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
    else
        tmp = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (Math.abs(im) < 1.0) {
		tmp = -(Math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	} else {
		tmp = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if math.fabs(im) < 1.0:
		tmp = -(math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)))
	else:
		tmp = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
	return tmp
function code(re, im)
	tmp = 0.0
	if (abs(im) < 1.0)
		tmp = Float64(-Float64(sin(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im))));
	else
		tmp = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (abs(im) < 1.0)
		tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
	else
		tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Sin[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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}
\end{array}

Reproduce

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