math.sin on complex, imaginary part

Percentage Accurate: 54.4% → 99.9%
Time: 10.6s
Alternatives: 9
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(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));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(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]
\begin{array}{l}

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

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 9 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: 54.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(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));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(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]
\begin{array}{l}

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

Alternative 1: 99.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \left(\left(\left(-2\right) \cdot \sinh im\right) \cdot \cos re\right) \cdot 0.5 \end{array} \]
(FPCore (re im) :precision binary64 (* (* (* (- 2.0) (sinh im)) (cos re)) 0.5))
double code(double re, double im) {
	return ((-2.0 * sinh(im)) * cos(re)) * 0.5;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = ((-2.0d0 * sinh(im)) * cos(re)) * 0.5d0
end function
public static double code(double re, double im) {
	return ((-2.0 * Math.sinh(im)) * Math.cos(re)) * 0.5;
}
def code(re, im):
	return ((-2.0 * math.sinh(im)) * math.cos(re)) * 0.5
function code(re, im)
	return Float64(Float64(Float64(Float64(-2.0) * sinh(im)) * cos(re)) * 0.5)
end
function tmp = code(re, im)
	tmp = ((-2.0 * sinh(im)) * cos(re)) * 0.5;
end
code[re_, im_] := N[(N[(N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(\left(-2\right) \cdot \sinh im\right) \cdot \cos re\right) \cdot 0.5
\end{array}
Derivation
  1. Initial program 54.4%

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

    \[\leadsto \color{blue}{\left(\left(\left(-2\right) \cdot \sinh im\right) \cdot \cos re\right) \cdot 0.5} \]
  3. Add Preprocessing

Alternative 2: 87.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-2\right) \cdot \sinh im\\ t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_1 \leq -0.01:\\ \;\;\;\;t\_0 \cdot 0.5\\ \mathbf{elif}\;t\_1 \leq 0.0001:\\ \;\;\;\;\left(im \cdot \cos re\right) \cdot \mathsf{fma}\left(im \cdot -0.16666666666666666, im, -1\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (- 2.0) (sinh im)))
        (t_1 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_1 -0.01)
     (* t_0 0.5)
     (if (<= t_1 0.0001)
       (* (* im (cos re)) (fma (* im -0.16666666666666666) im -1.0))
       (* (fma (* re -0.25) re 0.5) t_0)))))
double code(double re, double im) {
	double t_0 = -2.0 * sinh(im);
	double t_1 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = t_0 * 0.5;
	} else if (t_1 <= 0.0001) {
		tmp = (im * cos(re)) * fma((im * -0.16666666666666666), im, -1.0);
	} else {
		tmp = fma((re * -0.25), re, 0.5) * t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(-2.0) * sinh(im))
	t_1 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_1 <= -0.01)
		tmp = Float64(t_0 * 0.5);
	elseif (t_1 <= 0.0001)
		tmp = Float64(Float64(im * cos(re)) * fma(Float64(im * -0.16666666666666666), im, -1.0));
	else
		tmp = Float64(fma(Float64(re * -0.25), re, 0.5) * t_0);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(t$95$0 * 0.5), $MachinePrecision], If[LessEqual[t$95$1, 0.0001], N[(N[(im * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(im * -0.16666666666666666), $MachinePrecision] * im + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.25), $MachinePrecision] * re + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-2\right) \cdot \sinh im\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;t\_0 \cdot 0.5\\

\mathbf{elif}\;t\_1 \leq 0.0001:\\
\;\;\;\;\left(im \cdot \cos re\right) \cdot \mathsf{fma}\left(im \cdot -0.16666666666666666, im, -1\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -0.0100000000000000002

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(im\right)} - e^{im}\right)} \]
    3. Applied rewrites41.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Applied rewrites64.9%

      \[\leadsto \left(\left(-2\right) \cdot \sinh im\right) \cdot \color{blue}{0.5} \]

    if -0.0100000000000000002 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 1.00000000000000005e-4

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{im \cdot \left(-1 \cdot \cos re + \frac{-1}{6} \cdot \left({im}^{2} \cdot \cos re\right)\right)} \]
    3. Applied rewrites83.9%

      \[\leadsto \color{blue}{im \cdot \mathsf{fma}\left(-1, \cos re, -0.16666666666666666 \cdot \left({im}^{2} \cdot \cos re\right)\right)} \]
    4. Applied rewrites83.9%

      \[\leadsto \color{blue}{\left(im \cdot \cos re\right) \cdot \mathsf{fma}\left(im \cdot -0.16666666666666666, im, -1\right)} \]

    if 1.00000000000000005e-4 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} + \frac{-1}{4} \cdot {re}^{2}\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. Applied rewrites40.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot \left(\left(-2\right) \cdot \sinh im\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 87.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-2\right) \cdot \sinh im\\ t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_1 \leq -0.01:\\ \;\;\;\;t\_0 \cdot 0.5\\ \mathbf{elif}\;t\_1 \leq 0.0001:\\ \;\;\;\;\left(-im\right) \cdot \cos re\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (- 2.0) (sinh im)))
        (t_1 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_1 -0.01)
     (* t_0 0.5)
     (if (<= t_1 0.0001)
       (* (- im) (cos re))
       (* (fma (* re -0.25) re 0.5) t_0)))))
double code(double re, double im) {
	double t_0 = -2.0 * sinh(im);
	double t_1 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_1 <= -0.01) {
		tmp = t_0 * 0.5;
	} else if (t_1 <= 0.0001) {
		tmp = -im * cos(re);
	} else {
		tmp = fma((re * -0.25), re, 0.5) * t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(-2.0) * sinh(im))
	t_1 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_1 <= -0.01)
		tmp = Float64(t_0 * 0.5);
	elseif (t_1 <= 0.0001)
		tmp = Float64(Float64(-im) * cos(re));
	else
		tmp = Float64(fma(Float64(re * -0.25), re, 0.5) * t_0);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.01], N[(t$95$0 * 0.5), $MachinePrecision], If[LessEqual[t$95$1, 0.0001], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.25), $MachinePrecision] * re + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-2\right) \cdot \sinh im\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\mathbf{if}\;t\_1 \leq -0.01:\\
\;\;\;\;t\_0 \cdot 0.5\\

\mathbf{elif}\;t\_1 \leq 0.0001:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -0.0100000000000000002

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(im\right)} - e^{im}\right)} \]
    3. Applied rewrites41.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Applied rewrites64.9%

      \[\leadsto \left(\left(-2\right) \cdot \sinh im\right) \cdot \color{blue}{0.5} \]

    if -0.0100000000000000002 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 1.00000000000000005e-4

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Applied rewrites52.1%

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

    if 1.00000000000000005e-4 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} + \frac{-1}{4} \cdot {re}^{2}\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. Applied rewrites40.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot \left(\left(-2\right) \cdot \sinh im\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 65.2% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-2\right) \cdot \sinh im\\ \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\ \;\;\;\;t\_0 \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (- 2.0) (sinh im))))
   (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
     (* t_0 0.5)
     (* (fma (* re -0.25) re 0.5) t_0))))
double code(double re, double im) {
	double t_0 = -2.0 * sinh(im);
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
		tmp = t_0 * 0.5;
	} else {
		tmp = fma((re * -0.25), re, 0.5) * t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(-2.0) * sinh(im))
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0)
		tmp = Float64(t_0 * 0.5);
	else
		tmp = Float64(fma(Float64(re * -0.25), re, 0.5) * t_0);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(t$95$0 * 0.5), $MachinePrecision], N[(N[(N[(re * -0.25), $MachinePrecision] * re + 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(-2\right) \cdot \sinh im\\
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;t\_0 \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(im\right)} - e^{im}\right)} \]
    3. Applied rewrites41.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Applied rewrites64.9%

      \[\leadsto \left(\left(-2\right) \cdot \sinh im\right) \cdot \color{blue}{0.5} \]

    if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} + \frac{-1}{4} \cdot {re}^{2}\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    3. Applied rewrites40.0%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re \cdot -0.25, re, 0.5\right) \cdot \left(\left(-2\right) \cdot \sinh im\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 52.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\ \;\;\;\;\left(\left(-2\right) \cdot \sinh im\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
   (* (* (- 2.0) (sinh im)) 0.5)
   (fma -1.0 im (* 0.5 (* im (sqrt (* (* re re) (* re re))))))))
double code(double re, double im) {
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
		tmp = (-2.0 * sinh(im)) * 0.5;
	} else {
		tmp = fma(-1.0, im, (0.5 * (im * sqrt(((re * re) * (re * re))))));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0)
		tmp = Float64(Float64(Float64(-2.0) * sinh(im)) * 0.5);
	else
		tmp = fma(-1.0, im, Float64(0.5 * Float64(im * sqrt(Float64(Float64(re * re) * Float64(re * re))))));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(-1.0 * im + N[(0.5 * N[(im * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;\left(\left(-2\right) \cdot \sinh im\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(im\right)} - e^{im}\right)} \]
    3. Applied rewrites41.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Applied rewrites64.9%

      \[\leadsto \left(\left(-2\right) \cdot \sinh im\right) \cdot \color{blue}{0.5} \]

    if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Taylor expanded in re around 0

      \[\leadsto -1 \cdot im + \color{blue}{\frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)} \]
    5. Applied rewrites35.8%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    6. Applied rewrites36.2%

      \[\leadsto \mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 51.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\ \;\;\;\;\left(\left(-2\right) \cdot \sinh im\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
   (* (* (- 2.0) (sinh im)) 0.5)
   (* im (fma (* 0.5 re) re -1.0))))
double code(double re, double im) {
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
		tmp = (-2.0 * sinh(im)) * 0.5;
	} else {
		tmp = im * fma((0.5 * re), re, -1.0);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0)
		tmp = Float64(Float64(Float64(-2.0) * sinh(im)) * 0.5);
	else
		tmp = Float64(im * fma(Float64(0.5 * re), re, -1.0));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[((-2.0) * N[Sinh[im], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(im * N[(N[(0.5 * re), $MachinePrecision] * re + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;\left(\left(-2\right) \cdot \sinh im\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(e^{\mathsf{neg}\left(im\right)} - e^{im}\right)} \]
    3. Applied rewrites41.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Applied rewrites64.9%

      \[\leadsto \left(\left(-2\right) \cdot \sinh im\right) \cdot \color{blue}{0.5} \]

    if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Taylor expanded in re around 0

      \[\leadsto -1 \cdot im + \color{blue}{\frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)} \]
    5. Applied rewrites35.8%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    6. Applied rewrites35.8%

      \[\leadsto im \cdot \color{blue}{\mathsf{fma}\left(0.5 \cdot re, re, -1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 46.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\ \;\;\;\;im \cdot \left(-0.16666666666666666 \cdot \left(\left(im \cdot im\right) \cdot 1\right) - 1\right)\\ \mathbf{else}:\\ \;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
   (* im (- (* -0.16666666666666666 (* (* im im) 1.0)) 1.0))
   (* im (fma (* 0.5 re) re -1.0))))
double code(double re, double im) {
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
		tmp = im * ((-0.16666666666666666 * ((im * im) * 1.0)) - 1.0);
	} else {
		tmp = im * fma((0.5 * re), re, -1.0);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0)
		tmp = Float64(im * Float64(Float64(-0.16666666666666666 * Float64(Float64(im * im) * 1.0)) - 1.0));
	else
		tmp = Float64(im * fma(Float64(0.5 * re), re, -1.0));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(im * N[(N[(-0.16666666666666666 * N[(N[(im * im), $MachinePrecision] * 1.0), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision], N[(im * N[(N[(0.5 * re), $MachinePrecision] * re + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;im \cdot \left(-0.16666666666666666 \cdot \left(\left(im \cdot im\right) \cdot 1\right) - 1\right)\\

\mathbf{else}:\\
\;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{im \cdot \left(-1 \cdot \cos re + \frac{-1}{6} \cdot \left({im}^{2} \cdot \cos re\right)\right)} \]
    3. Applied rewrites83.9%

      \[\leadsto \color{blue}{im \cdot \mathsf{fma}\left(-1, \cos re, -0.16666666666666666 \cdot \left({im}^{2} \cdot \cos re\right)\right)} \]
    4. Applied rewrites83.9%

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

      \[\leadsto im \cdot \left(\frac{-1}{6} \cdot \left(\left(im \cdot im\right) \cdot 1\right) - \cos re\right) \]
    6. Applied rewrites75.1%

      \[\leadsto im \cdot \left(-0.16666666666666666 \cdot \left(\left(im \cdot im\right) \cdot 1\right) - \cos re\right) \]
    7. Taylor expanded in re around 0

      \[\leadsto im \cdot \left(\frac{-1}{6} \cdot \left(\left(im \cdot im\right) \cdot 1\right) - 1\right) \]
    8. Applied rewrites53.0%

      \[\leadsto im \cdot \left(-0.16666666666666666 \cdot \left(\left(im \cdot im\right) \cdot 1\right) - 1\right) \]

    if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Taylor expanded in re around 0

      \[\leadsto -1 \cdot im + \color{blue}{\frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)} \]
    5. Applied rewrites35.8%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    6. Applied rewrites35.8%

      \[\leadsto im \cdot \color{blue}{\mathsf{fma}\left(0.5 \cdot re, re, -1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 33.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 0.0)
   (* -1.0 im)
   (* im (fma (* 0.5 re) re -1.0))))
double code(double re, double im) {
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 0.0) {
		tmp = -1.0 * im;
	} else {
		tmp = im * fma((0.5 * re), re, -1.0);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 0.0)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(im * fma(Float64(0.5 * re), re, -1.0));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(-1.0 * im), $MachinePrecision], N[(im * N[(N[(0.5 * re), $MachinePrecision] * re + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq 0:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;im \cdot \mathsf{fma}\left(0.5 \cdot re, re, -1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 0.0

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Taylor expanded in re around 0

      \[\leadsto -1 \cdot im \]
    5. Applied rewrites29.4%

      \[\leadsto -1 \cdot im \]

    if 0.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (-.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im)))

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    3. Applied rewrites52.1%

      \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
    4. Taylor expanded in re around 0

      \[\leadsto -1 \cdot im + \color{blue}{\frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)} \]
    5. Applied rewrites35.8%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    6. Applied rewrites35.8%

      \[\leadsto im \cdot \color{blue}{\mathsf{fma}\left(0.5 \cdot re, re, -1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 29.4% accurate, 16.3× speedup?

\[\begin{array}{l} \\ -1 \cdot im \end{array} \]
(FPCore (re im) :precision binary64 (* -1.0 im))
double code(double re, double im) {
	return -1.0 * im;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (-1.0d0) * im
end function
public static double code(double re, double im) {
	return -1.0 * im;
}
def code(re, im):
	return -1.0 * im
function code(re, im)
	return Float64(-1.0 * im)
end
function tmp = code(re, im)
	tmp = -1.0 * im;
end
code[re_, im_] := N[(-1.0 * im), $MachinePrecision]
\begin{array}{l}

\\
-1 \cdot im
\end{array}
Derivation
  1. Initial program 54.4%

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

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  3. Applied rewrites52.1%

    \[\leadsto \color{blue}{-1 \cdot \left(im \cdot \cos re\right)} \]
  4. Taylor expanded in re around 0

    \[\leadsto -1 \cdot im \]
  5. Applied rewrites29.4%

    \[\leadsto -1 \cdot im \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025153 
(FPCore (re im)
  :name "math.sin on complex, imaginary part"
  :precision binary64
  (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))