math.sin on complex, imaginary part

Percentage Accurate: 54.8% → 99.9%
Time: 5.2s
Alternatives: 11
Speedup: 1.3×

Specification

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

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)

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

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

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)

Alternative 1: 99.9% accurate, 1.3× speedup?

\[\sinh \left(-im\right) \cdot \cos re \]
(FPCore (re im)
  :precision binary64
  (* (sinh (- im)) (cos re)))
double code(double re, double im) {
	return sinh(-im) * cos(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) * cos(re)
end function
public static double code(double re, double im) {
	return Math.sinh(-im) * Math.cos(re);
}
def code(re, im):
	return math.sinh(-im) * math.cos(re)
function code(re, im)
	return Float64(sinh(Float64(-im)) * cos(re))
end
function tmp = code(re, im)
	tmp = sinh(-im) * cos(re);
end
code[re_, im_] := N[(N[Sinh[(-im)], $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]
\sinh \left(-im\right) \cdot \cos re
Derivation
  1. Initial program 54.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{0 - im} - e^{im}}{2}} \cdot \cos re \]
    7. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{e^{0 - im} - e^{im}}}{2} \cdot \cos re \]
    8. lift-exp.f64N/A

      \[\leadsto \frac{\color{blue}{e^{0 - im}} - e^{im}}{2} \cdot \cos re \]
    9. lift-exp.f64N/A

      \[\leadsto \frac{e^{0 - im} - \color{blue}{e^{im}}}{2} \cdot \cos re \]
    10. --rgt-identityN/A

      \[\leadsto \frac{e^{0 - im} - e^{\color{blue}{im - 0}}}{2} \cdot \cos re \]
    11. sub-negate-revN/A

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

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

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

      \[\leadsto \color{blue}{\sinh \left(0 - im\right) \cdot \cos re} \]
    15. lower-sinh.f6499.9%

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

      \[\leadsto \sinh \color{blue}{\left(0 - im\right)} \cdot \cos re \]
    17. sub0-negN/A

      \[\leadsto \sinh \color{blue}{\left(\mathsf{neg}\left(im\right)\right)} \cdot \cos re \]
    18. lower-neg.f6499.9%

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

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

Alternative 2: 99.0% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := \sinh \left(-\left|im\right|\right)\\ t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right)\\ \mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -0.0001:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;\left(-\cos re\right) \cdot \left|im\right|\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(1 + -0.5 \cdot {re}^{2}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (sinh (- (fabs im))))
       (t_1
        (*
         (* 0.5 (cos re))
         (- (exp (- 0.0 (fabs im))) (exp (fabs im))))))
  (*
   (copysign 1.0 im)
   (if (<= t_1 -0.0001)
     t_0
     (if (<= t_1 0.0)
       (* (- (cos re)) (fabs im))
       (* t_0 (+ 1.0 (* -0.5 (pow re 2.0)))))))))
double code(double re, double im) {
	double t_0 = sinh(-fabs(im));
	double t_1 = (0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)));
	double tmp;
	if (t_1 <= -0.0001) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = -cos(re) * fabs(im);
	} else {
		tmp = t_0 * (1.0 + (-0.5 * pow(re, 2.0)));
	}
	return copysign(1.0, im) * tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.sinh(-Math.abs(im));
	double t_1 = (0.5 * Math.cos(re)) * (Math.exp((0.0 - Math.abs(im))) - Math.exp(Math.abs(im)));
	double tmp;
	if (t_1 <= -0.0001) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = -Math.cos(re) * Math.abs(im);
	} else {
		tmp = t_0 * (1.0 + (-0.5 * Math.pow(re, 2.0)));
	}
	return Math.copySign(1.0, im) * tmp;
}
def code(re, im):
	t_0 = math.sinh(-math.fabs(im))
	t_1 = (0.5 * math.cos(re)) * (math.exp((0.0 - math.fabs(im))) - math.exp(math.fabs(im)))
	tmp = 0
	if t_1 <= -0.0001:
		tmp = t_0
	elif t_1 <= 0.0:
		tmp = -math.cos(re) * math.fabs(im)
	else:
		tmp = t_0 * (1.0 + (-0.5 * math.pow(re, 2.0)))
	return math.copysign(1.0, im) * tmp
function code(re, im)
	t_0 = sinh(Float64(-abs(im)))
	t_1 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - abs(im))) - exp(abs(im))))
	tmp = 0.0
	if (t_1 <= -0.0001)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = Float64(Float64(-cos(re)) * abs(im));
	else
		tmp = Float64(t_0 * Float64(1.0 + Float64(-0.5 * (re ^ 2.0))));
	end
	return Float64(copysign(1.0, im) * tmp)
end
function tmp_2 = code(re, im)
	t_0 = sinh(-abs(im));
	t_1 = (0.5 * cos(re)) * (exp((0.0 - abs(im))) - exp(abs(im)));
	tmp = 0.0;
	if (t_1 <= -0.0001)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = -cos(re) * abs(im);
	else
		tmp = t_0 * (1.0 + (-0.5 * (re ^ 2.0)));
	end
	tmp_2 = (sign(im) * abs(1.0)) * tmp;
end
code[re_, im_] := Block[{t$95$0 = N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, -0.0001], t$95$0, If[LessEqual[t$95$1, 0.0], N[((-N[Cos[re], $MachinePrecision]) * N[Abs[im], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(1.0 + N[(-0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sinh \left(-\left|im\right|\right)\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right)\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -0.0001:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 + -0.5 \cdot {re}^{2}\right)\\


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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

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

        \[\leadsto \frac{e^{-im} - e^{im}}{\color{blue}{2}} \]
      5. lift--.f64N/A

        \[\leadsto \frac{e^{-im} - e^{im}}{2} \]
      6. sub-negate-revN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)}{2} \]
      7. distribute-neg-fracN/A

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

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

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

        \[\leadsto \mathsf{neg}\left(\frac{e^{im} - e^{\mathsf{neg}\left(im\right)}}{2}\right) \]
      11. sinh-defN/A

        \[\leadsto \mathsf{neg}\left(\sinh im\right) \]
      12. sinh-negN/A

        \[\leadsto \sinh \left(\mathsf{neg}\left(im\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sinh \left(-im\right) \]
      14. lift-sinh.f6464.9%

        \[\leadsto \sinh \left(-im\right) \]
    6. Applied rewrites64.9%

      \[\leadsto \sinh \left(-im\right) \]

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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\cos re\right)\right) \cdot \color{blue}{im} \]
      7. lower-neg.f6451.5%

        \[\leadsto \left(-\cos re\right) \cdot im \]
    6. Applied rewrites51.5%

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

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

    1. Initial program 54.8%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{e^{0 - im} - e^{im}}{2}} \cdot \cos re \]
      7. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{e^{0 - im} - e^{im}}}{2} \cdot \cos re \]
      8. lift-exp.f64N/A

        \[\leadsto \frac{\color{blue}{e^{0 - im}} - e^{im}}{2} \cdot \cos re \]
      9. lift-exp.f64N/A

        \[\leadsto \frac{e^{0 - im} - \color{blue}{e^{im}}}{2} \cdot \cos re \]
      10. --rgt-identityN/A

        \[\leadsto \frac{e^{0 - im} - e^{\color{blue}{im - 0}}}{2} \cdot \cos re \]
      11. sub-negate-revN/A

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

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

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

        \[\leadsto \color{blue}{\sinh \left(0 - im\right) \cdot \cos re} \]
      15. lower-sinh.f6499.9%

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

        \[\leadsto \sinh \color{blue}{\left(0 - im\right)} \cdot \cos re \]
      17. sub0-negN/A

        \[\leadsto \sinh \color{blue}{\left(\mathsf{neg}\left(im\right)\right)} \cdot \cos re \]
      18. lower-neg.f6499.9%

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

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

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

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

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

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

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

Alternative 3: 97.0% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\left(-\cos re\right) \cdot \left|im\right|\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \left|im\right|, \frac{1}{\frac{\mathsf{fma}\left(t\_1, \left|im\right|, \left|im\right| \cdot t\_1\right)}{\left|im\right| \cdot \left|im\right|}}\right)\\


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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

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

        \[\leadsto \frac{e^{-im} - e^{im}}{\color{blue}{2}} \]
      5. lift--.f64N/A

        \[\leadsto \frac{e^{-im} - e^{im}}{2} \]
      6. sub-negate-revN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)}{2} \]
      7. distribute-neg-fracN/A

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

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

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

        \[\leadsto \mathsf{neg}\left(\frac{e^{im} - e^{\mathsf{neg}\left(im\right)}}{2}\right) \]
      11. sinh-defN/A

        \[\leadsto \mathsf{neg}\left(\sinh im\right) \]
      12. sinh-negN/A

        \[\leadsto \sinh \left(\mathsf{neg}\left(im\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sinh \left(-im\right) \]
      14. lift-sinh.f6464.9%

        \[\leadsto \sinh \left(-im\right) \]
    6. Applied rewrites64.9%

      \[\leadsto \sinh \left(-im\right) \]

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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\cos re\right)\right) \cdot \color{blue}{im} \]
      7. lower-neg.f6451.5%

        \[\leadsto \left(-\cos re\right) \cdot im \]
    6. Applied rewrites51.5%

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

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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \left(im \cdot {re}^{2}\right) \cdot \frac{1}{2}\right) \]
      4. mult-flip-revN/A

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      6. lower-unsound-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      7. lower-unsound-/.f6437.0%

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      8. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{{re}^{2} \cdot im}}\right) \]
      10. lower-*.f6437.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
    9. Applied rewrites37.0%

      \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
    10. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
      3. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{2}{re \cdot re}}{im}}\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1 + 1}{re \cdot re}}{im}}\right) \]
      5. div-addN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} + \frac{1}{re \cdot re}}{im}}\right) \]
      6. div-add-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re}}{im} + \frac{\frac{1}{re \cdot re}}{im}}\right) \]
      7. frac-addN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{im \cdot im}}\right) \]
      8. sqr-neg-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      9. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      11. lower-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      12. lower-unsound-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      14. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      15. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      16. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      17. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      18. lower-unsound-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      19. lower-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      20. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      21. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      22. sqr-neg-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{im \cdot im}}\right) \]
      23. lower-*.f6436.8%

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{im \cdot im}}\right) \]
    11. Applied rewrites36.8%

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

Alternative 4: 76.3% accurate, 0.6× speedup?

\[\begin{array}{l} t_0 := \frac{1}{re \cdot re}\\ \mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right) \leq 0:\\ \;\;\;\;\sinh \left(-\left|im\right|\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-1, \left|im\right|, \frac{1}{\frac{\mathsf{fma}\left(t\_0, \left|im\right|, \left|im\right| \cdot t\_0\right)}{\left|im\right| \cdot \left|im\right|}}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (/ 1.0 (* re re))))
  (*
   (copysign 1.0 im)
   (if (<=
        (*
         (* 0.5 (cos re))
         (- (exp (- 0.0 (fabs im))) (exp (fabs im))))
        0.0)
     (sinh (- (fabs im)))
     (fma
      -1.0
      (fabs im)
      (/
       1.0
       (/
        (fma t_0 (fabs im) (* (fabs im) t_0))
        (* (fabs im) (fabs im)))))))))
double code(double re, double im) {
	double t_0 = 1.0 / (re * re);
	double tmp;
	if (((0.5 * cos(re)) * (exp((0.0 - fabs(im))) - exp(fabs(im)))) <= 0.0) {
		tmp = sinh(-fabs(im));
	} else {
		tmp = fma(-1.0, fabs(im), (1.0 / (fma(t_0, fabs(im), (fabs(im) * t_0)) / (fabs(im) * fabs(im)))));
	}
	return copysign(1.0, im) * tmp;
}
function code(re, im)
	t_0 = Float64(1.0 / Float64(re * re))
	tmp = 0.0
	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - abs(im))) - exp(abs(im)))) <= 0.0)
		tmp = sinh(Float64(-abs(im)));
	else
		tmp = fma(-1.0, abs(im), Float64(1.0 / Float64(fma(t_0, abs(im), Float64(abs(im) * t_0)) / Float64(abs(im) * abs(im)))));
	end
	return Float64(copysign(1.0, im) * tmp)
end
code[re_, im_] := Block[{t$95$0 = N[(1.0 / N[(re * re), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision], N[(-1.0 * N[Abs[im], $MachinePrecision] + N[(1.0 / N[(N[(t$95$0 * N[Abs[im], $MachinePrecision] + N[(N[Abs[im], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(N[Abs[im], $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_0 := \frac{1}{re \cdot re}\\
\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - \left|im\right|} - e^{\left|im\right|}\right) \leq 0:\\
\;\;\;\;\sinh \left(-\left|im\right|\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \left|im\right|, \frac{1}{\frac{\mathsf{fma}\left(t\_0, \left|im\right|, \left|im\right| \cdot t\_0\right)}{\left|im\right| \cdot \left|im\right|}}\right)\\


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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

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

        \[\leadsto \frac{e^{-im} - e^{im}}{\color{blue}{2}} \]
      5. lift--.f64N/A

        \[\leadsto \frac{e^{-im} - e^{im}}{2} \]
      6. sub-negate-revN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)}{2} \]
      7. distribute-neg-fracN/A

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

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

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

        \[\leadsto \mathsf{neg}\left(\frac{e^{im} - e^{\mathsf{neg}\left(im\right)}}{2}\right) \]
      11. sinh-defN/A

        \[\leadsto \mathsf{neg}\left(\sinh im\right) \]
      12. sinh-negN/A

        \[\leadsto \sinh \left(\mathsf{neg}\left(im\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sinh \left(-im\right) \]
      14. lift-sinh.f6464.9%

        \[\leadsto \sinh \left(-im\right) \]
    6. Applied rewrites64.9%

      \[\leadsto \sinh \left(-im\right) \]

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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \left(im \cdot {re}^{2}\right) \cdot \frac{1}{2}\right) \]
      4. mult-flip-revN/A

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      6. lower-unsound-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      7. lower-unsound-/.f6437.0%

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{im \cdot {re}^{2}}}\right) \]
      8. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{{re}^{2} \cdot im}}\right) \]
      10. lower-*.f6437.0%

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
    9. Applied rewrites37.0%

      \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
    10. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
      2. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{2}{\left(re \cdot re\right) \cdot im}}\right) \]
      3. associate-/r*N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{2}{re \cdot re}}{im}}\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1 + 1}{re \cdot re}}{im}}\right) \]
      5. div-addN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} + \frac{1}{re \cdot re}}{im}}\right) \]
      6. div-add-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re}}{im} + \frac{\frac{1}{re \cdot re}}{im}}\right) \]
      7. frac-addN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{im \cdot im}}\right) \]
      8. sqr-neg-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      9. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      10. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      11. lower-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      12. lower-unsound-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      13. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\frac{1}{re \cdot re} \cdot im + im \cdot \frac{1}{re \cdot re}}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      14. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      15. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      16. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      17. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      18. lower-unsound-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      19. lower-*.f32N/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      20. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(-1 \cdot im\right)}}\right) \]
      21. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)}}\right) \]
      22. sqr-neg-revN/A

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{im \cdot im}}\right) \]
      23. lower-*.f6436.8%

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{\frac{\mathsf{fma}\left(\frac{1}{re \cdot re}, im, im \cdot \frac{1}{re \cdot re}\right)}{im \cdot im}}\right) \]
    11. Applied rewrites36.8%

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

Alternative 5: 75.9% accurate, 0.7× speedup?

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

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


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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

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

        \[\leadsto \frac{e^{-im} - e^{im}}{\color{blue}{2}} \]
      5. lift--.f64N/A

        \[\leadsto \frac{e^{-im} - e^{im}}{2} \]
      6. sub-negate-revN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)}{2} \]
      7. distribute-neg-fracN/A

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

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

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

        \[\leadsto \mathsf{neg}\left(\frac{e^{im} - e^{\mathsf{neg}\left(im\right)}}{2}\right) \]
      11. sinh-defN/A

        \[\leadsto \mathsf{neg}\left(\sinh im\right) \]
      12. sinh-negN/A

        \[\leadsto \sinh \left(\mathsf{neg}\left(im\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sinh \left(-im\right) \]
      14. lift-sinh.f6464.9%

        \[\leadsto \sinh \left(-im\right) \]
    6. Applied rewrites64.9%

      \[\leadsto \sinh \left(-im\right) \]

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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

      \[\leadsto \mathsf{fma}\left(-1, \color{blue}{im}, 0.5 \cdot \left(im \cdot {re}^{2}\right)\right) \]
    8. Step-by-step derivation
      1. rem-square-sqrtN/A

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right)\right) \]
      4. lower-*.f6437.5%

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right)\right) \]
      7. lower-*.f6437.5%

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right) \]
      10. lower-*.f6437.5%

        \[\leadsto \mathsf{fma}\left(-1, im, 0.5 \cdot \left(im \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right)\right) \]
    9. Applied rewrites37.5%

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

Alternative 6: 74.6% accurate, 1.2× speedup?

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

\mathbf{else}:\\
\;\;\;\;\sinh \left(-im\right)\\


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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) + -1 \cdot im \]
      6. associate-*r*N/A

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot {re}^{2} + -1 \cdot im \]
      7. lift-pow.f64N/A

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

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot \left(re \cdot re\right) + -1 \cdot im \]
      9. associate-*r*N/A

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

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      12. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -1 \cdot im\right) \]
      14. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, -1 \cdot im\right) \]
      15. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, \mathsf{neg}\left(im\right)\right) \]
      16. lower-neg.f6437.0%

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -im\right) \]
    9. Applied rewrites37.0%

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

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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

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

        \[\leadsto \frac{e^{-im} - e^{im}}{\color{blue}{2}} \]
      5. lift--.f64N/A

        \[\leadsto \frac{e^{-im} - e^{im}}{2} \]
      6. sub-negate-revN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(e^{im} - e^{-im}\right)\right)}{2} \]
      7. distribute-neg-fracN/A

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

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

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

        \[\leadsto \mathsf{neg}\left(\frac{e^{im} - e^{\mathsf{neg}\left(im\right)}}{2}\right) \]
      11. sinh-defN/A

        \[\leadsto \mathsf{neg}\left(\sinh im\right) \]
      12. sinh-negN/A

        \[\leadsto \sinh \left(\mathsf{neg}\left(im\right)\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \sinh \left(-im\right) \]
      14. lift-sinh.f6464.9%

        \[\leadsto \sinh \left(-im\right) \]
    6. Applied rewrites64.9%

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

Alternative 7: 63.2% accurate, 1.3× speedup?

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

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


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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) + -1 \cdot im \]
      6. associate-*r*N/A

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot {re}^{2} + -1 \cdot im \]
      7. lift-pow.f64N/A

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

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot \left(re \cdot re\right) + -1 \cdot im \]
      9. associate-*r*N/A

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

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      12. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -1 \cdot im\right) \]
      14. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, -1 \cdot im\right) \]
      15. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, \mathsf{neg}\left(im\right)\right) \]
      16. lower-neg.f6437.0%

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -im\right) \]
    9. Applied rewrites37.0%

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

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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left|e^{-im}\right| - e^{im}\right) \]
      4. rem-sqrt-square-revN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{-im} \cdot e^{-im}} - e^{im}\right) \]
      8. exp-lft-sqr-revN/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(im\right)\right) \cdot 2}} - e^{im}\right) \]
      10. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(im \cdot 2\right)}} - e^{im}\right) \]
      11. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      12. count-2N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      14. lower-exp.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      16. count-2N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      18. lower-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      19. metadata-eval40.7%

        \[\leadsto 0.5 \cdot \left(\sqrt{e^{-2 \cdot im}} - e^{im}\right) \]
    6. Applied rewrites40.7%

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

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

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

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

        \[\leadsto im \cdot \left(\frac{-1}{6} \cdot {im}^{2} - 1\right) \]
      4. lower-pow.f6453.5%

        \[\leadsto im \cdot \left(-0.16666666666666666 \cdot {im}^{2} - 1\right) \]
    9. Applied rewrites53.5%

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

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

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

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

        \[\leadsto im \cdot \left(\frac{-1}{6} \cdot {im}^{2} + -1\right) \]
      5. distribute-rgt-inN/A

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{6} \cdot {im}^{2}, im, -1 \cdot im\right) \]
      7. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{6} \cdot {im}^{2}, im, -1 \cdot im\right) \]
      8. lift-pow.f64N/A

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

        \[\leadsto \mathsf{fma}\left(\frac{-1}{6} \cdot \left(im \cdot im\right), im, -1 \cdot im\right) \]
      10. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{-1}{6} \cdot im\right) \cdot im, im, -1 \cdot im\right) \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{-1}{6} \cdot im\right) \cdot im, im, -1 \cdot im\right) \]
      12. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{-1}{6} \cdot im\right) \cdot im, im, -1 \cdot im\right) \]
      13. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{-1}{6} \cdot im\right) \cdot im, im, \mathsf{neg}\left(im\right)\right) \]
      14. lower-neg.f6453.5%

        \[\leadsto \mathsf{fma}\left(\left(-0.16666666666666666 \cdot im\right) \cdot im, im, -im\right) \]
    11. Applied rewrites53.5%

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

Alternative 8: 63.2% accurate, 1.3× speedup?

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

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


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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) + -1 \cdot im \]
      6. associate-*r*N/A

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot {re}^{2} + -1 \cdot im \]
      7. lift-pow.f64N/A

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

        \[\leadsto \left(\frac{1}{2} \cdot im\right) \cdot \left(re \cdot re\right) + -1 \cdot im \]
      9. associate-*r*N/A

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

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      11. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(\frac{1}{2} \cdot im\right) \cdot re, re, -1 \cdot im\right) \]
      12. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -1 \cdot im\right) \]
      14. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, -1 \cdot im\right) \]
      15. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\left(im \cdot \frac{1}{2}\right) \cdot re, re, \mathsf{neg}\left(im\right)\right) \]
      16. lower-neg.f6437.0%

        \[\leadsto \mathsf{fma}\left(\left(im \cdot 0.5\right) \cdot re, re, -im\right) \]
    9. Applied rewrites37.0%

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

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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left|e^{-im}\right| - e^{im}\right) \]
      4. rem-sqrt-square-revN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{-im} \cdot e^{-im}} - e^{im}\right) \]
      8. exp-lft-sqr-revN/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(im\right)\right) \cdot 2}} - e^{im}\right) \]
      10. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(im \cdot 2\right)}} - e^{im}\right) \]
      11. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      12. count-2N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      14. lower-exp.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      16. count-2N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      18. lower-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      19. metadata-eval40.7%

        \[\leadsto 0.5 \cdot \left(\sqrt{e^{-2 \cdot im}} - e^{im}\right) \]
    6. Applied rewrites40.7%

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

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

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

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

        \[\leadsto im \cdot \left(\frac{-1}{6} \cdot {im}^{2} - 1\right) \]
      4. lower-pow.f6453.5%

        \[\leadsto im \cdot \left(-0.16666666666666666 \cdot {im}^{2} - 1\right) \]
    9. Applied rewrites53.5%

      \[\leadsto im \cdot \color{blue}{\left(-0.16666666666666666 \cdot {im}^{2} - 1\right)} \]
    10. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

        \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      5. lift-pow.f64N/A

        \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto im \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. sqr-neg-revN/A

        \[\leadsto im \cdot \left(\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. mul-1-negN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. mul-1-negN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      10. lower-*.f32N/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      11. lower-unsound-*.f32N/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + -1\right) \]
      13. lower-fma.f64N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      14. lower-unsound-*.f32N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      15. lower-*.f32N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      16. mul-1-negN/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      17. mul-1-negN/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right), \frac{-1}{6}, -1\right) \]
      18. sqr-neg-revN/A

        \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, \frac{-1}{6}, -1\right) \]
      19. lower-*.f6453.5%

        \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \]
    11. Applied rewrites53.5%

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

Alternative 9: 63.1% accurate, 1.3× speedup?

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

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


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

    1. Initial program 54.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(-1, im, \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right)\right) \]
      4. lower-pow.f6437.0%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) + -1 \cdot im \]
      5. mul-1-negN/A

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) + \left(\mathsf{neg}\left(im\right)\right) \]
      6. sub-flip-reverseN/A

        \[\leadsto \frac{1}{2} \cdot \left(im \cdot {re}^{2}\right) - im \]
      7. lower--.f6437.0%

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

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

        \[\leadsto \left(im \cdot {re}^{2}\right) \cdot \frac{1}{2} - im \]
      10. lower-*.f6437.0%

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

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

        \[\leadsto \left({re}^{2} \cdot im\right) \cdot \frac{1}{2} - im \]
      13. lower-*.f6437.0%

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

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

        \[\leadsto \left(\left(re \cdot re\right) \cdot im\right) \cdot \frac{1}{2} - im \]
      16. lower-*.f6437.0%

        \[\leadsto \left(\left(re \cdot re\right) \cdot im\right) \cdot 0.5 - im \]
    9. Applied rewrites37.0%

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

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

    1. Initial program 54.8%

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

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

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
      5. lower-exp.f6440.7%

        \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
    4. Applied rewrites40.7%

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\left|e^{-im}\right| - e^{im}\right) \]
      4. rem-sqrt-square-revN/A

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

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

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{-im} \cdot e^{-im}} - e^{im}\right) \]
      8. exp-lft-sqr-revN/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(im\right)\right) \cdot 2}} - e^{im}\right) \]
      10. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(im \cdot 2\right)}} - e^{im}\right) \]
      11. *-commutativeN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      12. count-2N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      14. lower-exp.f64N/A

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

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
      16. count-2N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
      17. distribute-lft-neg-inN/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      18. lower-*.f64N/A

        \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
      19. metadata-eval40.7%

        \[\leadsto 0.5 \cdot \left(\sqrt{e^{-2 \cdot im}} - e^{im}\right) \]
    6. Applied rewrites40.7%

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

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

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

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

        \[\leadsto im \cdot \left(\frac{-1}{6} \cdot {im}^{2} - 1\right) \]
      4. lower-pow.f6453.5%

        \[\leadsto im \cdot \left(-0.16666666666666666 \cdot {im}^{2} - 1\right) \]
    9. Applied rewrites53.5%

      \[\leadsto im \cdot \color{blue}{\left(-0.16666666666666666 \cdot {im}^{2} - 1\right)} \]
    10. Step-by-step derivation
      1. lift--.f64N/A

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

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

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

        \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      5. lift-pow.f64N/A

        \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      6. unpow2N/A

        \[\leadsto im \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      7. sqr-neg-revN/A

        \[\leadsto im \cdot \left(\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      8. mul-1-negN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      9. mul-1-negN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      10. lower-*.f32N/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      11. lower-unsound-*.f32N/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + -1\right) \]
      13. lower-fma.f64N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      14. lower-unsound-*.f32N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      15. lower-*.f32N/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      16. mul-1-negN/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
      17. mul-1-negN/A

        \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right), \frac{-1}{6}, -1\right) \]
      18. sqr-neg-revN/A

        \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, \frac{-1}{6}, -1\right) \]
      19. lower-*.f6453.5%

        \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \]
    11. Applied rewrites53.5%

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

Alternative 10: 53.5% accurate, 5.7× speedup?

\[im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \]
(FPCore (re im)
  :precision binary64
  (* im (fma (* im im) -0.16666666666666666 -1.0)))
double code(double re, double im) {
	return im * fma((im * im), -0.16666666666666666, -1.0);
}
function code(re, im)
	return Float64(im * fma(Float64(im * im), -0.16666666666666666, -1.0))
end
code[re_, im_] := N[(im * N[(N[(im * im), $MachinePrecision] * -0.16666666666666666 + -1.0), $MachinePrecision]), $MachinePrecision]
im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right)
Derivation
  1. Initial program 54.8%

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

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

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

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

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

      \[\leadsto \frac{1}{2} \cdot \left(e^{-im} - e^{im}\right) \]
    5. lower-exp.f6440.7%

      \[\leadsto 0.5 \cdot \left(e^{-im} - e^{im}\right) \]
  4. Applied rewrites40.7%

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

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

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

      \[\leadsto \frac{1}{2} \cdot \left(\left|e^{-im}\right| - e^{im}\right) \]
    4. rem-sqrt-square-revN/A

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

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

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

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{-im} \cdot e^{-im}} - e^{im}\right) \]
    8. exp-lft-sqr-revN/A

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

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(im\right)\right) \cdot 2}} - e^{im}\right) \]
    10. distribute-lft-neg-inN/A

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(im \cdot 2\right)}} - e^{im}\right) \]
    11. *-commutativeN/A

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
    12. count-2N/A

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

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
    14. lower-exp.f64N/A

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

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(\left(im + im\right)\right)}} - e^{im}\right) \]
    16. count-2N/A

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\mathsf{neg}\left(2 \cdot im\right)}} - e^{im}\right) \]
    17. distribute-lft-neg-inN/A

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
    18. lower-*.f64N/A

      \[\leadsto \frac{1}{2} \cdot \left(\sqrt{e^{\left(\mathsf{neg}\left(2\right)\right) \cdot im}} - e^{im}\right) \]
    19. metadata-eval40.7%

      \[\leadsto 0.5 \cdot \left(\sqrt{e^{-2 \cdot im}} - e^{im}\right) \]
  6. Applied rewrites40.7%

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

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

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

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

      \[\leadsto im \cdot \left(\frac{-1}{6} \cdot {im}^{2} - 1\right) \]
    4. lower-pow.f6453.5%

      \[\leadsto im \cdot \left(-0.16666666666666666 \cdot {im}^{2} - 1\right) \]
  9. Applied rewrites53.5%

    \[\leadsto im \cdot \color{blue}{\left(-0.16666666666666666 \cdot {im}^{2} - 1\right)} \]
  10. Step-by-step derivation
    1. lift--.f64N/A

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

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

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

      \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    5. lift-pow.f64N/A

      \[\leadsto im \cdot \left({im}^{2} \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    6. unpow2N/A

      \[\leadsto im \cdot \left(\left(im \cdot im\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    7. sqr-neg-revN/A

      \[\leadsto im \cdot \left(\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    8. mul-1-negN/A

      \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(\mathsf{neg}\left(im\right)\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    9. mul-1-negN/A

      \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    10. lower-*.f32N/A

      \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    11. lower-unsound-*.f32N/A

      \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + \left(\mathsf{neg}\left(1\right)\right)\right) \]
    12. metadata-evalN/A

      \[\leadsto im \cdot \left(\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right)\right) \cdot \frac{-1}{6} + -1\right) \]
    13. lower-fma.f64N/A

      \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
    14. lower-unsound-*.f32N/A

      \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
    15. lower-*.f32N/A

      \[\leadsto im \cdot \mathsf{fma}\left(\left(-1 \cdot im\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
    16. mul-1-negN/A

      \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(-1 \cdot im\right), \frac{-1}{6}, -1\right) \]
    17. mul-1-negN/A

      \[\leadsto im \cdot \mathsf{fma}\left(\left(\mathsf{neg}\left(im\right)\right) \cdot \left(\mathsf{neg}\left(im\right)\right), \frac{-1}{6}, -1\right) \]
    18. sqr-neg-revN/A

      \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, \frac{-1}{6}, -1\right) \]
    19. lower-*.f6453.5%

      \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \]
  11. Applied rewrites53.5%

    \[\leadsto im \cdot \mathsf{fma}\left(im \cdot im, -0.16666666666666666, -1\right) \]
  12. Add Preprocessing

Alternative 11: 29.6% accurate, 33.9× speedup?

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

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

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

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

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

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

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

    \[\leadsto -1 \cdot im \]
  6. Step-by-step derivation
    1. Applied rewrites29.6%

      \[\leadsto -1 \cdot im \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto -1 \cdot \color{blue}{im} \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(im\right) \]
      3. lower-neg.f6429.6%

        \[\leadsto -im \]
    3. Applied rewrites29.6%

      \[\leadsto -im \]
    4. Add Preprocessing

    Reproduce

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