math.sin on complex, imaginary part

Percentage Accurate: 54.9% → 99.9%
Time: 5.4s
Alternatives: 16
Speedup: 1.4×

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 16 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.9% 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(2 \cdot \sinh \left(-im\right)\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(2.0 * sinh(Float64(-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(2 \cdot \sinh \left(-im\right)\right) \cdot \cos re\right) \cdot 0.5
\end{array}
Derivation
  1. Initial program 54.9%

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

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

Alternative 2: 86.9% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
t_0 := e^{0 - im}\\
\mathbf{if}\;im \leq -5.5:\\
\;\;\;\;\mathsf{fma}\left(re, -0.25, 0.5\right) \cdot \left(t\_0 - \left(1 + im\right)\right)\\

\mathbf{elif}\;im \leq 0.0102:\\
\;\;\;\;-1 \cdot \left(im \cdot \cos re\right)\\

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


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

    1. Initial program 54.9%

      \[\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.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, -0.25, 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    5. Taylor expanded in im around 0

      \[\leadsto \mathsf{fma}\left(re, \frac{-1}{4}, \frac{1}{2}\right) \cdot \left(e^{0 - im} - \color{blue}{\left(1 + im\right)}\right) \]
    6. Applied rewrites26.1%

      \[\leadsto \mathsf{fma}\left(re, -0.25, 0.5\right) \cdot \left(e^{0 - im} - \color{blue}{\left(1 + im\right)}\right) \]

    if -5.5 < im < 0.010200000000000001

    1. Initial program 54.9%

      \[\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 rewrites51.5%

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

    if 0.010200000000000001 < im

    1. Initial program 54.9%

      \[\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.8%

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

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

Alternative 3: 76.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\ \;\;\;\;\left(-0.25 \cdot re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* 0.5 (cos re)) -0.01)
   (* (* -0.25 re) (- (exp (- 0.0 im)) (exp im)))
   (* (* (* 2.0 (sinh (- im))) 1.0) 0.5)))
double code(double re, double im) {
	double tmp;
	if ((0.5 * cos(re)) <= -0.01) {
		tmp = (-0.25 * re) * (exp((0.0 - im)) - exp(im));
	} else {
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((0.5d0 * cos(re)) <= (-0.01d0)) then
        tmp = ((-0.25d0) * re) * (exp((0.0d0 - im)) - exp(im))
    else
        tmp = ((2.0d0 * sinh(-im)) * 1.0d0) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((0.5 * Math.cos(re)) <= -0.01) {
		tmp = (-0.25 * re) * (Math.exp((0.0 - im)) - Math.exp(im));
	} else {
		tmp = ((2.0 * Math.sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (0.5 * math.cos(re)) <= -0.01:
		tmp = (-0.25 * re) * (math.exp((0.0 - im)) - math.exp(im))
	else:
		tmp = ((2.0 * math.sinh(-im)) * 1.0) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(0.5 * cos(re)) <= -0.01)
		tmp = Float64(Float64(-0.25 * re) * Float64(exp(Float64(0.0 - im)) - exp(im)));
	else
		tmp = Float64(Float64(Float64(2.0 * sinh(Float64(-im))) * 1.0) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((0.5 * cos(re)) <= -0.01)
		tmp = (-0.25 * re) * (exp((0.0 - im)) - exp(im));
	else
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(-0.25 * re), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[Sinh[(-im)], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\


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

    1. Initial program 54.9%

      \[\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.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, -0.25, 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right) \]
    5. Taylor expanded in re around inf

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

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

    if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

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

Alternative 4: 75.2% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.02:\\
\;\;\;\;\mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot {\left(re \cdot re\right)}^{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\


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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

      \[\leadsto \mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot {\left(re \cdot re\right)}^{2}\right)\right) \]

    if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

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

Alternative 5: 72.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \cos re \leq -0.02:\\ \;\;\;\;im \cdot \left(0.5 \cdot {re}^{2} - 1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* 0.5 (cos re)) -0.02)
   (* im (- (* 0.5 (pow re 2.0)) 1.0))
   (* (* (* 2.0 (sinh (- im))) 1.0) 0.5)))
double code(double re, double im) {
	double tmp;
	if ((0.5 * cos(re)) <= -0.02) {
		tmp = im * ((0.5 * pow(re, 2.0)) - 1.0);
	} else {
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((0.5d0 * cos(re)) <= (-0.02d0)) then
        tmp = im * ((0.5d0 * (re ** 2.0d0)) - 1.0d0)
    else
        tmp = ((2.0d0 * sinh(-im)) * 1.0d0) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((0.5 * Math.cos(re)) <= -0.02) {
		tmp = im * ((0.5 * Math.pow(re, 2.0)) - 1.0);
	} else {
		tmp = ((2.0 * Math.sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (0.5 * math.cos(re)) <= -0.02:
		tmp = im * ((0.5 * math.pow(re, 2.0)) - 1.0)
	else:
		tmp = ((2.0 * math.sinh(-im)) * 1.0) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(0.5 * cos(re)) <= -0.02)
		tmp = Float64(im * Float64(Float64(0.5 * (re ^ 2.0)) - 1.0));
	else
		tmp = Float64(Float64(Float64(2.0 * sinh(Float64(-im))) * 1.0) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((0.5 * cos(re)) <= -0.02)
		tmp = im * ((0.5 * (re ^ 2.0)) - 1.0);
	else
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.02], N[(im * N[(N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[Sinh[(-im)], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\


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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    6. Taylor expanded in im around 0

      \[\leadsto im \cdot \left(\frac{1}{2} \cdot {re}^{2} - \color{blue}{1}\right) \]
    7. Applied rewrites36.4%

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

    if -0.0200000000000000004 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

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

Alternative 6: 69.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\ \;\;\;\;0.5 \cdot \left(\left(1 + -1 \cdot im\right) - \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* 0.5 (cos re)) -0.01)
   (* 0.5 (- (+ 1.0 (* -1.0 im)) (+ 1.0 (* im (+ 1.0 (* 0.5 im))))))
   (* (* (* 2.0 (sinh (- im))) 1.0) 0.5)))
double code(double re, double im) {
	double tmp;
	if ((0.5 * cos(re)) <= -0.01) {
		tmp = 0.5 * ((1.0 + (-1.0 * im)) - (1.0 + (im * (1.0 + (0.5 * im)))));
	} else {
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((0.5d0 * cos(re)) <= (-0.01d0)) then
        tmp = 0.5d0 * ((1.0d0 + ((-1.0d0) * im)) - (1.0d0 + (im * (1.0d0 + (0.5d0 * im)))))
    else
        tmp = ((2.0d0 * sinh(-im)) * 1.0d0) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((0.5 * Math.cos(re)) <= -0.01) {
		tmp = 0.5 * ((1.0 + (-1.0 * im)) - (1.0 + (im * (1.0 + (0.5 * im)))));
	} else {
		tmp = ((2.0 * Math.sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (0.5 * math.cos(re)) <= -0.01:
		tmp = 0.5 * ((1.0 + (-1.0 * im)) - (1.0 + (im * (1.0 + (0.5 * im)))))
	else:
		tmp = ((2.0 * math.sinh(-im)) * 1.0) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(0.5 * cos(re)) <= -0.01)
		tmp = Float64(0.5 * Float64(Float64(1.0 + Float64(-1.0 * im)) - Float64(1.0 + Float64(im * Float64(1.0 + Float64(0.5 * im))))));
	else
		tmp = Float64(Float64(Float64(2.0 * sinh(Float64(-im))) * 1.0) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((0.5 * cos(re)) <= -0.01)
		tmp = 0.5 * ((1.0 + (-1.0 * im)) - (1.0 + (im * (1.0 + (0.5 * im)))));
	else
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(0.5 * N[(N[(1.0 + N[(-1.0 * im), $MachinePrecision]), $MachinePrecision] - N[(1.0 + N[(im * N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[Sinh[(-im)], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\


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

    1. Initial program 54.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - e^{\color{blue}{im}}\right) \]
    6. Taylor expanded in im around 0

      \[\leadsto \frac{1}{2} \cdot \left(\left(1 + -1 \cdot im\right) - \left(1 + \color{blue}{im \cdot \left(1 + \frac{1}{2} \cdot im\right)}\right)\right) \]
    7. Applied rewrites16.4%

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

    if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

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

Alternative 7: 68.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \cos re \leq -0.09:\\ \;\;\;\;0.5 \cdot \left(2 - \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* 0.5 (cos re)) -0.09)
   (* 0.5 (- 2.0 (+ 1.0 (* im (+ 1.0 (* 0.5 im))))))
   (* (* (* 2.0 (sinh (- im))) 1.0) 0.5)))
double code(double re, double im) {
	double tmp;
	if ((0.5 * cos(re)) <= -0.09) {
		tmp = 0.5 * (2.0 - (1.0 + (im * (1.0 + (0.5 * im)))));
	} else {
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((0.5d0 * cos(re)) <= (-0.09d0)) then
        tmp = 0.5d0 * (2.0d0 - (1.0d0 + (im * (1.0d0 + (0.5d0 * im)))))
    else
        tmp = ((2.0d0 * sinh(-im)) * 1.0d0) * 0.5d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((0.5 * Math.cos(re)) <= -0.09) {
		tmp = 0.5 * (2.0 - (1.0 + (im * (1.0 + (0.5 * im)))));
	} else {
		tmp = ((2.0 * Math.sinh(-im)) * 1.0) * 0.5;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (0.5 * math.cos(re)) <= -0.09:
		tmp = 0.5 * (2.0 - (1.0 + (im * (1.0 + (0.5 * im)))))
	else:
		tmp = ((2.0 * math.sinh(-im)) * 1.0) * 0.5
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(0.5 * cos(re)) <= -0.09)
		tmp = Float64(0.5 * Float64(2.0 - Float64(1.0 + Float64(im * Float64(1.0 + Float64(0.5 * im))))));
	else
		tmp = Float64(Float64(Float64(2.0 * sinh(Float64(-im))) * 1.0) * 0.5);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((0.5 * cos(re)) <= -0.09)
		tmp = 0.5 * (2.0 - (1.0 + (im * (1.0 + (0.5 * im)))));
	else
		tmp = ((2.0 * sinh(-im)) * 1.0) * 0.5;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.09], N[(0.5 * N[(2.0 - N[(1.0 + N[(im * N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[Sinh[(-im)], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \cos re \leq -0.09:\\
\;\;\;\;0.5 \cdot \left(2 - \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot 1\right) \cdot 0.5\\


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

    1. Initial program 54.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - e^{\color{blue}{im}}\right) \]
    6. Taylor expanded in im around 0

      \[\leadsto \frac{1}{2} \cdot \left(\left(1 + -1 \cdot im\right) - \left(1 + \color{blue}{im \cdot \left(1 + \frac{1}{2} \cdot im\right)}\right)\right) \]
    7. Applied rewrites16.4%

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - \left(1 + \color{blue}{im \cdot \left(1 + 0.5 \cdot im\right)}\right)\right) \]
    8. Applied rewrites15.0%

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

    if -0.089999999999999997 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

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

Alternative 8: 65.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;0.5 \cdot \left(2 - e^{im}\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(e^{-im} - \left(1 + im\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_0 (- INFINITY))
     (* 0.5 (- 2.0 (exp im)))
     (if (<= t_0 2e-5) (* -1.0 im) (* 0.5 (- (exp (- im)) (+ 1.0 im)))))))
double code(double re, double im) {
	double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = 0.5 * (2.0 - exp(im));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = 0.5 * (exp(-im) - (1.0 + im));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = 0.5 * (2.0 - Math.exp(im));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = 0.5 * (Math.exp(-im) - (1.0 + im));
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = 0.5 * (2.0 - math.exp(im))
	elif t_0 <= 2e-5:
		tmp = -1.0 * im
	else:
		tmp = 0.5 * (math.exp(-im) - (1.0 + im))
	return tmp
function code(re, im)
	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(0.5 * Float64(2.0 - exp(im)));
	elseif (t_0 <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(0.5 * Float64(exp(Float64(-im)) - Float64(1.0 + im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = 0.5 * (2.0 - exp(im));
	elseif (t_0 <= 2e-5)
		tmp = -1.0 * im;
	else
		tmp = 0.5 * (exp(-im) - (1.0 + im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[(0.5 * N[(2.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(-1.0 * im), $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[(1.0 + im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - \left(1 + im\right)\right)\\


\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))) < -inf.0

    1. Initial program 54.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - e^{\color{blue}{im}}\right) \]
    6. Applied rewrites21.4%

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

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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(e^{-im} - \left(1 + \color{blue}{im}\right)\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 53.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;0.5 \cdot \left(2 - e^{im}\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, im, 0.5 \cdot \left(\left(2 \cdot re\right) \cdot \left(2 \cdot re\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_0 (- INFINITY))
     (* 0.5 (- 2.0 (exp im)))
     (if (<= t_0 2e-5)
       (* -1.0 im)
       (fma -1.0 im (* 0.5 (* (* 2.0 re) (* 2.0 re))))))))
double code(double re, double im) {
	double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = 0.5 * (2.0 - exp(im));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = fma(-1.0, im, (0.5 * ((2.0 * re) * (2.0 * re))));
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(0.5 * Float64(2.0 - exp(im)));
	elseif (t_0 <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = fma(-1.0, im, Float64(0.5 * Float64(Float64(2.0 * re) * Float64(2.0 * re))));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[(0.5 * N[(2.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(-1.0 * im), $MachinePrecision], N[(-1.0 * im + N[(0.5 * N[(N[(2.0 * re), $MachinePrecision] * N[(2.0 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

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


\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))) < -inf.0

    1. Initial program 54.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - e^{\color{blue}{im}}\right) \]
    6. Applied rewrites21.4%

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

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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

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

Alternative 10: 53.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;0.5 \cdot \left(2 - e^{im}\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_0 (- INFINITY))
     (* 0.5 (- 2.0 (exp im)))
     (if (<= t_0 2e-5) (* -1.0 im) (* (* 2.0 re) (* re 0.5))))))
double code(double re, double im) {
	double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = 0.5 * (2.0 - exp(im));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = 0.5 * (2.0 - Math.exp(im));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
	tmp = 0
	if t_0 <= -math.inf:
		tmp = 0.5 * (2.0 - math.exp(im))
	elif t_0 <= 2e-5:
		tmp = -1.0 * im
	else:
		tmp = (2.0 * re) * (re * 0.5)
	return tmp
function code(re, im)
	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(0.5 * Float64(2.0 - exp(im)));
	elseif (t_0 <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(Float64(2.0 * re) * Float64(re * 0.5));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = 0.5 * (2.0 - exp(im));
	elseif (t_0 <= 2e-5)
		tmp = -1.0 * im;
	else
		tmp = (2.0 * re) * (re * 0.5);
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[(0.5 * N[(2.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(-1.0 * im), $MachinePrecision], N[(N[(2.0 * re), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\


\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))) < -inf.0

    1. Initial program 54.9%

      \[\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.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(e^{-im} - e^{im}\right)} \]
    4. Taylor expanded in im around 0

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

      \[\leadsto 0.5 \cdot \left(\left(1 + -1 \cdot im\right) - e^{\color{blue}{im}}\right) \]
    6. Applied rewrites21.4%

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

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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

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

Alternative 11: 41.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(-1, im, 0.5 \cdot \left(\left(2 \cdot re\right) \cdot \left(-re\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_0 (- INFINITY))
     (fma -1.0 im (* 0.5 (* (* 2.0 re) (- re))))
     (if (<= t_0 2e-5) (* -1.0 im) (* (* 2.0 re) (* re 0.5))))))
double code(double re, double im) {
	double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = fma(-1.0, im, (0.5 * ((2.0 * re) * -re)));
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = fma(-1.0, im, Float64(0.5 * Float64(Float64(2.0 * re) * Float64(-re))));
	elseif (t_0 <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(Float64(2.0 * re) * Float64(re * 0.5));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[(-1.0 * im + N[(0.5 * N[(N[(2.0 * re), $MachinePrecision] * (-re)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(-1.0 * im), $MachinePrecision], N[(N[(2.0 * re), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\


\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))) < -inf.0

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

      \[\leadsto \mathsf{fma}\left(-1, im, 0.5 \cdot \left(\left(2 \cdot re\right) \cdot \left(-re\right)\right)\right) \]

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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

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

Alternative 12: 40.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(re \cdot re, -0.25, 0.5\right) \cdot 2\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
   (if (<= t_0 (- INFINITY))
     (* (fma (* re re) -0.25 0.5) 2.0)
     (if (<= t_0 2e-5) (* -1.0 im) (* (* 2.0 re) (* re 0.5))))))
double code(double re, double im) {
	double t_0 = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = fma((re * re), -0.25, 0.5) * 2.0;
	} else if (t_0 <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(fma(Float64(re * re), -0.25, 0.5) * 2.0);
	elseif (t_0 <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(Float64(2.0 * re) * Float64(re * 0.5));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = 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$0, (-Infinity)], N[(N[(N[(re * re), $MachinePrecision] * -0.25 + 0.5), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$0, 2e-5], N[(-1.0 * im), $MachinePrecision], N[(N[(2.0 * re), $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\


\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))) < -inf.0

    1. Initial program 54.9%

      \[\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.8%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, -0.25, 0.5\right) \cdot 2} \]
    5. Applied rewrites8.4%

      \[\leadsto \mathsf{fma}\left(re \cdot re, -0.25, 0.5\right) \cdot 2 \]

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

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

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

Alternative 13: 35.4% 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 2 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot im\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))) 2e-5)
   (* -1.0 im)
   (* (* 2.0 re) (* re 0.5))))
double code(double re, double im) {
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
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
    real(8) :: tmp
    if (((0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))) <= 2d-5) then
        tmp = (-1.0d0) * im
    else
        tmp = (2.0d0 * re) * (re * 0.5d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (((0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im))) <= 2e-5) {
		tmp = -1.0 * im;
	} else {
		tmp = (2.0 * re) * (re * 0.5);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if ((0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))) <= 2e-5:
		tmp = -1.0 * im
	else:
		tmp = (2.0 * re) * (re * 0.5)
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) <= 2e-5)
		tmp = Float64(-1.0 * im);
	else
		tmp = Float64(Float64(2.0 * re) * Float64(re * 0.5));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (((0.5 * cos(re)) * (exp((0.0 - im)) - exp(im))) <= 2e-5)
		tmp = -1.0 * im;
	else
		tmp = (2.0 * re) * (re * 0.5);
	end
	tmp_2 = 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], 2e-5], N[(-1.0 * im), $MachinePrecision], N[(N[(2.0 * re), $MachinePrecision] * N[(re * 0.5), $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 2 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot im\\

\mathbf{else}:\\
\;\;\;\;\left(2 \cdot re\right) \cdot \left(re \cdot 0.5\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))) < 2.00000000000000016e-5

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]

    if 2.00000000000000016e-5 < (*.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.9%

      \[\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 rewrites51.5%

      \[\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 rewrites36.5%

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

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

Alternative 14: 32.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \cos re \leq -0.01:\\ \;\;\;\;\left(im \cdot 1\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= (* 0.5 (cos re)) -0.01) (* (* im 1.0) 0.5) (* -1.0 im)))
double code(double re, double im) {
	double tmp;
	if ((0.5 * cos(re)) <= -0.01) {
		tmp = (im * 1.0) * 0.5;
	} else {
		tmp = -1.0 * im;
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((0.5d0 * cos(re)) <= (-0.01d0)) then
        tmp = (im * 1.0d0) * 0.5d0
    else
        tmp = (-1.0d0) * im
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((0.5 * Math.cos(re)) <= -0.01) {
		tmp = (im * 1.0) * 0.5;
	} else {
		tmp = -1.0 * im;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (0.5 * math.cos(re)) <= -0.01:
		tmp = (im * 1.0) * 0.5
	else:
		tmp = -1.0 * im
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(0.5 * cos(re)) <= -0.01)
		tmp = Float64(Float64(im * 1.0) * 0.5);
	else
		tmp = Float64(-1.0 * im);
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((0.5 * cos(re)) <= -0.01)
		tmp = (im * 1.0) * 0.5;
	else
		tmp = -1.0 * im;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision], -0.01], N[(N[(im * 1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(-1.0 * im), $MachinePrecision]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;-1 \cdot im\\


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

    1. Initial program 54.9%

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

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

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites65.8%

      \[\leadsto \left(\left(2 \cdot \sinh \left(-im\right)\right) \cdot \color{blue}{1}\right) \cdot 0.5 \]
    5. Applied rewrites4.6%

      \[\leadsto \left(\color{blue}{im} \cdot 1\right) \cdot 0.5 \]

    if -0.0100000000000000002 < (*.f64 #s(literal 1/2 binary64) (cos.f64 re))

    1. Initial program 54.9%

      \[\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 rewrites51.5%

      \[\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.7%

      \[\leadsto -1 \cdot im \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 29.7% 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.9%

    \[\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 rewrites51.5%

    \[\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.7%

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

Alternative 16: 3.0% accurate, 16.3× speedup?

\[\begin{array}{l} \\ re \cdot 0.5 \end{array} \]
(FPCore (re im) :precision binary64 (* re 0.5))
double code(double re, double im) {
	return 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 = re * 0.5d0
end function
public static double code(double re, double im) {
	return re * 0.5;
}
def code(re, im):
	return re * 0.5
function code(re, im)
	return Float64(re * 0.5)
end
function tmp = code(re, im)
	tmp = re * 0.5;
end
code[re_, im_] := N[(re * 0.5), $MachinePrecision]
\begin{array}{l}

\\
re \cdot 0.5
\end{array}
Derivation
  1. Initial program 54.9%

    \[\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 rewrites51.5%

    \[\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 rewrites36.5%

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

    \[\leadsto re \cdot 0.5 \]
  7. Add Preprocessing

Reproduce

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