math.cos on complex, imaginary part

Percentage Accurate: 66.3% → 99.9%
Time: 5.2s
Alternatives: 17
Speedup: 1.4×

Specification

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

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

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

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

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

Alternative 1: 99.9% accurate, 1.1× speedup?

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

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

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

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

Alternative 2: 93.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq -0.0215:\\ \;\;\;\;\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{elif}\;im \leq 1.25:\\ \;\;\;\;-1 \cdot \left(im \cdot \sin re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(1 - e^{im}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im -0.0215)
   (*
    (* re (+ 0.5 (* -0.08333333333333333 (pow re 2.0))))
    (- (exp (- im)) (exp im)))
   (if (<= im 1.25)
     (* -1.0 (* im (sin re)))
     (* (* 0.5 (sin re)) (- 1.0 (exp im))))))
double code(double re, double im) {
	double tmp;
	if (im <= -0.0215) {
		tmp = (re * (0.5 + (-0.08333333333333333 * pow(re, 2.0)))) * (exp(-im) - exp(im));
	} else if (im <= 1.25) {
		tmp = -1.0 * (im * sin(re));
	} else {
		tmp = (0.5 * sin(re)) * (1.0 - exp(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 (im <= (-0.0215d0)) then
        tmp = (re * (0.5d0 + ((-0.08333333333333333d0) * (re ** 2.0d0)))) * (exp(-im) - exp(im))
    else if (im <= 1.25d0) then
        tmp = (-1.0d0) * (im * sin(re))
    else
        tmp = (0.5d0 * sin(re)) * (1.0d0 - exp(im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= -0.0215) {
		tmp = (re * (0.5 + (-0.08333333333333333 * Math.pow(re, 2.0)))) * (Math.exp(-im) - Math.exp(im));
	} else if (im <= 1.25) {
		tmp = -1.0 * (im * Math.sin(re));
	} else {
		tmp = (0.5 * Math.sin(re)) * (1.0 - Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= -0.0215:
		tmp = (re * (0.5 + (-0.08333333333333333 * math.pow(re, 2.0)))) * (math.exp(-im) - math.exp(im))
	elif im <= 1.25:
		tmp = -1.0 * (im * math.sin(re))
	else:
		tmp = (0.5 * math.sin(re)) * (1.0 - math.exp(im))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= -0.0215)
		tmp = Float64(Float64(re * Float64(0.5 + Float64(-0.08333333333333333 * (re ^ 2.0)))) * Float64(exp(Float64(-im)) - exp(im)));
	elseif (im <= 1.25)
		tmp = Float64(-1.0 * Float64(im * sin(re)));
	else
		tmp = Float64(Float64(0.5 * sin(re)) * Float64(1.0 - exp(im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= -0.0215)
		tmp = (re * (0.5 + (-0.08333333333333333 * (re ^ 2.0)))) * (exp(-im) - exp(im));
	elseif (im <= 1.25)
		tmp = -1.0 * (im * sin(re));
	else
		tmp = (0.5 * sin(re)) * (1.0 - exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, -0.0215], N[(N[(re * N[(0.5 + N[(-0.08333333333333333 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.25], N[(-1.0 * N[(im * N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.0215:\\
\;\;\;\;\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right) \cdot \left(e^{-im} - e^{im}\right)\\

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

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


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

    1. Initial program 66.3%

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

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

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

    if -0.021499999999999998 < im < 1.25

    1. Initial program 66.3%

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

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

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

    if 1.25 < im

    1. Initial program 66.3%

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

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

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

Alternative 3: 92.8% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 66.3%

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

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

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

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

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

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

    if -6.29999999999999982 < im < 1.25

    1. Initial program 66.3%

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

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

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

    if 1.25 < im

    1. Initial program 66.3%

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

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

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

Alternative 4: 86.7% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 66.3%

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

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

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

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

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

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

    if -6.29999999999999982 < im < 8.5

    1. Initial program 66.3%

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

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

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

    if 8.5 < im

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

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

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

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

Alternative 5: 63.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot re\\
\mathbf{if}\;0.5 \cdot \sin re \leq 5 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \left(e^{-im} - e^{im}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot im\\


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

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

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

    if 5.00000000000000024e-5 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 6: 63.3% accurate, 1.6× speedup?

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

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

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

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


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

    1. Initial program 66.3%

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

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

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

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

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

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

    if -1.65999999999999992 < im < 0.95999999999999996

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.95999999999999996 < im

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

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

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

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

Alternative 7: 61.8% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 66.3%

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

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

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

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

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

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

    if -1.65999999999999992 < im < 1.25

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 1.25 < im

    1. Initial program 66.3%

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

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

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

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

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

Alternative 8: 48.7% accurate, 2.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 3.1e13

    1. Initial program 66.3%

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

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

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

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

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

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

    if 3.1e13 < im

    1. Initial program 66.3%

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

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

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

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

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

Alternative 9: 45.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\\ \mathbf{if}\;t\_0 \leq -0.03:\\ \;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(\mathsf{fma}\left(re, -0.16666666666666666, 2\right) \cdot 2\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(1 + \left(-0.16666666666666666 \cdot re\right) \cdot re\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot re\right) \cdot im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re))))
   (if (<= t_0 -0.03)
     (* -1.0 (* im (* re (* (fma re -0.16666666666666666 2.0) 2.0))))
     (if (<= t_0 5e-5)
       (* -1.0 (* im (* re (+ 1.0 (* (* -0.16666666666666666 re) re)))))
       (* (* (fma re -0.08333333333333333 0.5) re) im)))))
double code(double re, double im) {
	double t_0 = 0.5 * sin(re);
	double tmp;
	if (t_0 <= -0.03) {
		tmp = -1.0 * (im * (re * (fma(re, -0.16666666666666666, 2.0) * 2.0)));
	} else if (t_0 <= 5e-5) {
		tmp = -1.0 * (im * (re * (1.0 + ((-0.16666666666666666 * re) * re))));
	} else {
		tmp = (fma(re, -0.08333333333333333, 0.5) * re) * im;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(0.5 * sin(re))
	tmp = 0.0
	if (t_0 <= -0.03)
		tmp = Float64(-1.0 * Float64(im * Float64(re * Float64(fma(re, -0.16666666666666666, 2.0) * 2.0))));
	elseif (t_0 <= 5e-5)
		tmp = Float64(-1.0 * Float64(im * Float64(re * Float64(1.0 + Float64(Float64(-0.16666666666666666 * re) * re)))));
	else
		tmp = Float64(Float64(fma(re, -0.08333333333333333, 0.5) * re) * im);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.03], N[(-1.0 * N[(im * N[(re * N[(N[(re * -0.16666666666666666 + 2.0), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e-5], N[(-1.0 * N[(im * N[(re * N[(1.0 + N[(N[(-0.16666666666666666 * re), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.08333333333333333 + 0.5), $MachinePrecision] * re), $MachinePrecision] * im), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;t\_0 \leq -0.03:\\
\;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(\mathsf{fma}\left(re, -0.16666666666666666, 2\right) \cdot 2\right)\right)\right)\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(1 + \left(-0.16666666666666666 \cdot re\right) \cdot re\right)\right)\right)\\

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


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

    1. Initial program 66.3%

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

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \left(re \cdot \color{blue}{\left(1 + -0.16666666666666666 \cdot {re}^{2}\right)}\right)\right) \]
    6. Applied rewrites25.4%

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

    if -0.029999999999999999 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 5.00000000000000024e-5

    1. Initial program 66.3%

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

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

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

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

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

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

    if 5.00000000000000024e-5 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 10: 44.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{-26}:\\ \;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(\mathsf{fma}\left(re, -0.16666666666666666, 2\right) \cdot 2\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.054:\\ \;\;\;\;-1 \cdot \left(im \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot re\right) \cdot im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re))))
   (if (<= t_0 -5e-26)
     (* -1.0 (* im (* re (* (fma re -0.16666666666666666 2.0) 2.0))))
     (if (<= t_0 0.054)
       (* -1.0 (* im re))
       (* (* (fma re -0.08333333333333333 0.5) re) im)))))
double code(double re, double im) {
	double t_0 = 0.5 * sin(re);
	double tmp;
	if (t_0 <= -5e-26) {
		tmp = -1.0 * (im * (re * (fma(re, -0.16666666666666666, 2.0) * 2.0)));
	} else if (t_0 <= 0.054) {
		tmp = -1.0 * (im * re);
	} else {
		tmp = (fma(re, -0.08333333333333333, 0.5) * re) * im;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(0.5 * sin(re))
	tmp = 0.0
	if (t_0 <= -5e-26)
		tmp = Float64(-1.0 * Float64(im * Float64(re * Float64(fma(re, -0.16666666666666666, 2.0) * 2.0))));
	elseif (t_0 <= 0.054)
		tmp = Float64(-1.0 * Float64(im * re));
	else
		tmp = Float64(Float64(fma(re, -0.08333333333333333, 0.5) * re) * im);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-26], N[(-1.0 * N[(im * N[(re * N[(N[(re * -0.16666666666666666 + 2.0), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.054], N[(-1.0 * N[(im * re), $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.08333333333333333 + 0.5), $MachinePrecision] * re), $MachinePrecision] * im), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-26}:\\
\;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(\mathsf{fma}\left(re, -0.16666666666666666, 2\right) \cdot 2\right)\right)\right)\\

\mathbf{elif}\;t\_0 \leq 0.054:\\
\;\;\;\;-1 \cdot \left(im \cdot re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -5.00000000000000019e-26

    1. Initial program 66.3%

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

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \left(re \cdot \color{blue}{\left(1 + -0.16666666666666666 \cdot {re}^{2}\right)}\right)\right) \]
    6. Applied rewrites25.4%

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

    if -5.00000000000000019e-26 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 0.0539999999999999994

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.0539999999999999994 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 11: 44.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\\ \mathbf{if}\;t\_0 \leq -5 \cdot 10^{-26}:\\ \;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \mathsf{fma}\left(re, -0.16666666666666666, 2\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.054:\\ \;\;\;\;-1 \cdot \left(im \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot re\right) \cdot im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re))))
   (if (<= t_0 -5e-26)
     (* -1.0 (* im (* re (fma re -0.16666666666666666 2.0))))
     (if (<= t_0 0.054)
       (* -1.0 (* im re))
       (* (* (fma re -0.08333333333333333 0.5) re) im)))))
double code(double re, double im) {
	double t_0 = 0.5 * sin(re);
	double tmp;
	if (t_0 <= -5e-26) {
		tmp = -1.0 * (im * (re * fma(re, -0.16666666666666666, 2.0)));
	} else if (t_0 <= 0.054) {
		tmp = -1.0 * (im * re);
	} else {
		tmp = (fma(re, -0.08333333333333333, 0.5) * re) * im;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(0.5 * sin(re))
	tmp = 0.0
	if (t_0 <= -5e-26)
		tmp = Float64(-1.0 * Float64(im * Float64(re * fma(re, -0.16666666666666666, 2.0))));
	elseif (t_0 <= 0.054)
		tmp = Float64(-1.0 * Float64(im * re));
	else
		tmp = Float64(Float64(fma(re, -0.08333333333333333, 0.5) * re) * im);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-26], N[(-1.0 * N[(im * N[(re * N[(re * -0.16666666666666666 + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.054], N[(-1.0 * N[(im * re), $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.08333333333333333 + 0.5), $MachinePrecision] * re), $MachinePrecision] * im), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-26}:\\
\;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \mathsf{fma}\left(re, -0.16666666666666666, 2\right)\right)\right)\\

\mathbf{elif}\;t\_0 \leq 0.054:\\
\;\;\;\;-1 \cdot \left(im \cdot re\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -5.00000000000000019e-26

    1. Initial program 66.3%

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

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \left(re \cdot \color{blue}{\left(1 + -0.16666666666666666 \cdot {re}^{2}\right)}\right)\right) \]
    6. Applied rewrites25.6%

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

    if -5.00000000000000019e-26 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 0.0539999999999999994

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.0539999999999999994 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 12: 44.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\\ \mathbf{if}\;t\_0 \leq -0.02:\\ \;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(-0.16666666666666666 \cdot re\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.054:\\ \;\;\;\;-1 \cdot \left(im \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot re\right) \cdot im\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re))))
   (if (<= t_0 -0.02)
     (* -1.0 (* im (* re (* -0.16666666666666666 re))))
     (if (<= t_0 0.054)
       (* -1.0 (* im re))
       (* (* (fma re -0.08333333333333333 0.5) re) im)))))
double code(double re, double im) {
	double t_0 = 0.5 * sin(re);
	double tmp;
	if (t_0 <= -0.02) {
		tmp = -1.0 * (im * (re * (-0.16666666666666666 * re)));
	} else if (t_0 <= 0.054) {
		tmp = -1.0 * (im * re);
	} else {
		tmp = (fma(re, -0.08333333333333333, 0.5) * re) * im;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(0.5 * sin(re))
	tmp = 0.0
	if (t_0 <= -0.02)
		tmp = Float64(-1.0 * Float64(im * Float64(re * Float64(-0.16666666666666666 * re))));
	elseif (t_0 <= 0.054)
		tmp = Float64(-1.0 * Float64(im * re));
	else
		tmp = Float64(Float64(fma(re, -0.08333333333333333, 0.5) * re) * im);
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.02], N[(-1.0 * N[(im * N[(re * N[(-0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.054], N[(-1.0 * N[(im * re), $MachinePrecision]), $MachinePrecision], N[(N[(N[(re * -0.08333333333333333 + 0.5), $MachinePrecision] * re), $MachinePrecision] * im), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;t\_0 \leq -0.02:\\
\;\;\;\;-1 \cdot \left(im \cdot \left(re \cdot \left(-0.16666666666666666 \cdot re\right)\right)\right)\\

\mathbf{elif}\;t\_0 \leq 0.054:\\
\;\;\;\;-1 \cdot \left(im \cdot re\right)\\

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


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

    1. Initial program 66.3%

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

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \left(re \cdot \color{blue}{\left(1 + -0.16666666666666666 \cdot {re}^{2}\right)}\right)\right) \]
    6. Applied rewrites25.6%

      \[\leadsto -1 \cdot \left(im \cdot \left(re \cdot \mathsf{fma}\left(re, \color{blue}{-0.16666666666666666}, 2\right)\right)\right) \]
    7. Taylor expanded in re around inf

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

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

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

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.0539999999999999994 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 13: 38.7% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.0539999999999999994 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

      \[\leadsto \color{blue}{\left(re \cdot \left(0.5 + -0.08333333333333333 \cdot {re}^{2}\right)\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites52.5%

      \[\leadsto \left(\mathsf{fma}\left(re, -0.08333333333333333, 0.5\right) \cdot \color{blue}{re}\right) \cdot \left(e^{-im} - e^{im}\right) \]
    5. Applied rewrites23.0%

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

Alternative 14: 38.7% accurate, 1.3× speedup?

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

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

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


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

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

    if 0.0539999999999999994 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re))

    1. Initial program 66.3%

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

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

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

      \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
    5. Applied rewrites33.2%

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

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

Alternative 15: 33.2% accurate, 9.0× speedup?

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

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

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

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

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

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  5. Applied rewrites33.2%

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  6. Add Preprocessing

Alternative 16: 14.9% accurate, 9.5× speedup?

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

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

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

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

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

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  5. Applied rewrites33.2%

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  6. Applied rewrites3.2%

    \[\leadsto -1 \cdot \color{blue}{re} \]
  7. Applied rewrites14.9%

    \[\leadsto -1 \cdot \left(re - re\right) \]
  8. Add Preprocessing

Alternative 17: 3.2% accurate, 15.8× speedup?

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

\\
-1 \cdot re
\end{array}
Derivation
  1. Initial program 66.3%

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

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

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

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  5. Applied rewrites33.2%

    \[\leadsto -1 \cdot \left(im \cdot \color{blue}{re}\right) \]
  6. Applied rewrites3.2%

    \[\leadsto -1 \cdot \color{blue}{re} \]
  7. Add Preprocessing

Reproduce

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