math.cos on complex, imaginary part

Percentage Accurate: 65.4% → 99.9%
Time: 15.6s
Alternatives: 11
Speedup: 1.4×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 11 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.4% 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.4%

    \[\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
    17. lower-sinh.f6499.9

      \[\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: 73.7% 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 -1 \cdot 10^{-109}:\\ \;\;\;\;\sinh \left(-im\right) \cdot re\\ \mathbf{elif}\;t\_0 \leq 200000:\\ \;\;\;\;\sin re \cdot \left(-im\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
   (if (<= t_0 -1e-109)
     (* (sinh (- im)) re)
     (if (<= t_0 200000.0) (* (sin re) (- im)) (* (expm1 im) re)))))
double code(double re, double im) {
	double t_0 = (0.5 * sin(re)) * (exp(-im) - exp(im));
	double tmp;
	if (t_0 <= -1e-109) {
		tmp = sinh(-im) * re;
	} else if (t_0 <= 200000.0) {
		tmp = sin(re) * -im;
	} else {
		tmp = expm1(im) * re;
	}
	return tmp;
}
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 <= -1e-109) {
		tmp = Math.sinh(-im) * re;
	} else if (t_0 <= 200000.0) {
		tmp = Math.sin(re) * -im;
	} else {
		tmp = Math.expm1(im) * re;
	}
	return tmp;
}
def code(re, im):
	t_0 = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
	tmp = 0
	if t_0 <= -1e-109:
		tmp = math.sinh(-im) * re
	elif t_0 <= 200000.0:
		tmp = math.sin(re) * -im
	else:
		tmp = math.expm1(im) * re
	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 <= -1e-109)
		tmp = Float64(sinh(Float64(-im)) * re);
	elseif (t_0 <= 200000.0)
		tmp = Float64(sin(re) * Float64(-im));
	else
		tmp = Float64(expm1(im) * re);
	end
	return 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, -1e-109], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision], If[LessEqual[t$95$0, 200000.0], N[(N[Sin[re], $MachinePrecision] * (-im)), $MachinePrecision], N[(N[(Exp[im] - 1), $MachinePrecision] * re), $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 -1 \cdot 10^{-109}:\\
\;\;\;\;\sinh \left(-im\right) \cdot re\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\


\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))) < -9.9999999999999999e-110

    1. Initial program 65.4%

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

        \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
        2. *-commutativeN/A

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

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

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

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

          \[\leadsto \mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right) \]
        7. associate-*r*N/A

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

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

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

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

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

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

          \[\leadsto \mathsf{neg}\left(\color{blue}{\sinh im} \cdot re\right) \]
        14. distribute-lft-neg-outN/A

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sinh im\right)\right) \cdot re} \]
      3. Applied rewrites62.1%

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

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

      1. Initial program 65.4%

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

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

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

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

          \[\leadsto -1 \cdot \left(im \cdot \sin re\right) \]
      4. Applied rewrites51.7%

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

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

          \[\leadsto \mathsf{neg}\left(im \cdot \sin re\right) \]
        3. lift-*.f64N/A

          \[\leadsto \mathsf{neg}\left(im \cdot \sin re\right) \]
        4. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\sin re \cdot im\right) \]
        5. distribute-rgt-neg-inN/A

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

          \[\leadsto \sin re \cdot \left(-im\right) \]
        7. lower-*.f6451.7

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

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

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

      1. Initial program 65.4%

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

          \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
          2. lift--.f64N/A

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

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

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
          6. exp-negN/A

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
          8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
          16. exp-negN/A

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

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

            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
          19. distribute-rgt-neg-inN/A

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

          \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
        4. Applied rewrites20.0%

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

      Alternative 3: 70.8% accurate, 1.4× speedup?

      \[\begin{array}{l} \\ \frac{\mathsf{expm1}\left(im\right)}{\frac{-1}{\sin re}} \end{array} \]
      (FPCore (re im) :precision binary64 (/ (expm1 im) (/ -1.0 (sin re))))
      double code(double re, double im) {
      	return expm1(im) / (-1.0 / sin(re));
      }
      
      public static double code(double re, double im) {
      	return Math.expm1(im) / (-1.0 / Math.sin(re));
      }
      
      def code(re, im):
      	return math.expm1(im) / (-1.0 / math.sin(re))
      
      function code(re, im)
      	return Float64(expm1(im) / Float64(-1.0 / sin(re)))
      end
      
      code[re_, im_] := N[(N[(Exp[im] - 1), $MachinePrecision] / N[(-1.0 / N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{\mathsf{expm1}\left(im\right)}{\frac{-1}{\sin re}}
      \end{array}
      
      Derivation
      1. Initial program 65.4%

        \[\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\sinh \left(-im\right) \cdot \sin re} \]
        17. lower-sinh.f6499.9

          \[\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. Step-by-step derivation
        1. lift-sinh.f64N/A

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

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

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

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

          \[\leadsto \frac{1}{\frac{2}{\color{blue}{e^{-im}} - e^{\mathsf{neg}\left(\left(-im\right)\right)}}} \cdot \sin re \]
        6. sub-to-multN/A

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

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

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

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

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

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

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

          \[\leadsto \frac{1}{\frac{2}{\color{blue}{e^{-im} - e^{im}}}} \cdot \sin re \]
        14. sub-to-multN/A

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

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

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

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

          \[\leadsto \mathsf{expm1}\left(im\right) \cdot \color{blue}{\frac{-1}{\frac{1}{\sin re}}} \]
        3. frac-2negN/A

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

          \[\leadsto \mathsf{expm1}\left(im\right) \cdot \frac{\color{blue}{1}}{\mathsf{neg}\left(\frac{1}{\sin re}\right)} \]
        5. mult-flip-revN/A

          \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(im\right)}{\mathsf{neg}\left(\frac{1}{\sin re}\right)}} \]
        6. lower-/.f64N/A

          \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(im\right)}{\mathsf{neg}\left(\frac{1}{\sin re}\right)}} \]
        7. lift-/.f64N/A

          \[\leadsto \frac{\mathsf{expm1}\left(im\right)}{\mathsf{neg}\left(\color{blue}{\frac{1}{\sin re}}\right)} \]
        8. distribute-neg-fracN/A

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

          \[\leadsto \frac{\mathsf{expm1}\left(im\right)}{\frac{\color{blue}{-1}}{\sin re}} \]
        10. lower-/.f6473.7

          \[\leadsto \frac{\mathsf{expm1}\left(im\right)}{\color{blue}{\frac{-1}{\sin re}}} \]
      8. Applied rewrites73.7%

        \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(im\right)}{\frac{-1}{\sin re}}} \]
      9. Add Preprocessing

      Alternative 4: 59.8% accurate, 1.1× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\left(\mathsf{expm1}\left(im\right) \cdot re\right) \cdot \mathsf{expm1}\left(im\right)\\ \mathbf{else}:\\ \;\;\;\;\sinh \left(-im\right) \cdot re\\ \end{array} \end{array} \]
      (FPCore (re im)
       :precision binary64
       (if (<= (* 0.5 (sin re)) -0.002)
         (* (* (expm1 im) re) (expm1 im))
         (* (sinh (- im)) re)))
      double code(double re, double im) {
      	double tmp;
      	if ((0.5 * sin(re)) <= -0.002) {
      		tmp = (expm1(im) * re) * expm1(im);
      	} else {
      		tmp = sinh(-im) * re;
      	}
      	return tmp;
      }
      
      public static double code(double re, double im) {
      	double tmp;
      	if ((0.5 * Math.sin(re)) <= -0.002) {
      		tmp = (Math.expm1(im) * re) * Math.expm1(im);
      	} else {
      		tmp = Math.sinh(-im) * re;
      	}
      	return tmp;
      }
      
      def code(re, im):
      	tmp = 0
      	if (0.5 * math.sin(re)) <= -0.002:
      		tmp = (math.expm1(im) * re) * math.expm1(im)
      	else:
      		tmp = math.sinh(-im) * re
      	return tmp
      
      function code(re, im)
      	tmp = 0.0
      	if (Float64(0.5 * sin(re)) <= -0.002)
      		tmp = Float64(Float64(expm1(im) * re) * expm1(im));
      	else
      		tmp = Float64(sinh(Float64(-im)) * re);
      	end
      	return tmp
      end
      
      code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision] * N[(Exp[im] - 1), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
      \;\;\;\;\left(\mathsf{expm1}\left(im\right) \cdot re\right) \cdot \mathsf{expm1}\left(im\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\sinh \left(-im\right) \cdot re\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

        1. Initial program 65.4%

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

            \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
            2. lift--.f64N/A

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

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

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

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
            6. exp-negN/A

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

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
            8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
            16. exp-negN/A

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

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

              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
            19. distribute-rgt-neg-inN/A

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

            \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
          4. Applied rewrites20.9%

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

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

          1. Initial program 65.4%

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

              \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
              2. *-commutativeN/A

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

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

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

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

                \[\leadsto \mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right) \]
              7. associate-*r*N/A

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

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

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

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

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

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

                \[\leadsto \mathsf{neg}\left(\color{blue}{\sinh im} \cdot re\right) \]
              14. distribute-lft-neg-outN/A

                \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sinh im\right)\right) \cdot re} \]
            3. Applied rewrites62.1%

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

          Alternative 5: 59.5% accurate, 1.1× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}\\ \mathbf{else}:\\ \;\;\;\;\sinh \left(-im\right) \cdot re\\ \end{array} \end{array} \]
          (FPCore (re im)
           :precision binary64
           (if (<= (* 0.5 (sin re)) -0.002)
             (/ (* (expm1 im) re) 4.0)
             (* (sinh (- im)) re)))
          double code(double re, double im) {
          	double tmp;
          	if ((0.5 * sin(re)) <= -0.002) {
          		tmp = (expm1(im) * re) / 4.0;
          	} else {
          		tmp = sinh(-im) * re;
          	}
          	return tmp;
          }
          
          public static double code(double re, double im) {
          	double tmp;
          	if ((0.5 * Math.sin(re)) <= -0.002) {
          		tmp = (Math.expm1(im) * re) / 4.0;
          	} else {
          		tmp = Math.sinh(-im) * re;
          	}
          	return tmp;
          }
          
          def code(re, im):
          	tmp = 0
          	if (0.5 * math.sin(re)) <= -0.002:
          		tmp = (math.expm1(im) * re) / 4.0
          	else:
          		tmp = math.sinh(-im) * re
          	return tmp
          
          function code(re, im)
          	tmp = 0.0
          	if (Float64(0.5 * sin(re)) <= -0.002)
          		tmp = Float64(Float64(expm1(im) * re) / 4.0);
          	else
          		tmp = Float64(sinh(Float64(-im)) * re);
          	end
          	return tmp
          end
          
          code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision] / 4.0), $MachinePrecision], N[(N[Sinh[(-im)], $MachinePrecision] * re), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
          \;\;\;\;\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}\\
          
          \mathbf{else}:\\
          \;\;\;\;\sinh \left(-im\right) \cdot re\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

            1. Initial program 65.4%

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

                \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                2. lift--.f64N/A

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

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

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                6. exp-negN/A

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                16. exp-negN/A

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

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

                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                19. distribute-rgt-neg-inN/A

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

                \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
              4. Applied rewrites20.0%

                \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}} \]

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

              1. Initial program 65.4%

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

                  \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                  2. *-commutativeN/A

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

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

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

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

                    \[\leadsto \mathsf{neg}\left(\left(e^{im} - e^{-im}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot re\right)}\right) \]
                  7. associate-*r*N/A

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

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

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

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

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

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

                    \[\leadsto \mathsf{neg}\left(\color{blue}{\sinh im} \cdot re\right) \]
                  14. distribute-lft-neg-outN/A

                    \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\sinh im\right)\right) \cdot re} \]
                3. Applied rewrites62.1%

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

              Alternative 6: 43.5% accurate, 1.2× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}\\ \mathbf{else}:\\ \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\ \end{array} \end{array} \]
              (FPCore (re im)
               :precision binary64
               (if (<= (* 0.5 (sin re)) -0.002)
                 (/ (* (expm1 im) re) 4.0)
                 (* (- re) (expm1 im))))
              double code(double re, double im) {
              	double tmp;
              	if ((0.5 * sin(re)) <= -0.002) {
              		tmp = (expm1(im) * re) / 4.0;
              	} else {
              		tmp = -re * expm1(im);
              	}
              	return tmp;
              }
              
              public static double code(double re, double im) {
              	double tmp;
              	if ((0.5 * Math.sin(re)) <= -0.002) {
              		tmp = (Math.expm1(im) * re) / 4.0;
              	} else {
              		tmp = -re * Math.expm1(im);
              	}
              	return tmp;
              }
              
              def code(re, im):
              	tmp = 0
              	if (0.5 * math.sin(re)) <= -0.002:
              		tmp = (math.expm1(im) * re) / 4.0
              	else:
              		tmp = -re * math.expm1(im)
              	return tmp
              
              function code(re, im)
              	tmp = 0.0
              	if (Float64(0.5 * sin(re)) <= -0.002)
              		tmp = Float64(Float64(expm1(im) * re) / 4.0);
              	else
              		tmp = Float64(Float64(-re) * expm1(im));
              	end
              	return tmp
              end
              
              code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision] / 4.0), $MachinePrecision], N[((-re) * N[(Exp[im] - 1), $MachinePrecision]), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
              \;\;\;\;\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}\\
              
              \mathbf{else}:\\
              \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

                1. Initial program 65.4%

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

                    \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                    2. lift--.f64N/A

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

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

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

                      \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                    6. exp-negN/A

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

                      \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                    8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                      \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                    16. exp-negN/A

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

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

                      \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                    19. distribute-rgt-neg-inN/A

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

                    \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                  4. Applied rewrites20.0%

                    \[\leadsto \color{blue}{\frac{\mathsf{expm1}\left(im\right) \cdot re}{4}} \]

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

                  1. Initial program 65.4%

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

                      \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                      2. lift--.f64N/A

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

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

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

                        \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                      6. exp-negN/A

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

                        \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                      8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                        \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                      16. exp-negN/A

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

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

                        \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                      19. distribute-rgt-neg-inN/A

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

                      \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                    4. Applied rewrites43.4%

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

                  Alternative 7: 43.5% accurate, 1.2× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\left(\mathsf{expm1}\left(im\right) \cdot re\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\ \end{array} \end{array} \]
                  (FPCore (re im)
                   :precision binary64
                   (if (<= (* 0.5 (sin re)) -0.002)
                     (* (* (expm1 im) re) 0.5)
                     (* (- re) (expm1 im))))
                  double code(double re, double im) {
                  	double tmp;
                  	if ((0.5 * sin(re)) <= -0.002) {
                  		tmp = (expm1(im) * re) * 0.5;
                  	} else {
                  		tmp = -re * expm1(im);
                  	}
                  	return tmp;
                  }
                  
                  public static double code(double re, double im) {
                  	double tmp;
                  	if ((0.5 * Math.sin(re)) <= -0.002) {
                  		tmp = (Math.expm1(im) * re) * 0.5;
                  	} else {
                  		tmp = -re * Math.expm1(im);
                  	}
                  	return tmp;
                  }
                  
                  def code(re, im):
                  	tmp = 0
                  	if (0.5 * math.sin(re)) <= -0.002:
                  		tmp = (math.expm1(im) * re) * 0.5
                  	else:
                  		tmp = -re * math.expm1(im)
                  	return tmp
                  
                  function code(re, im)
                  	tmp = 0.0
                  	if (Float64(0.5 * sin(re)) <= -0.002)
                  		tmp = Float64(Float64(expm1(im) * re) * 0.5);
                  	else
                  		tmp = Float64(Float64(-re) * expm1(im));
                  	end
                  	return tmp
                  end
                  
                  code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision] * 0.5), $MachinePrecision], N[((-re) * N[(Exp[im] - 1), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
                  \;\;\;\;\left(\mathsf{expm1}\left(im\right) \cdot re\right) \cdot 0.5\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

                    1. Initial program 65.4%

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

                        \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                        2. lift--.f64N/A

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

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

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

                          \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                        6. exp-negN/A

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

                          \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                        8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                          \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                        16. exp-negN/A

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

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

                          \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                        19. distribute-rgt-neg-inN/A

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

                        \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                      4. Applied rewrites20.0%

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

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

                      1. Initial program 65.4%

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

                          \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                          2. lift--.f64N/A

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

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

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

                            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                          6. exp-negN/A

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

                            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                          8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                          16. exp-negN/A

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

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

                            \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                          19. distribute-rgt-neg-inN/A

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

                          \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                        4. Applied rewrites43.4%

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

                      Alternative 8: 43.5% accurate, 1.2× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\ \mathbf{else}:\\ \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\ \end{array} \end{array} \]
                      (FPCore (re im)
                       :precision binary64
                       (if (<= (* 0.5 (sin re)) -0.002) (* (expm1 im) re) (* (- re) (expm1 im))))
                      double code(double re, double im) {
                      	double tmp;
                      	if ((0.5 * sin(re)) <= -0.002) {
                      		tmp = expm1(im) * re;
                      	} else {
                      		tmp = -re * expm1(im);
                      	}
                      	return tmp;
                      }
                      
                      public static double code(double re, double im) {
                      	double tmp;
                      	if ((0.5 * Math.sin(re)) <= -0.002) {
                      		tmp = Math.expm1(im) * re;
                      	} else {
                      		tmp = -re * Math.expm1(im);
                      	}
                      	return tmp;
                      }
                      
                      def code(re, im):
                      	tmp = 0
                      	if (0.5 * math.sin(re)) <= -0.002:
                      		tmp = math.expm1(im) * re
                      	else:
                      		tmp = -re * math.expm1(im)
                      	return tmp
                      
                      function code(re, im)
                      	tmp = 0.0
                      	if (Float64(0.5 * sin(re)) <= -0.002)
                      		tmp = Float64(expm1(im) * re);
                      	else
                      		tmp = Float64(Float64(-re) * expm1(im));
                      	end
                      	return tmp
                      end
                      
                      code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision], N[((-re) * N[(Exp[im] - 1), $MachinePrecision]), $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
                      \;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\
                      
                      \mathbf{else}:\\
                      \;\;\;\;\left(-re\right) \cdot \mathsf{expm1}\left(im\right)\\
                      
                      
                      \end{array}
                      \end{array}
                      
                      Derivation
                      1. Split input into 2 regimes
                      2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

                        1. Initial program 65.4%

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

                            \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                            2. lift--.f64N/A

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

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

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

                              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                            6. exp-negN/A

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

                              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                            8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                            16. exp-negN/A

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

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

                              \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                            19. distribute-rgt-neg-inN/A

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

                            \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                          4. Applied rewrites20.0%

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

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

                          1. Initial program 65.4%

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

                              \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                              2. lift--.f64N/A

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

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

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

                                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                              6. exp-negN/A

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

                                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                              8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                              16. exp-negN/A

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

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

                                \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                              19. distribute-rgt-neg-inN/A

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

                              \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                            4. Applied rewrites43.4%

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

                          Alternative 9: 32.4% accurate, 1.3× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\ \;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\ \mathbf{else}:\\ \;\;\;\;-re \cdot im\\ \end{array} \end{array} \]
                          (FPCore (re im)
                           :precision binary64
                           (if (<= (* 0.5 (sin re)) -0.002) (* (expm1 im) re) (- (* re im))))
                          double code(double re, double im) {
                          	double tmp;
                          	if ((0.5 * sin(re)) <= -0.002) {
                          		tmp = expm1(im) * re;
                          	} else {
                          		tmp = -(re * im);
                          	}
                          	return tmp;
                          }
                          
                          public static double code(double re, double im) {
                          	double tmp;
                          	if ((0.5 * Math.sin(re)) <= -0.002) {
                          		tmp = Math.expm1(im) * re;
                          	} else {
                          		tmp = -(re * im);
                          	}
                          	return tmp;
                          }
                          
                          def code(re, im):
                          	tmp = 0
                          	if (0.5 * math.sin(re)) <= -0.002:
                          		tmp = math.expm1(im) * re
                          	else:
                          		tmp = -(re * im)
                          	return tmp
                          
                          function code(re, im)
                          	tmp = 0.0
                          	if (Float64(0.5 * sin(re)) <= -0.002)
                          		tmp = Float64(expm1(im) * re);
                          	else
                          		tmp = Float64(-Float64(re * im));
                          	end
                          	return tmp
                          end
                          
                          code[re_, im_] := If[LessEqual[N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision], -0.002], N[(N[(Exp[im] - 1), $MachinePrecision] * re), $MachinePrecision], (-N[(re * im), $MachinePrecision])]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          \mathbf{if}\;0.5 \cdot \sin re \leq -0.002:\\
                          \;\;\;\;\mathsf{expm1}\left(im\right) \cdot re\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;-re \cdot im\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -2e-3

                            1. Initial program 65.4%

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

                                \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                                2. lift--.f64N/A

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

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

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

                                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                                6. exp-negN/A

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

                                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                                8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                                16. exp-negN/A

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

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

                                  \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                                19. distribute-rgt-neg-inN/A

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

                                \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                              4. Applied rewrites20.0%

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

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

                              1. Initial program 65.4%

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

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

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

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

                                  \[\leadsto -1 \cdot \left(im \cdot \sin re\right) \]
                              4. Applied rewrites51.7%

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

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

                                  \[\leadsto -1 \cdot \left(im \cdot re\right) \]
                              7. Applied rewrites31.9%

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

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

                                  \[\leadsto \mathsf{neg}\left(im \cdot re\right) \]
                                3. lower-neg.f6431.9

                                  \[\leadsto -im \cdot re \]
                                4. lift-*.f64N/A

                                  \[\leadsto -im \cdot re \]
                                5. *-commutativeN/A

                                  \[\leadsto -re \cdot im \]
                                6. lower-*.f6431.9

                                  \[\leadsto -re \cdot im \]
                              9. Applied rewrites31.9%

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

                            Alternative 10: 32.3% accurate, 1.4× speedup?

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

                              1. Initial program 65.4%

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

                                  \[\leadsto \left(0.5 \cdot \color{blue}{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 re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
                                  2. lift--.f64N/A

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

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

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

                                    \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - e^{\color{blue}{\mathsf{neg}\left(im\right)}}\right)\right)\right) \]
                                  6. exp-negN/A

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

                                    \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\left(e^{im} - \frac{1}{\color{blue}{e^{im}}}\right)\right)\right) \]
                                  8. sub-to-fraction-revN/A

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

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

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

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

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

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

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

                                    \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \frac{1}{\color{blue}{e^{im}}}\right)\right) \]
                                  16. exp-negN/A

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

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

                                    \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \left(\mathsf{neg}\left(\mathsf{expm1}\left(im + im\right) \cdot \color{blue}{e^{-im}}\right)\right) \]
                                  19. distribute-rgt-neg-inN/A

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

                                  \[\leadsto \color{blue}{\left(\left(re \cdot 0.5\right) \cdot \mathsf{expm1}\left(im + im\right)\right) \cdot \left(-e^{-im}\right)} \]
                                4. Applied rewrites20.0%

                                  \[\leadsto \color{blue}{\left(\mathsf{expm1}\left(im\right) \cdot re\right) \cdot 2} \]
                                5. Taylor expanded in im around 0

                                  \[\leadsto \left(\color{blue}{im} \cdot re\right) \cdot 2 \]
                                6. Step-by-step derivation
                                  1. Applied rewrites20.3%

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

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

                                  1. Initial program 65.4%

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

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

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

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

                                      \[\leadsto -1 \cdot \left(im \cdot \sin re\right) \]
                                  4. Applied rewrites51.7%

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

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

                                      \[\leadsto -1 \cdot \left(im \cdot re\right) \]
                                  7. Applied rewrites31.9%

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

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

                                      \[\leadsto \mathsf{neg}\left(im \cdot re\right) \]
                                    3. lower-neg.f6431.9

                                      \[\leadsto -im \cdot re \]
                                    4. lift-*.f64N/A

                                      \[\leadsto -im \cdot re \]
                                    5. *-commutativeN/A

                                      \[\leadsto -re \cdot im \]
                                    6. lower-*.f6431.9

                                      \[\leadsto -re \cdot im \]
                                  9. Applied rewrites31.9%

                                    \[\leadsto \color{blue}{-re \cdot im} \]
                                7. Recombined 2 regimes into one program.
                                8. Add Preprocessing

                                Alternative 11: 31.9% accurate, 12.7× speedup?

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

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

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

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

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

                                    \[\leadsto -1 \cdot \left(im \cdot \sin re\right) \]
                                4. Applied rewrites51.7%

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

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

                                    \[\leadsto -1 \cdot \left(im \cdot re\right) \]
                                7. Applied rewrites31.9%

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

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

                                    \[\leadsto \mathsf{neg}\left(im \cdot re\right) \]
                                  3. lower-neg.f6431.9

                                    \[\leadsto -im \cdot re \]
                                  4. lift-*.f64N/A

                                    \[\leadsto -im \cdot re \]
                                  5. *-commutativeN/A

                                    \[\leadsto -re \cdot im \]
                                  6. lower-*.f6431.9

                                    \[\leadsto -re \cdot im \]
                                9. Applied rewrites31.9%

                                  \[\leadsto \color{blue}{-re \cdot im} \]
                                10. Add Preprocessing

                                Reproduce

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