math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 2.7s
Alternatives: 6
Speedup: 1.4×

Specification

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

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp(-im) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-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 6 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: 100.0% accurate, 1.0× speedup?

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

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

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

Alternative 1: 100.0% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
    5. metadata-evalN/A

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
    13. lower-*.f64N/A

      \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
    14. lower-cosh.f64100.0%

      \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
  4. Add Preprocessing

Alternative 2: 99.2% accurate, 0.4× speedup?

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

\mathbf{elif}\;t\_1 \leq 0.9992904828097019:\\
\;\;\;\;t\_0 \cdot 2\\

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


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

    1. Initial program 100.0%

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

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

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

        \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
      5. metadata-evalN/A

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
      13. lower-*.f64N/A

        \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
      14. lower-cosh.f64100.0%

        \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
    3. Applied rewrites100.0%

      \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
    4. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cosh im \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{2} + 1\right) \]
      7. sqr-abs-revN/A

        \[\leadsto \cosh im \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
      8. lower-*.f32N/A

        \[\leadsto \cosh im \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
      9. lower-unsound-*.f32N/A

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

        \[\leadsto \cosh im \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \color{blue}{\frac{-1}{2}}, 1\right) \]
      11. lower-unsound-*.f32N/A

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

        \[\leadsto \cosh im \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \frac{-1}{2}, 1\right) \]
      13. sqr-abs-revN/A

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

        \[\leadsto \cosh im \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right) \]
    8. Applied rewrites62.8%

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

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

    1. Initial program 100.0%

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

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{2} \]
    3. Step-by-step derivation
      1. Applied rewrites50.8%

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

      if 0.999290482809701897 < (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)))

      1. Initial program 100.0%

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

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

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

          \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
        5. metadata-evalN/A

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
        13. lower-*.f64N/A

          \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
        14. lower-cosh.f64100.0%

          \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
      3. Applied rewrites100.0%

        \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
      4. Taylor expanded in re around 0

        \[\leadsto \cosh im \cdot \color{blue}{1} \]
      5. Step-by-step derivation
        1. Applied rewrites64.0%

          \[\leadsto \cosh im \cdot \color{blue}{1} \]
      6. Recombined 3 regimes into one program.
      7. Add Preprocessing

      Alternative 3: 77.4% accurate, 0.7× speedup?

      \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.05:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\cosh im \cdot 1\\ \end{array} \]
      (FPCore (re im)
       :precision binary64
       (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.05)
         (* (cosh im) (fma (* re re) -0.5 1.0))
         (* (cosh im) 1.0)))
      double code(double re, double im) {
      	double tmp;
      	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.05) {
      		tmp = cosh(im) * fma((re * re), -0.5, 1.0);
      	} else {
      		tmp = cosh(im) * 1.0;
      	}
      	return tmp;
      }
      
      function code(re, im)
      	tmp = 0.0
      	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.05)
      		tmp = Float64(cosh(im) * fma(Float64(re * re), -0.5, 1.0));
      	else
      		tmp = Float64(cosh(im) * 1.0);
      	end
      	return tmp
      end
      
      code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[Cosh[im], $MachinePrecision] * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * 1.0), $MachinePrecision]]
      
      \begin{array}{l}
      \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.05:\\
      \;\;\;\;\cosh im \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\cosh im \cdot 1\\
      
      
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003

        1. Initial program 100.0%

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

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

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

            \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
          5. metadata-evalN/A

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
          13. lower-*.f64N/A

            \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
          14. lower-cosh.f64100.0%

            \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
        3. Applied rewrites100.0%

          \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
        4. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \cosh im \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{2} + 1\right) \]
          7. sqr-abs-revN/A

            \[\leadsto \cosh im \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
          8. lower-*.f32N/A

            \[\leadsto \cosh im \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
          9. lower-unsound-*.f32N/A

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

            \[\leadsto \cosh im \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \color{blue}{\frac{-1}{2}}, 1\right) \]
          11. lower-unsound-*.f32N/A

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

            \[\leadsto \cosh im \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \frac{-1}{2}, 1\right) \]
          13. sqr-abs-revN/A

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

            \[\leadsto \cosh im \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right) \]
        8. Applied rewrites62.8%

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

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

        1. Initial program 100.0%

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

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

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

            \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
          5. metadata-evalN/A

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
          13. lower-*.f64N/A

            \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
          14. lower-cosh.f64100.0%

            \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
        3. Applied rewrites100.0%

          \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
        4. Taylor expanded in re around 0

          \[\leadsto \cosh im \cdot \color{blue}{1} \]
        5. Step-by-step derivation
          1. Applied rewrites64.0%

            \[\leadsto \cosh im \cdot \color{blue}{1} \]
        6. Recombined 2 regimes into one program.
        7. Add Preprocessing

        Alternative 4: 71.3% accurate, 0.8× speedup?

        \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.05:\\ \;\;\;\;\left(2 \cdot 0.5\right) \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\cosh im \cdot 1\\ \end{array} \]
        (FPCore (re im)
         :precision binary64
         (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.05)
           (* (* 2.0 0.5) (fma (* re re) -0.5 1.0))
           (* (cosh im) 1.0)))
        double code(double re, double im) {
        	double tmp;
        	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.05) {
        		tmp = (2.0 * 0.5) * fma((re * re), -0.5, 1.0);
        	} else {
        		tmp = cosh(im) * 1.0;
        	}
        	return tmp;
        }
        
        function code(re, im)
        	tmp = 0.0
        	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.05)
        		tmp = Float64(Float64(2.0 * 0.5) * fma(Float64(re * re), -0.5, 1.0));
        	else
        		tmp = Float64(cosh(im) * 1.0);
        	end
        	return tmp
        end
        
        code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(2.0 * 0.5), $MachinePrecision] * N[(N[(re * re), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * 1.0), $MachinePrecision]]
        
        \begin{array}{l}
        \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.05:\\
        \;\;\;\;\left(2 \cdot 0.5\right) \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\cosh im \cdot 1\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 (*.f64 #s(literal 1/2 binary64) (cos.f64 re)) (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -0.050000000000000003

          1. Initial program 100.0%

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

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{2} \]
          3. Step-by-step derivation
            1. Applied rewrites50.8%

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

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

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

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

                \[\leadsto \left(0.5 \cdot \left(1 + -0.5 \cdot {re}^{\color{blue}{2}}\right)\right) \cdot 2 \]
            4. Applied rewrites32.4%

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

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

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

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

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

                \[\leadsto \color{blue}{\left(2 \cdot \frac{1}{2}\right) \cdot \left(1 + \frac{-1}{2} \cdot {re}^{2}\right)} \]
              6. lower-*.f6432.4%

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

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

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

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

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

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

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{2} + 1\right) \]
              13. sqr-abs-revN/A

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
              14. lower-*.f32N/A

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \frac{-1}{2} + 1\right) \]
              15. lower-unsound-*.f32N/A

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

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \color{blue}{\frac{-1}{2}}, 1\right) \]
              17. lower-unsound-*.f32N/A

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

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \mathsf{fma}\left(\left|re\right| \cdot \left|re\right|, \frac{-1}{2}, 1\right) \]
              19. sqr-abs-revN/A

                \[\leadsto \left(2 \cdot \frac{1}{2}\right) \cdot \mathsf{fma}\left(re \cdot re, \frac{-1}{2}, 1\right) \]
              20. lower-*.f6432.4%

                \[\leadsto \left(2 \cdot 0.5\right) \cdot \mathsf{fma}\left(re \cdot re, -0.5, 1\right) \]
            6. Applied rewrites32.4%

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

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

            1. Initial program 100.0%

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

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

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

                \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
              5. metadata-evalN/A

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
              13. lower-*.f64N/A

                \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
              14. lower-cosh.f64100.0%

                \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
            3. Applied rewrites100.0%

              \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
            4. Taylor expanded in re around 0

              \[\leadsto \cosh im \cdot \color{blue}{1} \]
            5. Step-by-step derivation
              1. Applied rewrites64.0%

                \[\leadsto \cosh im \cdot \color{blue}{1} \]
            6. Recombined 2 regimes into one program.
            7. Add Preprocessing

            Alternative 5: 64.0% accurate, 4.3× speedup?

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

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

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

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

                \[\leadsto \left(e^{-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^{-im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \cos re} \]
              5. metadata-evalN/A

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
              13. lower-*.f64N/A

                \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
              14. lower-cosh.f64100.0%

                \[\leadsto \color{blue}{\cosh im} \cdot \cos re \]
            3. Applied rewrites100.0%

              \[\leadsto \color{blue}{\cosh im \cdot \cos re} \]
            4. Taylor expanded in re around 0

              \[\leadsto \cosh im \cdot \color{blue}{1} \]
            5. Step-by-step derivation
              1. Applied rewrites64.0%

                \[\leadsto \cosh im \cdot \color{blue}{1} \]
              2. Add Preprocessing

              Alternative 6: 28.1% accurate, 15.9× speedup?

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

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

                \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{2} \]
              3. Step-by-step derivation
                1. Applied rewrites50.8%

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

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

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

                    \[\leadsto \color{blue}{\frac{1}{2}} \cdot 2 \]
                  3. Step-by-step derivation
                    1. Applied rewrites28.1%

                      \[\leadsto \color{blue}{0.5} \cdot 2 \]
                    2. Add Preprocessing

                    Reproduce

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