math.cos on complex, imaginary part

Percentage Accurate: 65.2% → 99.9%
Time: 4.2s
Alternatives: 10
Speedup: 1.3×

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 10 alternatives:

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

Initial Program: 65.2% 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.3× speedup?

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

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

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
    3. associate-*l*N/A

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
    4. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
    5. associate-*l*N/A

      \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
    6. lift--.f64N/A

      \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
    7. sub-negate-revN/A

      \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
    8. distribute-lft-neg-outN/A

      \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
    9. metadata-evalN/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
    10. mult-flipN/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
    11. lift-exp.f64N/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
    12. lift-exp.f64N/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
    13. lift-neg.f64N/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
    14. sinh-defN/A

      \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
    15. sinh-negN/A

      \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
    16. lift-neg.f64N/A

      \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
    17. *-commutativeN/A

      \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    18. lower-*.f64N/A

      \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
  3. Applied rewrites99.9%

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

Alternative 2: 86.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-216}:\\ \;\;\;\;\frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{re}}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\sin re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;\sinh \left(-im\right) \cdot \left(re \cdot \left(1 + -0.16666666666666666 \cdot {re}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
   (if (<= t_0 -2e-216)
     (/ 1.0 (* (/ -0.5 (sinh im)) (/ 2.0 re)))
     (if (<= t_0 5e-8)
       (* (sin re) (- im))
       (*
        (sinh (- im))
        (* re (+ 1.0 (* -0.16666666666666666 (pow re 2.0)))))))))
double code(double re, double im) {
	double t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
	double tmp;
	if (t_0 <= -2e-216) {
		tmp = 1.0 / ((-0.5 / sinh(im)) * (2.0 / re));
	} else if (t_0 <= 5e-8) {
		tmp = sin(re) * -im;
	} else {
		tmp = sinh(-im) * (re * (1.0 + (-0.16666666666666666 * pow(re, 2.0))));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
    if (t_0 <= (-2d-216)) then
        tmp = 1.0d0 / (((-0.5d0) / sinh(im)) * (2.0d0 / re))
    else if (t_0 <= 5d-8) then
        tmp = sin(re) * -im
    else
        tmp = sinh(-im) * (re * (1.0d0 + ((-0.16666666666666666d0) * (re ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
	double tmp;
	if (t_0 <= -2e-216) {
		tmp = 1.0 / ((-0.5 / Math.sinh(im)) * (2.0 / re));
	} else if (t_0 <= 5e-8) {
		tmp = Math.sin(re) * -im;
	} else {
		tmp = Math.sinh(-im) * (re * (1.0 + (-0.16666666666666666 * Math.pow(re, 2.0))));
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
	tmp = 0
	if t_0 <= -2e-216:
		tmp = 1.0 / ((-0.5 / math.sinh(im)) * (2.0 / re))
	elif t_0 <= 5e-8:
		tmp = math.sin(re) * -im
	else:
		tmp = math.sinh(-im) * (re * (1.0 + (-0.16666666666666666 * math.pow(re, 2.0))))
	return tmp
function code(re, im)
	t_0 = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= -2e-216)
		tmp = Float64(1.0 / Float64(Float64(-0.5 / sinh(im)) * Float64(2.0 / re)));
	elseif (t_0 <= 5e-8)
		tmp = Float64(sin(re) * Float64(-im));
	else
		tmp = Float64(sinh(Float64(-im)) * Float64(re * Float64(1.0 + Float64(-0.16666666666666666 * (re ^ 2.0)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
	tmp = 0.0;
	if (t_0 <= -2e-216)
		tmp = 1.0 / ((-0.5 / sinh(im)) * (2.0 / re));
	elseif (t_0 <= 5e-8)
		tmp = sin(re) * -im;
	else
		tmp = sinh(-im) * (re * (1.0 + (-0.16666666666666666 * (re ^ 2.0))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-216], N[(1.0 / N[(N[(-0.5 / N[Sinh[im], $MachinePrecision]), $MachinePrecision] * N[(2.0 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e-8], N[(N[Sin[re], $MachinePrecision] * (-im)), $MachinePrecision], N[(N[Sinh[(-im)], $MachinePrecision] * N[(re * N[(1.0 + N[(-0.16666666666666666 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{else}:\\
\;\;\;\;\sinh \left(-im\right) \cdot \left(re \cdot \left(1 + -0.16666666666666666 \cdot {re}^{2}\right)\right)\\


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

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift--.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(e^{-im} - e^{im}\right)} \]
      3. flip--N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}} \]
      4. div-flipN/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      5. mult-flip-revN/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      7. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sin re}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      10. div-flipN/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\color{blue}{\frac{1}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}}}} \]
      11. flip--N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      12. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      13. lower-/.f6465.2

        \[\leadsto \frac{\sin re \cdot 0.5}{\color{blue}{\frac{1}{e^{-im} - e^{im}}}} \]
      14. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      15. sub-negate-revN/A

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

      \[\leadsto \color{blue}{\frac{\sin re \cdot 0.5}{\frac{1}{-2 \cdot \sinh im}}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin re \cdot \frac{1}{2}}{\frac{1}{-2 \cdot \sinh im}}} \]
      2. div-flipN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot 0.5}}} \]
      5. lift-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{1}{\frac{\frac{1}{\color{blue}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      7. associate-/r*N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      8. lower-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      9. metadata-eval99.2

        \[\leadsto \frac{1}{\frac{\frac{\color{blue}{-0.5}}{\sinh im}}{\sin re \cdot 0.5}} \]
    5. Applied rewrites99.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{-0.5}{\sinh im}}{\sin re \cdot 0.5}}} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\frac{-1}{2}}{\sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      2. mult-flipN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{1}{\sin re \cdot 0.5}}} \]
    7. Applied rewrites99.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{-0.5}{\sinh im} \cdot \frac{1}{\sin re \cdot 0.5}}} \]
    8. Taylor expanded in re around 0

      \[\leadsto \frac{1}{\frac{\frac{-1}{2}}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]
    9. Step-by-step derivation
      1. lower-/.f6463.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{\color{blue}{re}}} \]
    10. Applied rewrites63.2%

      \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]

    if -2.0000000000000001e-216 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 4.9999999999999998e-8

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
      7. sub-negate-revN/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
      9. metadata-evalN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      10. mult-flipN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
      11. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
      12. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
      14. sinh-defN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
      15. sinh-negN/A

        \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
      16. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
      17. *-commutativeN/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
      18. lower-*.f64N/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    3. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    5. Step-by-step derivation
      1. lower-*.f6452.3

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sin re \cdot \left(-1 \cdot im\right)} \]
      3. lower-*.f6452.3

        \[\leadsto \color{blue}{\sin re \cdot \left(-1 \cdot im\right)} \]
      4. lift-*.f64N/A

        \[\leadsto \sin re \cdot \left(-1 \cdot \color{blue}{im}\right) \]
      5. mul-1-negN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(im\right)\right) \]
      6. lower-neg.f6452.3

        \[\leadsto \sin re \cdot \left(-im\right) \]
    8. Applied rewrites52.3%

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

    if 4.9999999999999998e-8 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
      7. sub-negate-revN/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
      9. metadata-evalN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      10. mult-flipN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
      11. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
      12. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
      14. sinh-defN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
      15. sinh-negN/A

        \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
      16. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
      17. *-commutativeN/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
      18. lower-*.f64N/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    3. Applied rewrites99.9%

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

      \[\leadsto \sinh \left(-im\right) \cdot \color{blue}{\left(re \cdot \left(1 + \frac{-1}{6} \cdot {re}^{2}\right)\right)} \]
    5. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \sinh \left(-im\right) \cdot \left(re \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {re}^{2}\right)}\right) \]
      2. lower-+.f64N/A

        \[\leadsto \sinh \left(-im\right) \cdot \left(re \cdot \left(1 + \color{blue}{\frac{-1}{6} \cdot {re}^{2}}\right)\right) \]
      3. lower-*.f64N/A

        \[\leadsto \sinh \left(-im\right) \cdot \left(re \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{re}^{2}}\right)\right) \]
      4. lower-pow.f6463.2

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

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

Alternative 3: 73.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-216}:\\ \;\;\;\;\frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{re}}\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-8}:\\ \;\;\;\;\sin re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-1 \cdot im\right) \cdot \left(re \cdot \left(1 + -0.16666666666666666 \cdot {re}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
   (if (<= t_0 -2e-216)
     (/ 1.0 (* (/ -0.5 (sinh im)) (/ 2.0 re)))
     (if (<= t_0 5e-8)
       (* (sin re) (- im))
       (* (* -1.0 im) (* re (+ 1.0 (* -0.16666666666666666 (pow re 2.0)))))))))
double code(double re, double im) {
	double t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
	double tmp;
	if (t_0 <= -2e-216) {
		tmp = 1.0 / ((-0.5 / sinh(im)) * (2.0 / re));
	} else if (t_0 <= 5e-8) {
		tmp = sin(re) * -im;
	} else {
		tmp = (-1.0 * im) * (re * (1.0 + (-0.16666666666666666 * pow(re, 2.0))));
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
    if (t_0 <= (-2d-216)) then
        tmp = 1.0d0 / (((-0.5d0) / sinh(im)) * (2.0d0 / re))
    else if (t_0 <= 5d-8) then
        tmp = sin(re) * -im
    else
        tmp = ((-1.0d0) * im) * (re * (1.0d0 + ((-0.16666666666666666d0) * (re ** 2.0d0))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double t_0 = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
	double tmp;
	if (t_0 <= -2e-216) {
		tmp = 1.0 / ((-0.5 / Math.sinh(im)) * (2.0 / re));
	} else if (t_0 <= 5e-8) {
		tmp = Math.sin(re) * -im;
	} else {
		tmp = (-1.0 * im) * (re * (1.0 + (-0.16666666666666666 * Math.pow(re, 2.0))));
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
	tmp = 0
	if t_0 <= -2e-216:
		tmp = 1.0 / ((-0.5 / math.sinh(im)) * (2.0 / re))
	elif t_0 <= 5e-8:
		tmp = math.sin(re) * -im
	else:
		tmp = (-1.0 * im) * (re * (1.0 + (-0.16666666666666666 * math.pow(re, 2.0))))
	return tmp
function code(re, im)
	t_0 = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im)))
	tmp = 0.0
	if (t_0 <= -2e-216)
		tmp = Float64(1.0 / Float64(Float64(-0.5 / sinh(im)) * Float64(2.0 / re)));
	elseif (t_0 <= 5e-8)
		tmp = Float64(sin(re) * Float64(-im));
	else
		tmp = Float64(Float64(-1.0 * im) * Float64(re * Float64(1.0 + Float64(-0.16666666666666666 * (re ^ 2.0)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
	tmp = 0.0;
	if (t_0 <= -2e-216)
		tmp = 1.0 / ((-0.5 / sinh(im)) * (2.0 / re));
	elseif (t_0 <= 5e-8)
		tmp = sin(re) * -im;
	else
		tmp = (-1.0 * im) * (re * (1.0 + (-0.16666666666666666 * (re ^ 2.0))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-216], N[(1.0 / N[(N[(-0.5 / N[Sinh[im], $MachinePrecision]), $MachinePrecision] * N[(2.0 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e-8], N[(N[Sin[re], $MachinePrecision] * (-im)), $MachinePrecision], N[(N[(-1.0 * im), $MachinePrecision] * N[(re * N[(1.0 + N[(-0.16666666666666666 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift--.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(e^{-im} - e^{im}\right)} \]
      3. flip--N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}} \]
      4. div-flipN/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      5. mult-flip-revN/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      7. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sin re}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      10. div-flipN/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\color{blue}{\frac{1}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}}}} \]
      11. flip--N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      12. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      13. lower-/.f6465.2

        \[\leadsto \frac{\sin re \cdot 0.5}{\color{blue}{\frac{1}{e^{-im} - e^{im}}}} \]
      14. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      15. sub-negate-revN/A

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

      \[\leadsto \color{blue}{\frac{\sin re \cdot 0.5}{\frac{1}{-2 \cdot \sinh im}}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin re \cdot \frac{1}{2}}{\frac{1}{-2 \cdot \sinh im}}} \]
      2. div-flipN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot 0.5}}} \]
      5. lift-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{1}{\frac{\frac{1}{\color{blue}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      7. associate-/r*N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      8. lower-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      9. metadata-eval99.2

        \[\leadsto \frac{1}{\frac{\frac{\color{blue}{-0.5}}{\sinh im}}{\sin re \cdot 0.5}} \]
    5. Applied rewrites99.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{-0.5}{\sinh im}}{\sin re \cdot 0.5}}} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\frac{-1}{2}}{\sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      2. mult-flipN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{1}{\sin re \cdot 0.5}}} \]
    7. Applied rewrites99.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{-0.5}{\sinh im} \cdot \frac{1}{\sin re \cdot 0.5}}} \]
    8. Taylor expanded in re around 0

      \[\leadsto \frac{1}{\frac{\frac{-1}{2}}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]
    9. Step-by-step derivation
      1. lower-/.f6463.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{\color{blue}{re}}} \]
    10. Applied rewrites63.2%

      \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]

    if -2.0000000000000001e-216 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 4.9999999999999998e-8

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
      7. sub-negate-revN/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
      9. metadata-evalN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      10. mult-flipN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
      11. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
      12. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
      14. sinh-defN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
      15. sinh-negN/A

        \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
      16. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
      17. *-commutativeN/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
      18. lower-*.f64N/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    3. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    5. Step-by-step derivation
      1. lower-*.f6452.3

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot im\right) \cdot \sin re} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\sin re \cdot \left(-1 \cdot im\right)} \]
      3. lower-*.f6452.3

        \[\leadsto \color{blue}{\sin re \cdot \left(-1 \cdot im\right)} \]
      4. lift-*.f64N/A

        \[\leadsto \sin re \cdot \left(-1 \cdot \color{blue}{im}\right) \]
      5. mul-1-negN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(im\right)\right) \]
      6. lower-neg.f6452.3

        \[\leadsto \sin re \cdot \left(-im\right) \]
    8. Applied rewrites52.3%

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

    if 4.9999999999999998e-8 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
      7. sub-negate-revN/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
      9. metadata-evalN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      10. mult-flipN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
      11. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
      12. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
      14. sinh-defN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
      15. sinh-negN/A

        \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
      16. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
      17. *-commutativeN/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
      18. lower-*.f64N/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    3. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    5. Step-by-step derivation
      1. lower-*.f6452.3

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

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

      \[\leadsto \left(-1 \cdot im\right) \cdot \color{blue}{\left(re \cdot \left(1 + \frac{-1}{6} \cdot {re}^{2}\right)\right)} \]
    8. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {re}^{2}\right)}\right) \]
      2. lower-+.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \left(1 + \color{blue}{\frac{-1}{6} \cdot {re}^{2}}\right)\right) \]
      3. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{re}^{2}}\right)\right) \]
      4. lower-pow.f6436.8

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

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

Alternative 4: 63.2% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \leq -2 \cdot 10^{-216}:\\
\;\;\;\;\frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{re}}\\

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


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

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift--.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(e^{-im} - e^{im}\right)} \]
      3. flip--N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}} \]
      4. div-flipN/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      5. mult-flip-revN/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
      7. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sin re}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
      10. div-flipN/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\color{blue}{\frac{1}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}}}} \]
      11. flip--N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      12. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      13. lower-/.f6465.2

        \[\leadsto \frac{\sin re \cdot 0.5}{\color{blue}{\frac{1}{e^{-im} - e^{im}}}} \]
      14. lift--.f64N/A

        \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
      15. sub-negate-revN/A

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

      \[\leadsto \color{blue}{\frac{\sin re \cdot 0.5}{\frac{1}{-2 \cdot \sinh im}}} \]
    4. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin re \cdot \frac{1}{2}}{\frac{1}{-2 \cdot \sinh im}}} \]
      2. div-flipN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot 0.5}}} \]
      5. lift-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      6. lift-*.f64N/A

        \[\leadsto \frac{1}{\frac{\frac{1}{\color{blue}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      7. associate-/r*N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      8. lower-/.f64N/A

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
      9. metadata-eval99.2

        \[\leadsto \frac{1}{\frac{\frac{\color{blue}{-0.5}}{\sinh im}}{\sin re \cdot 0.5}} \]
    5. Applied rewrites99.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{\frac{-0.5}{\sinh im}}{\sin re \cdot 0.5}}} \]
    6. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\frac{-1}{2}}{\sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
      2. mult-flipN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
      4. lower-/.f6499.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{1}{\sin re \cdot 0.5}}} \]
    7. Applied rewrites99.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{-0.5}{\sinh im} \cdot \frac{1}{\sin re \cdot 0.5}}} \]
    8. Taylor expanded in re around 0

      \[\leadsto \frac{1}{\frac{\frac{-1}{2}}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]
    9. Step-by-step derivation
      1. lower-/.f6463.2

        \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{\color{blue}{re}}} \]
    10. Applied rewrites63.2%

      \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]

    if -2.0000000000000001e-216 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

    1. Initial program 65.2%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot \left(e^{-im} - e^{im}\right) \]
      3. associate-*l*N/A

        \[\leadsto \color{blue}{\frac{1}{2} \cdot \left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin re \cdot \left(e^{-im} - e^{im}\right)\right) \cdot \frac{1}{2}} \]
      5. associate-*l*N/A

        \[\leadsto \color{blue}{\sin re \cdot \left(\left(e^{-im} - e^{im}\right) \cdot \frac{1}{2}\right)} \]
      6. lift--.f64N/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(e^{-im} - e^{im}\right)} \cdot \frac{1}{2}\right) \]
      7. sub-negate-revN/A

        \[\leadsto \sin re \cdot \left(\color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)\right)} \cdot \frac{1}{2}\right) \]
      8. distribute-lft-neg-outN/A

        \[\leadsto \sin re \cdot \color{blue}{\left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \frac{1}{2}\right)\right)} \]
      9. metadata-evalN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\frac{1}{2}}\right)\right) \]
      10. mult-flipN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{e^{im} - e^{-im}}{2}}\right)\right) \]
      11. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{\color{blue}{e^{im}} - e^{-im}}{2}\right)\right) \]
      12. lift-exp.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - \color{blue}{e^{-im}}}{2}\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\frac{e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}}{2}\right)\right) \]
      14. sinh-defN/A

        \[\leadsto \sin re \cdot \left(\mathsf{neg}\left(\color{blue}{\sinh im}\right)\right) \]
      15. sinh-negN/A

        \[\leadsto \sin re \cdot \color{blue}{\sinh \left(\mathsf{neg}\left(im\right)\right)} \]
      16. lift-neg.f64N/A

        \[\leadsto \sin re \cdot \sinh \color{blue}{\left(-im\right)} \]
      17. *-commutativeN/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
      18. lower-*.f64N/A

        \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    3. Applied rewrites99.9%

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

      \[\leadsto \color{blue}{\left(-1 \cdot im\right)} \cdot \sin re \]
    5. Step-by-step derivation
      1. lower-*.f6452.3

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

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

      \[\leadsto \left(-1 \cdot im\right) \cdot \color{blue}{\left(re \cdot \left(1 + \frac{-1}{6} \cdot {re}^{2}\right)\right)} \]
    8. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {re}^{2}\right)}\right) \]
      2. lower-+.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \left(1 + \color{blue}{\frac{-1}{6} \cdot {re}^{2}}\right)\right) \]
      3. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot im\right) \cdot \left(re \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{re}^{2}}\right)\right) \]
      4. lower-pow.f6436.8

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

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

Alternative 5: 63.2% accurate, 0.7× speedup?

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

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

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


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

    1. Initial program 65.2%

      \[\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. Step-by-step derivation
      1. Applied rewrites52.5%

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

        \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\color{blue}{1} - e^{im}\right) \]
      3. Step-by-step derivation
        1. Applied rewrites34.0%

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

        if -5.0000000000000001e-4 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

        1. Initial program 65.2%

          \[\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. Step-by-step derivation
          1. Applied rewrites52.5%

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{\left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right)} \]
          3. Step-by-step derivation
            1. lower-*.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \color{blue}{\left(\frac{-1}{3} \cdot {im}^{2} - 2\right)}\right) \]
            2. lower--.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - \color{blue}{2}\right)\right) \]
            3. lower-*.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            4. lower-pow.f6454.0

              \[\leadsto \left(0.5 \cdot re\right) \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right) \]
          4. Applied rewrites54.0%

            \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
          5. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot re\right)} \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\left(re \cdot \frac{1}{2}\right)} \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            3. lower-*.f6454.0

              \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right) \]
            4. lift-*.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(im \cdot \color{blue}{\left(\frac{-1}{3} \cdot {im}^{2} - 2\right)}\right) \]
            5. *-commutativeN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} - 2\right) \cdot \color{blue}{im}\right) \]
            6. lower-*.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\left(-0.3333333333333333 \cdot {im}^{2} - 2\right) \cdot \color{blue}{im}\right) \]
            7. lift--.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} - 2\right) \cdot im\right) \]
            8. sub-flipN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            9. lift-*.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            10. *-commutativeN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot \frac{-1}{3} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            11. metadata-evalN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot \frac{-1}{3} + -2\right) \cdot im\right) \]
            12. lower-fma.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left({im}^{2}, -0.3333333333333333, -2\right) \cdot im\right) \]
            13. lift-pow.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\mathsf{fma}\left({im}^{2}, \frac{-1}{3}, -2\right) \cdot im\right) \]
            14. unpow2N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\mathsf{fma}\left(im \cdot im, \frac{-1}{3}, -2\right) \cdot im\right) \]
            15. lower-*.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left(im \cdot im, -0.3333333333333333, -2\right) \cdot im\right) \]
          6. Applied rewrites54.0%

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

        Alternative 6: 54.0% accurate, 2.4× speedup?

        \[\begin{array}{l} \\ \frac{1}{\frac{\frac{-0.5}{\sinh im}}{0.5 \cdot re}} \end{array} \]
        (FPCore (re im) :precision binary64 (/ 1.0 (/ (/ -0.5 (sinh im)) (* 0.5 re))))
        double code(double re, double im) {
        	return 1.0 / ((-0.5 / sinh(im)) / (0.5 * 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 / (((-0.5d0) / sinh(im)) / (0.5d0 * re))
        end function
        
        public static double code(double re, double im) {
        	return 1.0 / ((-0.5 / Math.sinh(im)) / (0.5 * re));
        }
        
        def code(re, im):
        	return 1.0 / ((-0.5 / math.sinh(im)) / (0.5 * re))
        
        function code(re, im)
        	return Float64(1.0 / Float64(Float64(-0.5 / sinh(im)) / Float64(0.5 * re)))
        end
        
        function tmp = code(re, im)
        	tmp = 1.0 / ((-0.5 / sinh(im)) / (0.5 * re));
        end
        
        code[re_, im_] := N[(1.0 / N[(N[(-0.5 / N[Sinh[im], $MachinePrecision]), $MachinePrecision] / N[(0.5 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \frac{1}{\frac{\frac{-0.5}{\sinh im}}{0.5 \cdot re}}
        \end{array}
        
        Derivation
        1. Initial program 65.2%

          \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
          2. lift--.f64N/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(e^{-im} - e^{im}\right)} \]
          3. flip--N/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}} \]
          4. div-flipN/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          5. mult-flip-revN/A

            \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          6. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          7. lift-*.f64N/A

            \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sin re}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          8. *-commutativeN/A

            \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          9. lower-*.f64N/A

            \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          10. div-flipN/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\color{blue}{\frac{1}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}}}} \]
          11. flip--N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          12. lift--.f64N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          13. lower-/.f6465.2

            \[\leadsto \frac{\sin re \cdot 0.5}{\color{blue}{\frac{1}{e^{-im} - e^{im}}}} \]
          14. lift--.f64N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          15. sub-negate-revN/A

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

          \[\leadsto \color{blue}{\frac{\sin re \cdot 0.5}{\frac{1}{-2 \cdot \sinh im}}} \]
        4. Step-by-step derivation
          1. lift-/.f64N/A

            \[\leadsto \color{blue}{\frac{\sin re \cdot \frac{1}{2}}{\frac{1}{-2 \cdot \sinh im}}} \]
          2. div-flipN/A

            \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
          3. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
          4. lower-/.f6499.2

            \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot 0.5}}} \]
          5. lift-/.f64N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          6. lift-*.f64N/A

            \[\leadsto \frac{1}{\frac{\frac{1}{\color{blue}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          7. associate-/r*N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          8. lower-/.f64N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          9. metadata-eval99.2

            \[\leadsto \frac{1}{\frac{\frac{\color{blue}{-0.5}}{\sinh im}}{\sin re \cdot 0.5}} \]
        5. Applied rewrites99.2%

          \[\leadsto \color{blue}{\frac{1}{\frac{\frac{-0.5}{\sinh im}}{\sin re \cdot 0.5}}} \]
        6. Taylor expanded in re around 0

          \[\leadsto \frac{1}{\frac{\frac{\frac{-1}{2}}{\sinh im}}{\color{blue}{\frac{1}{2} \cdot re}}} \]
        7. Step-by-step derivation
          1. lower-*.f6463.2

            \[\leadsto \frac{1}{\frac{\frac{-0.5}{\sinh im}}{0.5 \cdot \color{blue}{re}}} \]
        8. Applied rewrites63.2%

          \[\leadsto \frac{1}{\frac{\frac{-0.5}{\sinh im}}{\color{blue}{0.5 \cdot re}}} \]
        9. Add Preprocessing

        Alternative 7: 49.9% accurate, 2.4× speedup?

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

          \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
          2. lift--.f64N/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(e^{-im} - e^{im}\right)} \]
          3. flip--N/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}} \]
          4. div-flipN/A

            \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          5. mult-flip-revN/A

            \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          6. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\frac{1}{2} \cdot \sin re}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}}} \]
          7. lift-*.f64N/A

            \[\leadsto \frac{\color{blue}{\frac{1}{2} \cdot \sin re}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          8. *-commutativeN/A

            \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          9. lower-*.f64N/A

            \[\leadsto \frac{\color{blue}{\sin re \cdot \frac{1}{2}}}{\frac{e^{-im} + e^{im}}{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}} \]
          10. div-flipN/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\color{blue}{\frac{1}{\frac{e^{-im} \cdot e^{-im} - e^{im} \cdot e^{im}}{e^{-im} + e^{im}}}}} \]
          11. flip--N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          12. lift--.f64N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          13. lower-/.f6465.2

            \[\leadsto \frac{\sin re \cdot 0.5}{\color{blue}{\frac{1}{e^{-im} - e^{im}}}} \]
          14. lift--.f64N/A

            \[\leadsto \frac{\sin re \cdot \frac{1}{2}}{\frac{1}{\color{blue}{e^{-im} - e^{im}}}} \]
          15. sub-negate-revN/A

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

          \[\leadsto \color{blue}{\frac{\sin re \cdot 0.5}{\frac{1}{-2 \cdot \sinh im}}} \]
        4. Step-by-step derivation
          1. lift-/.f64N/A

            \[\leadsto \color{blue}{\frac{\sin re \cdot \frac{1}{2}}{\frac{1}{-2 \cdot \sinh im}}} \]
          2. div-flipN/A

            \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
          3. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{1}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
          4. lower-/.f6499.2

            \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{-2 \cdot \sinh im}}{\sin re \cdot 0.5}}} \]
          5. lift-/.f64N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          6. lift-*.f64N/A

            \[\leadsto \frac{1}{\frac{\frac{1}{\color{blue}{-2 \cdot \sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          7. associate-/r*N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          8. lower-/.f64N/A

            \[\leadsto \frac{1}{\frac{\color{blue}{\frac{\frac{1}{-2}}{\sinh im}}}{\sin re \cdot \frac{1}{2}}} \]
          9. metadata-eval99.2

            \[\leadsto \frac{1}{\frac{\frac{\color{blue}{-0.5}}{\sinh im}}{\sin re \cdot 0.5}} \]
        5. Applied rewrites99.2%

          \[\leadsto \color{blue}{\frac{1}{\frac{\frac{-0.5}{\sinh im}}{\sin re \cdot 0.5}}} \]
        6. Step-by-step derivation
          1. lift-/.f64N/A

            \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\frac{-1}{2}}{\sinh im}}{\sin re \cdot \frac{1}{2}}}} \]
          2. mult-flipN/A

            \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
          3. lower-*.f64N/A

            \[\leadsto \frac{1}{\color{blue}{\frac{\frac{-1}{2}}{\sinh im} \cdot \frac{1}{\sin re \cdot \frac{1}{2}}}} \]
          4. lower-/.f6499.2

            \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{1}{\sin re \cdot 0.5}}} \]
        7. Applied rewrites99.2%

          \[\leadsto \frac{1}{\color{blue}{\frac{-0.5}{\sinh im} \cdot \frac{1}{\sin re \cdot 0.5}}} \]
        8. Taylor expanded in re around 0

          \[\leadsto \frac{1}{\frac{\frac{-1}{2}}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]
        9. Step-by-step derivation
          1. lower-/.f6463.2

            \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \frac{2}{\color{blue}{re}}} \]
        10. Applied rewrites63.2%

          \[\leadsto \frac{1}{\frac{-0.5}{\sinh im} \cdot \color{blue}{\frac{2}{re}}} \]
        11. Add Preprocessing

        Alternative 8: 49.7% accurate, 3.5× speedup?

        \[\begin{array}{l} \\ \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left(im \cdot im, -0.3333333333333333, -2\right) \cdot im\right) \end{array} \]
        (FPCore (re im)
         :precision binary64
         (* (* re 0.5) (* (fma (* im im) -0.3333333333333333 -2.0) im)))
        double code(double re, double im) {
        	return (re * 0.5) * (fma((im * im), -0.3333333333333333, -2.0) * im);
        }
        
        function code(re, im)
        	return Float64(Float64(re * 0.5) * Float64(fma(Float64(im * im), -0.3333333333333333, -2.0) * im))
        end
        
        code[re_, im_] := N[(N[(re * 0.5), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.3333333333333333 + -2.0), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left(im \cdot im, -0.3333333333333333, -2\right) \cdot im\right)
        \end{array}
        
        Derivation
        1. Initial program 65.2%

          \[\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. Step-by-step derivation
          1. Applied rewrites52.5%

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{\left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right)} \]
          3. Step-by-step derivation
            1. lower-*.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \color{blue}{\left(\frac{-1}{3} \cdot {im}^{2} - 2\right)}\right) \]
            2. lower--.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - \color{blue}{2}\right)\right) \]
            3. lower-*.f64N/A

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            4. lower-pow.f6454.0

              \[\leadsto \left(0.5 \cdot re\right) \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right) \]
          4. Applied rewrites54.0%

            \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)} \]
          5. Step-by-step derivation
            1. lift-*.f64N/A

              \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot re\right)} \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            2. *-commutativeN/A

              \[\leadsto \color{blue}{\left(re \cdot \frac{1}{2}\right)} \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
            3. lower-*.f6454.0

              \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right) \]
            4. lift-*.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(im \cdot \color{blue}{\left(\frac{-1}{3} \cdot {im}^{2} - 2\right)}\right) \]
            5. *-commutativeN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} - 2\right) \cdot \color{blue}{im}\right) \]
            6. lower-*.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\left(-0.3333333333333333 \cdot {im}^{2} - 2\right) \cdot \color{blue}{im}\right) \]
            7. lift--.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} - 2\right) \cdot im\right) \]
            8. sub-flipN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            9. lift-*.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\frac{-1}{3} \cdot {im}^{2} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            10. *-commutativeN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot \frac{-1}{3} + \left(\mathsf{neg}\left(2\right)\right)\right) \cdot im\right) \]
            11. metadata-evalN/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot \frac{-1}{3} + -2\right) \cdot im\right) \]
            12. lower-fma.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left({im}^{2}, -0.3333333333333333, -2\right) \cdot im\right) \]
            13. lift-pow.f64N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\mathsf{fma}\left({im}^{2}, \frac{-1}{3}, -2\right) \cdot im\right) \]
            14. unpow2N/A

              \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\mathsf{fma}\left(im \cdot im, \frac{-1}{3}, -2\right) \cdot im\right) \]
            15. lower-*.f6454.0

              \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left(im \cdot im, -0.3333333333333333, -2\right) \cdot im\right) \]
          6. Applied rewrites54.0%

            \[\leadsto \color{blue}{\left(re \cdot 0.5\right) \cdot \left(\mathsf{fma}\left(im \cdot im, -0.3333333333333333, -2\right) \cdot im\right)} \]
          7. Add Preprocessing

          Alternative 9: 43.7% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \leq -0.0005:\\ \;\;\;\;\left(re \cdot 0.5\right) \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot -0.3333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(-2 \cdot im\right)\\ \end{array} \end{array} \]
          (FPCore (re im)
           :precision binary64
           (if (<= (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))) -0.0005)
             (* (* re 0.5) (* (* (* im im) im) -0.3333333333333333))
             (* (* 0.5 re) (* -2.0 im))))
          double code(double re, double im) {
          	double tmp;
          	if (((0.5 * sin(re)) * (exp(-im) - exp(im))) <= -0.0005) {
          		tmp = (re * 0.5) * (((im * im) * im) * -0.3333333333333333);
          	} else {
          		tmp = (0.5 * re) * (-2.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 * sin(re)) * (exp(-im) - exp(im))) <= (-0.0005d0)) then
                  tmp = (re * 0.5d0) * (((im * im) * im) * (-0.3333333333333333d0))
              else
                  tmp = (0.5d0 * re) * ((-2.0d0) * im)
              end if
              code = tmp
          end function
          
          public static double code(double re, double im) {
          	double tmp;
          	if (((0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im))) <= -0.0005) {
          		tmp = (re * 0.5) * (((im * im) * im) * -0.3333333333333333);
          	} else {
          		tmp = (0.5 * re) * (-2.0 * im);
          	}
          	return tmp;
          }
          
          def code(re, im):
          	tmp = 0
          	if ((0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))) <= -0.0005:
          		tmp = (re * 0.5) * (((im * im) * im) * -0.3333333333333333)
          	else:
          		tmp = (0.5 * re) * (-2.0 * im)
          	return tmp
          
          function code(re, im)
          	tmp = 0.0
          	if (Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) <= -0.0005)
          		tmp = Float64(Float64(re * 0.5) * Float64(Float64(Float64(im * im) * im) * -0.3333333333333333));
          	else
          		tmp = Float64(Float64(0.5 * re) * Float64(-2.0 * im));
          	end
          	return tmp
          end
          
          function tmp_2 = code(re, im)
          	tmp = 0.0;
          	if (((0.5 * sin(re)) * (exp(-im) - exp(im))) <= -0.0005)
          		tmp = (re * 0.5) * (((im * im) * im) * -0.3333333333333333);
          	else
          		tmp = (0.5 * re) * (-2.0 * im);
          	end
          	tmp_2 = tmp;
          end
          
          code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.0005], N[(N[(re * 0.5), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * im), $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right) \leq -0.0005:\\
          \;\;\;\;\left(re \cdot 0.5\right) \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot -0.3333333333333333\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(-2 \cdot im\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -5.0000000000000001e-4

            1. Initial program 65.2%

              \[\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. Step-by-step derivation
              1. Applied rewrites52.5%

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

                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{\left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right)} \]
              3. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \color{blue}{\left(\frac{-1}{3} \cdot {im}^{2} - 2\right)}\right) \]
                2. lower--.f64N/A

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - \color{blue}{2}\right)\right) \]
                3. lower-*.f64N/A

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(im \cdot \left(\frac{-1}{3} \cdot {im}^{2} - 2\right)\right) \]
                4. lower-pow.f6454.0

                  \[\leadsto \left(0.5 \cdot re\right) \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right) \]
              4. Applied rewrites54.0%

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

                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\frac{-1}{3} \cdot \color{blue}{{im}^{3}}\right) \]
              6. Step-by-step derivation
                1. lower-*.f64N/A

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\frac{-1}{3} \cdot {im}^{\color{blue}{3}}\right) \]
                2. lower-pow.f6442.2

                  \[\leadsto \left(0.5 \cdot re\right) \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right) \]
              7. Applied rewrites42.2%

                \[\leadsto \left(0.5 \cdot re\right) \cdot \left(-0.3333333333333333 \cdot \color{blue}{{im}^{3}}\right) \]
              8. Step-by-step derivation
                1. lift-*.f64N/A

                  \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot re\right)} \cdot \left(\frac{-1}{3} \cdot {im}^{3}\right) \]
                2. *-commutativeN/A

                  \[\leadsto \color{blue}{\left(re \cdot \frac{1}{2}\right)} \cdot \left(\frac{-1}{3} \cdot {im}^{3}\right) \]
                3. lower-*.f6442.2

                  \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \left(-0.3333333333333333 \cdot {im}^{3}\right) \]
                4. lift-*.f64N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\frac{-1}{3} \cdot {im}^{\color{blue}{3}}\right) \]
                5. *-commutativeN/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left({im}^{3} \cdot \frac{-1}{3}\right) \]
                6. lower-*.f6442.2

                  \[\leadsto \left(re \cdot 0.5\right) \cdot \left({im}^{3} \cdot -0.3333333333333333\right) \]
                7. lift-pow.f64N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left({im}^{3} \cdot \frac{-1}{3}\right) \]
                8. unpow3N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3}\right) \]
                9. unpow2N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot im\right) \cdot \frac{-1}{3}\right) \]
                10. lower-*.f64N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left({im}^{2} \cdot im\right) \cdot \frac{-1}{3}\right) \]
                11. unpow2N/A

                  \[\leadsto \left(re \cdot \frac{1}{2}\right) \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot \frac{-1}{3}\right) \]
                12. lower-*.f6442.2

                  \[\leadsto \left(re \cdot 0.5\right) \cdot \left(\left(\left(im \cdot im\right) \cdot im\right) \cdot -0.3333333333333333\right) \]
              9. Applied rewrites42.2%

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

              if -5.0000000000000001e-4 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

              1. Initial program 65.2%

                \[\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. Step-by-step derivation
                1. Applied rewrites52.5%

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{\left(-2 \cdot im\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f6433.9

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

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

              Alternative 10: 33.9% accurate, 6.3× speedup?

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

                \[\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. Step-by-step derivation
                1. Applied rewrites52.5%

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \color{blue}{\left(-2 \cdot im\right)} \]
                3. Step-by-step derivation
                  1. lower-*.f6433.9

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

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

                Reproduce

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