math.cos on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 3.3s
Alternatives: 13
Speedup: 1.5×

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 13 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.5× 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: 98.9% 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)\\ t_2 := \left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot t\_2\\ \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\ \;\;\;\;t\_0 \cdot t\_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))))
       (t_2
        (*
         (+ 2.0 (* im (- (* 2.0 im) 2.0)))
         (+ 1.0 (* im (+ 1.0 (* 0.5 im)))))))
  (if (<= t_1 (- INFINITY))
    (* (+ 0.5 (* -0.25 (pow re 2.0))) t_2)
    (if (<= t_1 0.9998915577998635) (* t_0 t_2) (* (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 t_2 = (2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im))));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (0.5 + (-0.25 * pow(re, 2.0))) * t_2;
	} else if (t_1 <= 0.9998915577998635) {
		tmp = t_0 * t_2;
	} else {
		tmp = cosh(im) * 1.0;
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = 0.5 * Math.cos(re);
	double t_1 = t_0 * (Math.exp(-im) + Math.exp(im));
	double t_2 = (2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im))));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = (0.5 + (-0.25 * Math.pow(re, 2.0))) * t_2;
	} else if (t_1 <= 0.9998915577998635) {
		tmp = t_0 * t_2;
	} else {
		tmp = Math.cosh(im) * 1.0;
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 * math.cos(re)
	t_1 = t_0 * (math.exp(-im) + math.exp(im))
	t_2 = (2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im))))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = (0.5 + (-0.25 * math.pow(re, 2.0))) * t_2
	elif t_1 <= 0.9998915577998635:
		tmp = t_0 * t_2
	else:
		tmp = math.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)))
	t_2 = Float64(Float64(2.0 + Float64(im * Float64(Float64(2.0 * im) - 2.0))) * Float64(1.0 + Float64(im * Float64(1.0 + Float64(0.5 * im)))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(0.5 + Float64(-0.25 * (re ^ 2.0))) * t_2);
	elseif (t_1 <= 0.9998915577998635)
		tmp = Float64(t_0 * t_2);
	else
		tmp = Float64(cosh(im) * 1.0);
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * cos(re);
	t_1 = t_0 * (exp(-im) + exp(im));
	t_2 = (2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im))));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = (0.5 + (-0.25 * (re ^ 2.0))) * t_2;
	elseif (t_1 <= 0.9998915577998635)
		tmp = t_0 * t_2;
	else
		tmp = cosh(im) * 1.0;
	end
	tmp_2 = 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]}, Block[{t$95$2 = N[(N[(2.0 + N[(im * N[(N[(2.0 * im), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(im * N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(0.5 + N[(-0.25 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[t$95$1, 0.9998915577998635], N[(t$95$0 * t$95$2), $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)\\
t_2 := \left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot t\_2\\

\mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\
\;\;\;\;t\_0 \cdot t\_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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
      2. +-commutativeN/A

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
      4. lower-*.f6475.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
    6. Applied rewrites75.0%

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot im}\right)\right)\right) \]
      4. lower-*.f6488.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot \color{blue}{im}\right)\right)\right) \]
    9. Applied rewrites88.3%

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

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

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

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

        \[\leadsto \left(0.5 + -0.25 \cdot {re}^{\color{blue}{2}}\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right) \]
    12. Applied rewrites56.1%

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

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

    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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
      2. +-commutativeN/A

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
      4. lower-*.f6475.0%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
    6. Applied rewrites75.0%

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot im}\right)\right)\right) \]
      4. lower-*.f6488.3%

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot \color{blue}{im}\right)\right)\right) \]
    9. Applied rewrites88.3%

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

    if 0.9998915577998635 < (*.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.8%

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

    Alternative 3: 98.6% accurate, 0.4× speedup?

    \[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\ t_2 := 2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot \left(t\_2 \cdot \left(1 + \left|im\right|\right)\right)\\ \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\ \;\;\;\;t\_0 \cdot \left(t\_2 \cdot \left(1 + \left|im\right| \cdot \left(1 + 0.5 \cdot \left|im\right|\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cosh \left(\left|im\right|\right) \cdot 1\\ \end{array} \]
    (FPCore (re im)
      :precision binary64
      (let* ((t_0 (* 0.5 (cos re)))
           (t_1 (* t_0 (+ (exp (- (fabs im))) (exp (fabs im)))))
           (t_2 (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))))
      (if (<= t_1 (- INFINITY))
        (* (+ 0.5 (* -0.25 (pow re 2.0))) (* t_2 (+ 1.0 (fabs im))))
        (if (<= t_1 0.9998915577998635)
          (* t_0 (* t_2 (+ 1.0 (* (fabs im) (+ 1.0 (* 0.5 (fabs im)))))))
          (* (cosh (fabs im)) 1.0)))))
    double code(double re, double im) {
    	double t_0 = 0.5 * cos(re);
    	double t_1 = t_0 * (exp(-fabs(im)) + exp(fabs(im)));
    	double t_2 = 2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0));
    	double tmp;
    	if (t_1 <= -((double) INFINITY)) {
    		tmp = (0.5 + (-0.25 * pow(re, 2.0))) * (t_2 * (1.0 + fabs(im)));
    	} else if (t_1 <= 0.9998915577998635) {
    		tmp = t_0 * (t_2 * (1.0 + (fabs(im) * (1.0 + (0.5 * fabs(im))))));
    	} else {
    		tmp = cosh(fabs(im)) * 1.0;
    	}
    	return tmp;
    }
    
    public static double code(double re, double im) {
    	double t_0 = 0.5 * Math.cos(re);
    	double t_1 = t_0 * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)));
    	double t_2 = 2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0));
    	double tmp;
    	if (t_1 <= -Double.POSITIVE_INFINITY) {
    		tmp = (0.5 + (-0.25 * Math.pow(re, 2.0))) * (t_2 * (1.0 + Math.abs(im)));
    	} else if (t_1 <= 0.9998915577998635) {
    		tmp = t_0 * (t_2 * (1.0 + (Math.abs(im) * (1.0 + (0.5 * Math.abs(im))))));
    	} else {
    		tmp = Math.cosh(Math.abs(im)) * 1.0;
    	}
    	return tmp;
    }
    
    def code(re, im):
    	t_0 = 0.5 * math.cos(re)
    	t_1 = t_0 * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))
    	t_2 = 2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))
    	tmp = 0
    	if t_1 <= -math.inf:
    		tmp = (0.5 + (-0.25 * math.pow(re, 2.0))) * (t_2 * (1.0 + math.fabs(im)))
    	elif t_1 <= 0.9998915577998635:
    		tmp = t_0 * (t_2 * (1.0 + (math.fabs(im) * (1.0 + (0.5 * math.fabs(im))))))
    	else:
    		tmp = math.cosh(math.fabs(im)) * 1.0
    	return tmp
    
    function code(re, im)
    	t_0 = Float64(0.5 * cos(re))
    	t_1 = Float64(t_0 * Float64(exp(Float64(-abs(im))) + exp(abs(im))))
    	t_2 = Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0)))
    	tmp = 0.0
    	if (t_1 <= Float64(-Inf))
    		tmp = Float64(Float64(0.5 + Float64(-0.25 * (re ^ 2.0))) * Float64(t_2 * Float64(1.0 + abs(im))));
    	elseif (t_1 <= 0.9998915577998635)
    		tmp = Float64(t_0 * Float64(t_2 * Float64(1.0 + Float64(abs(im) * Float64(1.0 + Float64(0.5 * abs(im)))))));
    	else
    		tmp = Float64(cosh(abs(im)) * 1.0);
    	end
    	return tmp
    end
    
    function tmp_2 = code(re, im)
    	t_0 = 0.5 * cos(re);
    	t_1 = t_0 * (exp(-abs(im)) + exp(abs(im)));
    	t_2 = 2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0));
    	tmp = 0.0;
    	if (t_1 <= -Inf)
    		tmp = (0.5 + (-0.25 * (re ^ 2.0))) * (t_2 * (1.0 + abs(im)));
    	elseif (t_1 <= 0.9998915577998635)
    		tmp = t_0 * (t_2 * (1.0 + (abs(im) * (1.0 + (0.5 * abs(im))))));
    	else
    		tmp = cosh(abs(im)) * 1.0;
    	end
    	tmp_2 = 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[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(0.5 + N[(-0.25 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(t$95$2 * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.9998915577998635], N[(t$95$0 * N[(t$95$2 * N[(1.0 + N[(N[Abs[im], $MachinePrecision] * N[(1.0 + N[(0.5 * N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]]]]
    
    \begin{array}{l}
    t_0 := 0.5 \cdot \cos re\\
    t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\
    t_2 := 2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\\
    \mathbf{if}\;t\_1 \leq -\infty:\\
    \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot \left(t\_2 \cdot \left(1 + \left|im\right|\right)\right)\\
    
    \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\
    \;\;\;\;t\_0 \cdot \left(t\_2 \cdot \left(1 + \left|im\right| \cdot \left(1 + 0.5 \cdot \left|im\right|\right)\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\cosh \left(\left|im\right|\right) \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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
        2. +-commutativeN/A

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

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

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

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

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

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

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

          \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
        4. lower-*.f6475.0%

          \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
      6. Applied rewrites75.0%

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

        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
      8. Step-by-step derivation
        1. lower-+.f6467.4%

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

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

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

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

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

          \[\leadsto \left(0.5 + -0.25 \cdot {re}^{\color{blue}{2}}\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
      12. Applied rewrites44.9%

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

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

      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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
        2. +-commutativeN/A

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

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

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

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

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

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

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

          \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
        4. lower-*.f6475.0%

          \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
      6. Applied rewrites75.0%

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

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

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

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

          \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot im}\right)\right)\right) \]
        4. lower-*.f6488.3%

          \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot \color{blue}{im}\right)\right)\right) \]
      9. Applied rewrites88.3%

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

      if 0.9998915577998635 < (*.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.8%

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

      Alternative 4: 98.6% accurate, 0.4× speedup?

      \[\begin{array}{l} t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\ \mathbf{elif}\;t\_0 \leq 0.9998915577998635:\\ \;\;\;\;\left(\left(\cos re \cdot \left(\left(\left|im\right| \cdot 0.5 - -1\right) \cdot \left|im\right| - -1\right)\right) \cdot \left(\left(\left(\left|im\right| + \left|im\right|\right) - 2\right) \cdot \left|im\right| - -2\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\cosh \left(\left|im\right|\right) \cdot 1\\ \end{array} \]
      (FPCore (re im)
        :precision binary64
        (let* ((t_0
              (* (* 0.5 (cos re)) (+ (exp (- (fabs im))) (exp (fabs im))))))
        (if (<= t_0 (- INFINITY))
          (*
           (+ 0.5 (* -0.25 (pow re 2.0)))
           (*
            (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))
            (+ 1.0 (fabs im))))
          (if (<= t_0 0.9998915577998635)
            (*
             (*
              (* (cos re) (- (* (- (* (fabs im) 0.5) -1.0) (fabs im)) -1.0))
              (- (* (- (+ (fabs im) (fabs im)) 2.0) (fabs im)) -2.0))
             0.5)
            (* (cosh (fabs im)) 1.0)))))
      double code(double re, double im) {
      	double t_0 = (0.5 * cos(re)) * (exp(-fabs(im)) + exp(fabs(im)));
      	double tmp;
      	if (t_0 <= -((double) INFINITY)) {
      		tmp = (0.5 + (-0.25 * pow(re, 2.0))) * ((2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0))) * (1.0 + fabs(im)));
      	} else if (t_0 <= 0.9998915577998635) {
      		tmp = ((cos(re) * ((((fabs(im) * 0.5) - -1.0) * fabs(im)) - -1.0)) * ((((fabs(im) + fabs(im)) - 2.0) * fabs(im)) - -2.0)) * 0.5;
      	} else {
      		tmp = cosh(fabs(im)) * 1.0;
      	}
      	return tmp;
      }
      
      public static double code(double re, double im) {
      	double t_0 = (0.5 * Math.cos(re)) * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)));
      	double tmp;
      	if (t_0 <= -Double.POSITIVE_INFINITY) {
      		tmp = (0.5 + (-0.25 * Math.pow(re, 2.0))) * ((2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0))) * (1.0 + Math.abs(im)));
      	} else if (t_0 <= 0.9998915577998635) {
      		tmp = ((Math.cos(re) * ((((Math.abs(im) * 0.5) - -1.0) * Math.abs(im)) - -1.0)) * ((((Math.abs(im) + Math.abs(im)) - 2.0) * Math.abs(im)) - -2.0)) * 0.5;
      	} else {
      		tmp = Math.cosh(Math.abs(im)) * 1.0;
      	}
      	return tmp;
      }
      
      def code(re, im):
      	t_0 = (0.5 * math.cos(re)) * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))
      	tmp = 0
      	if t_0 <= -math.inf:
      		tmp = (0.5 + (-0.25 * math.pow(re, 2.0))) * ((2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))) * (1.0 + math.fabs(im)))
      	elif t_0 <= 0.9998915577998635:
      		tmp = ((math.cos(re) * ((((math.fabs(im) * 0.5) - -1.0) * math.fabs(im)) - -1.0)) * ((((math.fabs(im) + math.fabs(im)) - 2.0) * math.fabs(im)) - -2.0)) * 0.5
      	else:
      		tmp = math.cosh(math.fabs(im)) * 1.0
      	return tmp
      
      function code(re, im)
      	t_0 = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-abs(im))) + exp(abs(im))))
      	tmp = 0.0
      	if (t_0 <= Float64(-Inf))
      		tmp = Float64(Float64(0.5 + Float64(-0.25 * (re ^ 2.0))) * Float64(Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0))) * Float64(1.0 + abs(im))));
      	elseif (t_0 <= 0.9998915577998635)
      		tmp = Float64(Float64(Float64(cos(re) * Float64(Float64(Float64(Float64(abs(im) * 0.5) - -1.0) * abs(im)) - -1.0)) * Float64(Float64(Float64(Float64(abs(im) + abs(im)) - 2.0) * abs(im)) - -2.0)) * 0.5);
      	else
      		tmp = Float64(cosh(abs(im)) * 1.0);
      	end
      	return tmp
      end
      
      function tmp_2 = code(re, im)
      	t_0 = (0.5 * cos(re)) * (exp(-abs(im)) + exp(abs(im)));
      	tmp = 0.0;
      	if (t_0 <= -Inf)
      		tmp = (0.5 + (-0.25 * (re ^ 2.0))) * ((2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0))) * (1.0 + abs(im)));
      	elseif (t_0 <= 0.9998915577998635)
      		tmp = ((cos(re) * ((((abs(im) * 0.5) - -1.0) * abs(im)) - -1.0)) * ((((abs(im) + abs(im)) - 2.0) * abs(im)) - -2.0)) * 0.5;
      	else
      		tmp = cosh(abs(im)) * 1.0;
      	end
      	tmp_2 = tmp;
      end
      
      code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(0.5 + N[(-0.25 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.9998915577998635], N[(N[(N[(N[Cos[re], $MachinePrecision] * N[(N[(N[(N[(N[Abs[im], $MachinePrecision] * 0.5), $MachinePrecision] - -1.0), $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision] - -2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]]
      
      \begin{array}{l}
      t_0 := \left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\
      \mathbf{if}\;t\_0 \leq -\infty:\\
      \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\
      
      \mathbf{elif}\;t\_0 \leq 0.9998915577998635:\\
      \;\;\;\;\left(\left(\cos re \cdot \left(\left(\left|im\right| \cdot 0.5 - -1\right) \cdot \left|im\right| - -1\right)\right) \cdot \left(\left(\left(\left|im\right| + \left|im\right|\right) - 2\right) \cdot \left|im\right| - -2\right)\right) \cdot 0.5\\
      
      \mathbf{else}:\\
      \;\;\;\;\cosh \left(\left|im\right|\right) \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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
          2. +-commutativeN/A

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

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

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

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

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

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

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

            \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
          4. lower-*.f6475.0%

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
        6. Applied rewrites75.0%

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

          \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
        8. Step-by-step derivation
          1. lower-+.f6467.4%

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

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

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

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

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

            \[\leadsto \left(0.5 + -0.25 \cdot {re}^{\color{blue}{2}}\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
        12. Applied rewrites44.9%

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

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

        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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
          2. +-commutativeN/A

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

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

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

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

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

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

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

            \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
          4. lower-*.f6475.0%

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
        6. Applied rewrites75.0%

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

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

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

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

            \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot im}\right)\right)\right) \]
          4. lower-*.f6488.3%

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot \color{blue}{im}\right)\right)\right) \]
        9. Applied rewrites88.3%

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

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

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

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

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

            \[\leadsto \color{blue}{\left(\cos re \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \frac{1}{2} \cdot im\right)\right)\right)\right) \cdot \frac{1}{2}} \]
        11. Applied rewrites88.3%

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

        if 0.9998915577998635 < (*.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.8%

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

        Alternative 5: 98.5% accurate, 0.4× speedup?

        \[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\ t_2 := \left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot t\_2\\ \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\ \;\;\;\;t\_0 \cdot t\_2\\ \mathbf{else}:\\ \;\;\;\;\cosh \left(\left|im\right|\right) \cdot 1\\ \end{array} \]
        (FPCore (re im)
          :precision binary64
          (let* ((t_0 (* 0.5 (cos re)))
               (t_1 (* t_0 (+ (exp (- (fabs im))) (exp (fabs im)))))
               (t_2
                (*
                 (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))
                 (+ 1.0 (fabs im)))))
          (if (<= t_1 (- INFINITY))
            (* (+ 0.5 (* -0.25 (pow re 2.0))) t_2)
            (if (<= t_1 0.9998915577998635)
              (* t_0 t_2)
              (* (cosh (fabs im)) 1.0)))))
        double code(double re, double im) {
        	double t_0 = 0.5 * cos(re);
        	double t_1 = t_0 * (exp(-fabs(im)) + exp(fabs(im)));
        	double t_2 = (2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0))) * (1.0 + fabs(im));
        	double tmp;
        	if (t_1 <= -((double) INFINITY)) {
        		tmp = (0.5 + (-0.25 * pow(re, 2.0))) * t_2;
        	} else if (t_1 <= 0.9998915577998635) {
        		tmp = t_0 * t_2;
        	} else {
        		tmp = cosh(fabs(im)) * 1.0;
        	}
        	return tmp;
        }
        
        public static double code(double re, double im) {
        	double t_0 = 0.5 * Math.cos(re);
        	double t_1 = t_0 * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)));
        	double t_2 = (2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0))) * (1.0 + Math.abs(im));
        	double tmp;
        	if (t_1 <= -Double.POSITIVE_INFINITY) {
        		tmp = (0.5 + (-0.25 * Math.pow(re, 2.0))) * t_2;
        	} else if (t_1 <= 0.9998915577998635) {
        		tmp = t_0 * t_2;
        	} else {
        		tmp = Math.cosh(Math.abs(im)) * 1.0;
        	}
        	return tmp;
        }
        
        def code(re, im):
        	t_0 = 0.5 * math.cos(re)
        	t_1 = t_0 * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))
        	t_2 = (2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))) * (1.0 + math.fabs(im))
        	tmp = 0
        	if t_1 <= -math.inf:
        		tmp = (0.5 + (-0.25 * math.pow(re, 2.0))) * t_2
        	elif t_1 <= 0.9998915577998635:
        		tmp = t_0 * t_2
        	else:
        		tmp = math.cosh(math.fabs(im)) * 1.0
        	return tmp
        
        function code(re, im)
        	t_0 = Float64(0.5 * cos(re))
        	t_1 = Float64(t_0 * Float64(exp(Float64(-abs(im))) + exp(abs(im))))
        	t_2 = Float64(Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0))) * Float64(1.0 + abs(im)))
        	tmp = 0.0
        	if (t_1 <= Float64(-Inf))
        		tmp = Float64(Float64(0.5 + Float64(-0.25 * (re ^ 2.0))) * t_2);
        	elseif (t_1 <= 0.9998915577998635)
        		tmp = Float64(t_0 * t_2);
        	else
        		tmp = Float64(cosh(abs(im)) * 1.0);
        	end
        	return tmp
        end
        
        function tmp_2 = code(re, im)
        	t_0 = 0.5 * cos(re);
        	t_1 = t_0 * (exp(-abs(im)) + exp(abs(im)));
        	t_2 = (2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0))) * (1.0 + abs(im));
        	tmp = 0.0;
        	if (t_1 <= -Inf)
        		tmp = (0.5 + (-0.25 * (re ^ 2.0))) * t_2;
        	elseif (t_1 <= 0.9998915577998635)
        		tmp = t_0 * t_2;
        	else
        		tmp = cosh(abs(im)) * 1.0;
        	end
        	tmp_2 = 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[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(0.5 + N[(-0.25 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[t$95$1, 0.9998915577998635], N[(t$95$0 * t$95$2), $MachinePrecision], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]]]]
        
        \begin{array}{l}
        t_0 := 0.5 \cdot \cos re\\
        t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\
        t_2 := \left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\\
        \mathbf{if}\;t\_1 \leq -\infty:\\
        \;\;\;\;\left(0.5 + -0.25 \cdot {re}^{2}\right) \cdot t\_2\\
        
        \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\
        \;\;\;\;t\_0 \cdot t\_2\\
        
        \mathbf{else}:\\
        \;\;\;\;\cosh \left(\left|im\right|\right) \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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
            2. +-commutativeN/A

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

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

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

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

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

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

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

              \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
            4. lower-*.f6475.0%

              \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
          6. Applied rewrites75.0%

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

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
          8. Step-by-step derivation
            1. lower-+.f6467.4%

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

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

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

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

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

              \[\leadsto \left(0.5 + -0.25 \cdot {re}^{\color{blue}{2}}\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
          12. Applied rewrites44.9%

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

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

          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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
            2. +-commutativeN/A

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

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

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

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

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

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

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

              \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
            4. lower-*.f6475.0%

              \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
          6. Applied rewrites75.0%

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

            \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
          8. Step-by-step derivation
            1. lower-+.f6467.4%

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

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

          if 0.9998915577998635 < (*.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.8%

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

          Alternative 6: 96.4% accurate, 0.4× speedup?

          \[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\ \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\ \;\;\;\;t\_0 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cosh \left(\left|im\right|\right) \cdot 1\\ \end{array} \]
          (FPCore (re im)
            :precision binary64
            (let* ((t_0 (* 0.5 (cos re)))
                 (t_1 (* t_0 (+ (exp (- (fabs im))) (exp (fabs im))))))
            (if (<= t_1 (- INFINITY))
              (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0)
              (if (<= t_1 0.9998915577998635)
                (*
                 t_0
                 (*
                  (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))
                  (+ 1.0 (fabs im))))
                (* (cosh (fabs im)) 1.0)))))
          double code(double re, double im) {
          	double t_0 = 0.5 * cos(re);
          	double t_1 = t_0 * (exp(-fabs(im)) + exp(fabs(im)));
          	double tmp;
          	if (t_1 <= -((double) INFINITY)) {
          		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
          	} else if (t_1 <= 0.9998915577998635) {
          		tmp = t_0 * ((2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0))) * (1.0 + fabs(im)));
          	} else {
          		tmp = cosh(fabs(im)) * 1.0;
          	}
          	return tmp;
          }
          
          public static double code(double re, double im) {
          	double t_0 = 0.5 * Math.cos(re);
          	double t_1 = t_0 * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)));
          	double tmp;
          	if (t_1 <= -Double.POSITIVE_INFINITY) {
          		tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
          	} else if (t_1 <= 0.9998915577998635) {
          		tmp = t_0 * ((2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0))) * (1.0 + Math.abs(im)));
          	} else {
          		tmp = Math.cosh(Math.abs(im)) * 1.0;
          	}
          	return tmp;
          }
          
          def code(re, im):
          	t_0 = 0.5 * math.cos(re)
          	t_1 = t_0 * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))
          	tmp = 0
          	if t_1 <= -math.inf:
          		tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0
          	elif t_1 <= 0.9998915577998635:
          		tmp = t_0 * ((2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))) * (1.0 + math.fabs(im)))
          	else:
          		tmp = math.cosh(math.fabs(im)) * 1.0
          	return tmp
          
          function code(re, im)
          	t_0 = Float64(0.5 * cos(re))
          	t_1 = Float64(t_0 * Float64(exp(Float64(-abs(im))) + exp(abs(im))))
          	tmp = 0.0
          	if (t_1 <= Float64(-Inf))
          		tmp = Float64(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0);
          	elseif (t_1 <= 0.9998915577998635)
          		tmp = Float64(t_0 * Float64(Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0))) * Float64(1.0 + abs(im))));
          	else
          		tmp = Float64(cosh(abs(im)) * 1.0);
          	end
          	return tmp
          end
          
          function tmp_2 = code(re, im)
          	t_0 = 0.5 * cos(re);
          	t_1 = t_0 * (exp(-abs(im)) + exp(abs(im)));
          	tmp = 0.0;
          	if (t_1 <= -Inf)
          		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
          	elseif (t_1 <= 0.9998915577998635)
          		tmp = t_0 * ((2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0))) * (1.0 + abs(im)));
          	else
          		tmp = cosh(abs(im)) * 1.0;
          	end
          	tmp_2 = 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[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$1, 0.9998915577998635], N[(t$95$0 * N[(N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[N[Abs[im], $MachinePrecision]], $MachinePrecision] * 1.0), $MachinePrecision]]]]]
          
          \begin{array}{l}
          t_0 := 0.5 \cdot \cos re\\
          t_1 := t\_0 \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right)\\
          \mathbf{if}\;t\_1 \leq -\infty:\\
          \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
          
          \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\
          \;\;\;\;t\_0 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\cosh \left(\left|im\right|\right) \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. 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 rewrites51.4%

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

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

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

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

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

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

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

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

                  \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                4. lower-*.f6434.8%

                  \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                5. lift-pow.f64N/A

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

                  \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                7. lower-*.f6434.8%

                  \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                8. lift-pow.f64N/A

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

                  \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                10. lower-*.f6434.8%

                  \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
              6. Applied rewrites34.8%

                \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]

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

              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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
                2. +-commutativeN/A

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

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

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

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

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

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

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

                  \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
                4. lower-*.f6475.0%

                  \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
              6. Applied rewrites75.0%

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

                \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
              8. Step-by-step derivation
                1. lower-+.f6467.4%

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

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

              if 0.9998915577998635 < (*.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.8%

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

              Alternative 7: 96.4% 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:\\ \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\ \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\ \;\;\;\;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))
                  (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0)
                  (if (<= t_1 0.9998915577998635) (* 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 = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
              	} else if (t_1 <= 0.9998915577998635) {
              		tmp = t_0 * 2.0;
              	} else {
              		tmp = cosh(im) * 1.0;
              	}
              	return tmp;
              }
              
              public static double code(double re, double im) {
              	double t_0 = 0.5 * Math.cos(re);
              	double t_1 = t_0 * (Math.exp(-im) + Math.exp(im));
              	double tmp;
              	if (t_1 <= -Double.POSITIVE_INFINITY) {
              		tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
              	} else if (t_1 <= 0.9998915577998635) {
              		tmp = t_0 * 2.0;
              	} else {
              		tmp = Math.cosh(im) * 1.0;
              	}
              	return tmp;
              }
              
              def code(re, im):
              	t_0 = 0.5 * math.cos(re)
              	t_1 = t_0 * (math.exp(-im) + math.exp(im))
              	tmp = 0
              	if t_1 <= -math.inf:
              		tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0
              	elif t_1 <= 0.9998915577998635:
              		tmp = t_0 * 2.0
              	else:
              		tmp = math.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(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0);
              	elseif (t_1 <= 0.9998915577998635)
              		tmp = Float64(t_0 * 2.0);
              	else
              		tmp = Float64(cosh(im) * 1.0);
              	end
              	return tmp
              end
              
              function tmp_2 = code(re, im)
              	t_0 = 0.5 * cos(re);
              	t_1 = t_0 * (exp(-im) + exp(im));
              	tmp = 0.0;
              	if (t_1 <= -Inf)
              		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
              	elseif (t_1 <= 0.9998915577998635)
              		tmp = t_0 * 2.0;
              	else
              		tmp = cosh(im) * 1.0;
              	end
              	tmp_2 = 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[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$1, 0.9998915577998635], 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:\\
              \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
              
              \mathbf{elif}\;t\_1 \leq 0.9998915577998635:\\
              \;\;\;\;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. 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 rewrites51.4%

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

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

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

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

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

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

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

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

                      \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                    4. lower-*.f6434.8%

                      \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                    5. lift-pow.f64N/A

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

                      \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                    7. lower-*.f6434.8%

                      \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                    8. lift-pow.f64N/A

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

                      \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                    10. lower-*.f6434.8%

                      \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                  6. Applied rewrites34.8%

                    \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]

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

                  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 rewrites51.4%

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

                    if 0.9998915577998635 < (*.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.8%

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

                    Alternative 8: 74.2% 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.02:\\ \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\cosh im \cdot 1\\ \end{array} \]
                    (FPCore (re im)
                      :precision binary64
                      (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.02)
                      (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0)
                      (* (cosh im) 1.0)))
                    double code(double re, double im) {
                    	double tmp;
                    	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02) {
                    		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                    	} else {
                    		tmp = cosh(im) * 1.0;
                    	}
                    	return tmp;
                    }
                    
                    module fmin_fmax_functions
                        implicit none
                        private
                        public fmax
                        public fmin
                    
                        interface fmax
                            module procedure fmax88
                            module procedure fmax44
                            module procedure fmax84
                            module procedure fmax48
                        end interface
                        interface fmin
                            module procedure fmin88
                            module procedure fmin44
                            module procedure fmin84
                            module procedure fmin48
                        end interface
                    contains
                        real(8) function fmax88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmax44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmax84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmax48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                        end function
                        real(8) function fmin88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmin44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmin84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmin48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                        end function
                    end module
                    
                    real(8) function code(re, im)
                    use fmin_fmax_functions
                        real(8), intent (in) :: re
                        real(8), intent (in) :: im
                        real(8) :: tmp
                        if (((0.5d0 * cos(re)) * (exp(-im) + exp(im))) <= (-0.02d0)) then
                            tmp = (0.5d0 + ((-0.25d0) * sqrt(((re * re) * (re * re))))) * 2.0d0
                        else
                            tmp = cosh(im) * 1.0d0
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double re, double im) {
                    	double tmp;
                    	if (((0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im))) <= -0.02) {
                    		tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
                    	} else {
                    		tmp = Math.cosh(im) * 1.0;
                    	}
                    	return tmp;
                    }
                    
                    def code(re, im):
                    	tmp = 0
                    	if ((0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))) <= -0.02:
                    		tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0
                    	else:
                    		tmp = math.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.02)
                    		tmp = Float64(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0);
                    	else
                    		tmp = Float64(cosh(im) * 1.0);
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(re, im)
                    	tmp = 0.0;
                    	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02)
                    		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                    	else
                    		tmp = cosh(im) * 1.0;
                    	end
                    	tmp_2 = 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.02], N[(N[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $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.02:\\
                    \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
                    
                    \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.02

                      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 rewrites51.4%

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

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

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

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

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

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

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

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

                            \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                          4. lower-*.f6434.8%

                            \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                          5. lift-pow.f64N/A

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

                            \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                          7. lower-*.f6434.8%

                            \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                          8. lift-pow.f64N/A

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

                            \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                          10. lower-*.f6434.8%

                            \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                        6. Applied rewrites34.8%

                          \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]

                        if -0.02 < (*.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.8%

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

                        Alternative 9: 65.5% accurate, 0.9× speedup?

                        \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.02:\\ \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right)\\ \end{array} \]
                        (FPCore (re im)
                          :precision binary64
                          (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.02)
                          (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0)
                          (*
                           0.5
                           (*
                            (+ 2.0 (* im (- (* 2.0 im) 2.0)))
                            (+ 1.0 (* im (+ 1.0 (* 0.5 im))))))))
                        double code(double re, double im) {
                        	double tmp;
                        	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02) {
                        		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                        	} else {
                        		tmp = 0.5 * ((2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im)))));
                        	}
                        	return tmp;
                        }
                        
                        module fmin_fmax_functions
                            implicit none
                            private
                            public fmax
                            public fmin
                        
                            interface fmax
                                module procedure fmax88
                                module procedure fmax44
                                module procedure fmax84
                                module procedure fmax48
                            end interface
                            interface fmin
                                module procedure fmin88
                                module procedure fmin44
                                module procedure fmin84
                                module procedure fmin48
                            end interface
                        contains
                            real(8) function fmax88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmax44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmax84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmax48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                            end function
                            real(8) function fmin88(x, y) result (res)
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(4) function fmin44(x, y) result (res)
                                real(4), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                            end function
                            real(8) function fmin84(x, y) result(res)
                                real(8), intent (in) :: x
                                real(4), intent (in) :: y
                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                            end function
                            real(8) function fmin48(x, y) result(res)
                                real(4), intent (in) :: x
                                real(8), intent (in) :: y
                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                            end function
                        end module
                        
                        real(8) function code(re, im)
                        use fmin_fmax_functions
                            real(8), intent (in) :: re
                            real(8), intent (in) :: im
                            real(8) :: tmp
                            if (((0.5d0 * cos(re)) * (exp(-im) + exp(im))) <= (-0.02d0)) then
                                tmp = (0.5d0 + ((-0.25d0) * sqrt(((re * re) * (re * re))))) * 2.0d0
                            else
                                tmp = 0.5d0 * ((2.0d0 + (im * ((2.0d0 * im) - 2.0d0))) * (1.0d0 + (im * (1.0d0 + (0.5d0 * im)))))
                            end if
                            code = tmp
                        end function
                        
                        public static double code(double re, double im) {
                        	double tmp;
                        	if (((0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im))) <= -0.02) {
                        		tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
                        	} else {
                        		tmp = 0.5 * ((2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im)))));
                        	}
                        	return tmp;
                        }
                        
                        def code(re, im):
                        	tmp = 0
                        	if ((0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))) <= -0.02:
                        		tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0
                        	else:
                        		tmp = 0.5 * ((2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im)))))
                        	return tmp
                        
                        function code(re, im)
                        	tmp = 0.0
                        	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.02)
                        		tmp = Float64(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0);
                        	else
                        		tmp = Float64(0.5 * Float64(Float64(2.0 + Float64(im * Float64(Float64(2.0 * im) - 2.0))) * Float64(1.0 + Float64(im * Float64(1.0 + Float64(0.5 * im))))));
                        	end
                        	return tmp
                        end
                        
                        function tmp_2 = code(re, im)
                        	tmp = 0.0;
                        	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02)
                        		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                        	else
                        		tmp = 0.5 * ((2.0 + (im * ((2.0 * im) - 2.0))) * (1.0 + (im * (1.0 + (0.5 * im)))));
                        	end
                        	tmp_2 = 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.02], N[(N[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(0.5 * N[(N[(2.0 + N[(im * N[(N[(2.0 * im), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(im * N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                        
                        \begin{array}{l}
                        \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.02:\\
                        \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;0.5 \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\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 (neg.f64 im)) (exp.f64 im))) < -0.02

                          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 rewrites51.4%

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

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

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

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

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

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

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

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

                                \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                              4. lower-*.f6434.8%

                                \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                              5. lift-pow.f64N/A

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

                                \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                              7. lower-*.f6434.8%

                                \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                              8. lift-pow.f64N/A

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

                                \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                              10. lower-*.f6434.8%

                                \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                            6. Applied rewrites34.8%

                              \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]

                            if -0.02 < (*.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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
                              2. +-commutativeN/A

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

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

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

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

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

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

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

                                \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
                              4. lower-*.f6475.0%

                                \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
                            6. Applied rewrites75.0%

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

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

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

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

                                \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + \color{blue}{\frac{1}{2} \cdot im}\right)\right)\right) \]
                              4. lower-*.f6488.3%

                                \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot \color{blue}{im}\right)\right)\right) \]
                            9. Applied rewrites88.3%

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

                              \[\leadsto \color{blue}{\frac{1}{2}} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right) \]
                            11. Step-by-step derivation
                              1. Applied rewrites56.1%

                                \[\leadsto \color{blue}{0.5} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im \cdot \left(1 + 0.5 \cdot im\right)\right)\right) \]
                            12. Recombined 2 regimes into one program.
                            13. Add Preprocessing

                            Alternative 10: 62.5% accurate, 0.9× speedup?

                            \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right) \leq -0.02:\\ \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\ \end{array} \]
                            (FPCore (re im)
                              :precision binary64
                              (if (<=
                                 (* (* 0.5 (cos re)) (+ (exp (- (fabs im))) (exp (fabs im))))
                                 -0.02)
                              (* (+ 0.5 (* -0.25 (sqrt (* (* re re) (* re re))))) 2.0)
                              (*
                               0.5
                               (*
                                (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))
                                (+ 1.0 (fabs im))))))
                            double code(double re, double im) {
                            	double tmp;
                            	if (((0.5 * cos(re)) * (exp(-fabs(im)) + exp(fabs(im)))) <= -0.02) {
                            		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                            	} else {
                            		tmp = 0.5 * ((2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0))) * (1.0 + fabs(im)));
                            	}
                            	return tmp;
                            }
                            
                            module fmin_fmax_functions
                                implicit none
                                private
                                public fmax
                                public fmin
                            
                                interface fmax
                                    module procedure fmax88
                                    module procedure fmax44
                                    module procedure fmax84
                                    module procedure fmax48
                                end interface
                                interface fmin
                                    module procedure fmin88
                                    module procedure fmin44
                                    module procedure fmin84
                                    module procedure fmin48
                                end interface
                            contains
                                real(8) function fmax88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmax44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmax84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmax48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                end function
                                real(8) function fmin88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmin44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmin84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmin48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                end function
                            end module
                            
                            real(8) function code(re, im)
                            use fmin_fmax_functions
                                real(8), intent (in) :: re
                                real(8), intent (in) :: im
                                real(8) :: tmp
                                if (((0.5d0 * cos(re)) * (exp(-abs(im)) + exp(abs(im)))) <= (-0.02d0)) then
                                    tmp = (0.5d0 + ((-0.25d0) * sqrt(((re * re) * (re * re))))) * 2.0d0
                                else
                                    tmp = 0.5d0 * ((2.0d0 + (abs(im) * ((2.0d0 * abs(im)) - 2.0d0))) * (1.0d0 + abs(im)))
                                end if
                                code = tmp
                            end function
                            
                            public static double code(double re, double im) {
                            	double tmp;
                            	if (((0.5 * Math.cos(re)) * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)))) <= -0.02) {
                            		tmp = (0.5 + (-0.25 * Math.sqrt(((re * re) * (re * re))))) * 2.0;
                            	} else {
                            		tmp = 0.5 * ((2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0))) * (1.0 + Math.abs(im)));
                            	}
                            	return tmp;
                            }
                            
                            def code(re, im):
                            	tmp = 0
                            	if ((0.5 * math.cos(re)) * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))) <= -0.02:
                            		tmp = (0.5 + (-0.25 * math.sqrt(((re * re) * (re * re))))) * 2.0
                            	else:
                            		tmp = 0.5 * ((2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))) * (1.0 + math.fabs(im)))
                            	return tmp
                            
                            function code(re, im)
                            	tmp = 0.0
                            	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-abs(im))) + exp(abs(im)))) <= -0.02)
                            		tmp = Float64(Float64(0.5 + Float64(-0.25 * sqrt(Float64(Float64(re * re) * Float64(re * re))))) * 2.0);
                            	else
                            		tmp = Float64(0.5 * Float64(Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0))) * Float64(1.0 + abs(im))));
                            	end
                            	return tmp
                            end
                            
                            function tmp_2 = code(re, im)
                            	tmp = 0.0;
                            	if (((0.5 * cos(re)) * (exp(-abs(im)) + exp(abs(im)))) <= -0.02)
                            		tmp = (0.5 + (-0.25 * sqrt(((re * re) * (re * re))))) * 2.0;
                            	else
                            		tmp = 0.5 * ((2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0))) * (1.0 + abs(im)));
                            	end
                            	tmp_2 = tmp;
                            end
                            
                            code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(0.5 + N[(-0.25 * N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], N[(0.5 * N[(N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                            
                            \begin{array}{l}
                            \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right) \leq -0.02:\\
                            \;\;\;\;\left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;0.5 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\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 (neg.f64 im)) (exp.f64 im))) < -0.02

                              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 rewrites51.4%

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

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

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

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

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

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

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

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

                                    \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                                  4. lower-*.f6434.8%

                                    \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{{re}^{2} \cdot {re}^{2}}\right) \cdot 2 \]
                                  5. lift-pow.f64N/A

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

                                    \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                                  7. lower-*.f6434.8%

                                    \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot {re}^{2}}\right) \cdot 2 \]
                                  8. lift-pow.f64N/A

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

                                    \[\leadsto \left(\frac{1}{2} + \frac{-1}{4} \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                                  10. lower-*.f6434.8%

                                    \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]
                                6. Applied rewrites34.8%

                                  \[\leadsto \left(0.5 + -0.25 \cdot \sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)}\right) \cdot 2 \]

                                if -0.02 < (*.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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
                                  2. +-commutativeN/A

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

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

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

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

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

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

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

                                    \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
                                  4. lower-*.f6475.0%

                                    \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
                                6. Applied rewrites75.0%

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

                                  \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
                                8. Step-by-step derivation
                                  1. lower-+.f6467.4%

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

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

                                  \[\leadsto \color{blue}{\frac{1}{2}} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
                                11. Step-by-step derivation
                                  1. Applied rewrites44.9%

                                    \[\leadsto \color{blue}{0.5} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
                                12. Recombined 2 regimes into one program.
                                13. Add Preprocessing

                                Alternative 11: 59.6% accurate, 0.9× speedup?

                                \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right) \leq -0.02:\\ \;\;\;\;2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\right|\right)\right)\\ \end{array} \]
                                (FPCore (re im)
                                  :precision binary64
                                  (if (<=
                                     (* (* 0.5 (cos re)) (+ (exp (- (fabs im))) (exp (fabs im))))
                                     -0.02)
                                  (* 2.0 (- (* (* re re) -0.25) -0.5))
                                  (*
                                   0.5
                                   (*
                                    (+ 2.0 (* (fabs im) (- (* 2.0 (fabs im)) 2.0)))
                                    (+ 1.0 (fabs im))))))
                                double code(double re, double im) {
                                	double tmp;
                                	if (((0.5 * cos(re)) * (exp(-fabs(im)) + exp(fabs(im)))) <= -0.02) {
                                		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                	} else {
                                		tmp = 0.5 * ((2.0 + (fabs(im) * ((2.0 * fabs(im)) - 2.0))) * (1.0 + fabs(im)));
                                	}
                                	return tmp;
                                }
                                
                                module fmin_fmax_functions
                                    implicit none
                                    private
                                    public fmax
                                    public fmin
                                
                                    interface fmax
                                        module procedure fmax88
                                        module procedure fmax44
                                        module procedure fmax84
                                        module procedure fmax48
                                    end interface
                                    interface fmin
                                        module procedure fmin88
                                        module procedure fmin44
                                        module procedure fmin84
                                        module procedure fmin48
                                    end interface
                                contains
                                    real(8) function fmax88(x, y) result (res)
                                        real(8), intent (in) :: x
                                        real(8), intent (in) :: y
                                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                    end function
                                    real(4) function fmax44(x, y) result (res)
                                        real(4), intent (in) :: x
                                        real(4), intent (in) :: y
                                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                    end function
                                    real(8) function fmax84(x, y) result(res)
                                        real(8), intent (in) :: x
                                        real(4), intent (in) :: y
                                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                    end function
                                    real(8) function fmax48(x, y) result(res)
                                        real(4), intent (in) :: x
                                        real(8), intent (in) :: y
                                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                    end function
                                    real(8) function fmin88(x, y) result (res)
                                        real(8), intent (in) :: x
                                        real(8), intent (in) :: y
                                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                    end function
                                    real(4) function fmin44(x, y) result (res)
                                        real(4), intent (in) :: x
                                        real(4), intent (in) :: y
                                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                    end function
                                    real(8) function fmin84(x, y) result(res)
                                        real(8), intent (in) :: x
                                        real(4), intent (in) :: y
                                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                    end function
                                    real(8) function fmin48(x, y) result(res)
                                        real(4), intent (in) :: x
                                        real(8), intent (in) :: y
                                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                    end function
                                end module
                                
                                real(8) function code(re, im)
                                use fmin_fmax_functions
                                    real(8), intent (in) :: re
                                    real(8), intent (in) :: im
                                    real(8) :: tmp
                                    if (((0.5d0 * cos(re)) * (exp(-abs(im)) + exp(abs(im)))) <= (-0.02d0)) then
                                        tmp = 2.0d0 * (((re * re) * (-0.25d0)) - (-0.5d0))
                                    else
                                        tmp = 0.5d0 * ((2.0d0 + (abs(im) * ((2.0d0 * abs(im)) - 2.0d0))) * (1.0d0 + abs(im)))
                                    end if
                                    code = tmp
                                end function
                                
                                public static double code(double re, double im) {
                                	double tmp;
                                	if (((0.5 * Math.cos(re)) * (Math.exp(-Math.abs(im)) + Math.exp(Math.abs(im)))) <= -0.02) {
                                		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                	} else {
                                		tmp = 0.5 * ((2.0 + (Math.abs(im) * ((2.0 * Math.abs(im)) - 2.0))) * (1.0 + Math.abs(im)));
                                	}
                                	return tmp;
                                }
                                
                                def code(re, im):
                                	tmp = 0
                                	if ((0.5 * math.cos(re)) * (math.exp(-math.fabs(im)) + math.exp(math.fabs(im)))) <= -0.02:
                                		tmp = 2.0 * (((re * re) * -0.25) - -0.5)
                                	else:
                                		tmp = 0.5 * ((2.0 + (math.fabs(im) * ((2.0 * math.fabs(im)) - 2.0))) * (1.0 + math.fabs(im)))
                                	return tmp
                                
                                function code(re, im)
                                	tmp = 0.0
                                	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-abs(im))) + exp(abs(im)))) <= -0.02)
                                		tmp = Float64(2.0 * Float64(Float64(Float64(re * re) * -0.25) - -0.5));
                                	else
                                		tmp = Float64(0.5 * Float64(Float64(2.0 + Float64(abs(im) * Float64(Float64(2.0 * abs(im)) - 2.0))) * Float64(1.0 + abs(im))));
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(re, im)
                                	tmp = 0.0;
                                	if (((0.5 * cos(re)) * (exp(-abs(im)) + exp(abs(im)))) <= -0.02)
                                		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                	else
                                		tmp = 0.5 * ((2.0 + (abs(im) * ((2.0 * abs(im)) - 2.0))) * (1.0 + abs(im)));
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[re_, im_] := If[LessEqual[N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] + N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.02], N[(2.0 * N[(N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(2.0 + N[(N[Abs[im], $MachinePrecision] * N[(N[(2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
                                
                                \begin{array}{l}
                                \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-\left|im\right|} + e^{\left|im\right|}\right) \leq -0.02:\\
                                \;\;\;\;2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right)\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;0.5 \cdot \left(\left(2 + \left|im\right| \cdot \left(2 \cdot \left|im\right| - 2\right)\right) \cdot \left(1 + \left|im\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 (neg.f64 im)) (exp.f64 im))) < -0.02

                                  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 rewrites51.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{4} - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right) \]
                                      13. lower-*.f64N/A

                                        \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{4} - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right) \]
                                      14. metadata-eval32.0%

                                        \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right) \]
                                    6. Applied rewrites32.0%

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

                                    if -0.02 < (*.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 \left(\frac{1}{2} \cdot \cos re\right) \cdot \color{blue}{\left(e^{-im} + e^{im}\right)} \]
                                      2. +-commutativeN/A

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

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

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

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

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

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

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

                                        \[\leadsto \left(\frac{1}{2} \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - \color{blue}{2}\right)\right) \cdot e^{im}\right) \]
                                      4. lower-*.f6475.0%

                                        \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot e^{im}\right) \]
                                    6. Applied rewrites75.0%

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

                                      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \color{blue}{\left(1 + im\right)}\right) \]
                                    8. Step-by-step derivation
                                      1. lower-+.f6467.4%

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

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

                                      \[\leadsto \color{blue}{\frac{1}{2}} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
                                    11. Step-by-step derivation
                                      1. Applied rewrites44.9%

                                        \[\leadsto \color{blue}{0.5} \cdot \left(\left(2 + im \cdot \left(2 \cdot im - 2\right)\right) \cdot \left(1 + im\right)\right) \]
                                    12. Recombined 2 regimes into one program.
                                    13. Add Preprocessing

                                    Alternative 12: 34.8% accurate, 0.9× speedup?

                                    \[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.02:\\ \;\;\;\;2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot 2\\ \end{array} \]
                                    (FPCore (re im)
                                      :precision binary64
                                      (if (<= (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))) -0.02)
                                      (* 2.0 (- (* (* re re) -0.25) -0.5))
                                      (* 0.5 2.0)))
                                    double code(double re, double im) {
                                    	double tmp;
                                    	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02) {
                                    		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                    	} else {
                                    		tmp = 0.5 * 2.0;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    module fmin_fmax_functions
                                        implicit none
                                        private
                                        public fmax
                                        public fmin
                                    
                                        interface fmax
                                            module procedure fmax88
                                            module procedure fmax44
                                            module procedure fmax84
                                            module procedure fmax48
                                        end interface
                                        interface fmin
                                            module procedure fmin88
                                            module procedure fmin44
                                            module procedure fmin84
                                            module procedure fmin48
                                        end interface
                                    contains
                                        real(8) function fmax88(x, y) result (res)
                                            real(8), intent (in) :: x
                                            real(8), intent (in) :: y
                                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                        end function
                                        real(4) function fmax44(x, y) result (res)
                                            real(4), intent (in) :: x
                                            real(4), intent (in) :: y
                                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                        end function
                                        real(8) function fmax84(x, y) result(res)
                                            real(8), intent (in) :: x
                                            real(4), intent (in) :: y
                                            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                        end function
                                        real(8) function fmax48(x, y) result(res)
                                            real(4), intent (in) :: x
                                            real(8), intent (in) :: y
                                            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                        end function
                                        real(8) function fmin88(x, y) result (res)
                                            real(8), intent (in) :: x
                                            real(8), intent (in) :: y
                                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                        end function
                                        real(4) function fmin44(x, y) result (res)
                                            real(4), intent (in) :: x
                                            real(4), intent (in) :: y
                                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                        end function
                                        real(8) function fmin84(x, y) result(res)
                                            real(8), intent (in) :: x
                                            real(4), intent (in) :: y
                                            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                        end function
                                        real(8) function fmin48(x, y) result(res)
                                            real(4), intent (in) :: x
                                            real(8), intent (in) :: y
                                            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                        end function
                                    end module
                                    
                                    real(8) function code(re, im)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: re
                                        real(8), intent (in) :: im
                                        real(8) :: tmp
                                        if (((0.5d0 * cos(re)) * (exp(-im) + exp(im))) <= (-0.02d0)) then
                                            tmp = 2.0d0 * (((re * re) * (-0.25d0)) - (-0.5d0))
                                        else
                                            tmp = 0.5d0 * 2.0d0
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double re, double im) {
                                    	double tmp;
                                    	if (((0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im))) <= -0.02) {
                                    		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                    	} else {
                                    		tmp = 0.5 * 2.0;
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(re, im):
                                    	tmp = 0
                                    	if ((0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))) <= -0.02:
                                    		tmp = 2.0 * (((re * re) * -0.25) - -0.5)
                                    	else:
                                    		tmp = 0.5 * 2.0
                                    	return tmp
                                    
                                    function code(re, im)
                                    	tmp = 0.0
                                    	if (Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) <= -0.02)
                                    		tmp = Float64(2.0 * Float64(Float64(Float64(re * re) * -0.25) - -0.5));
                                    	else
                                    		tmp = Float64(0.5 * 2.0);
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(re, im)
                                    	tmp = 0.0;
                                    	if (((0.5 * cos(re)) * (exp(-im) + exp(im))) <= -0.02)
                                    		tmp = 2.0 * (((re * re) * -0.25) - -0.5);
                                    	else
                                    		tmp = 0.5 * 2.0;
                                    	end
                                    	tmp_2 = 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.02], N[(2.0 * N[(N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision] - -0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * 2.0), $MachinePrecision]]
                                    
                                    \begin{array}{l}
                                    \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right) \leq -0.02:\\
                                    \;\;\;\;2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right)\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;0.5 \cdot 2\\
                                    
                                    
                                    \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.02

                                      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 rewrites51.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{4} - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right) \]
                                          13. lower-*.f64N/A

                                            \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot \frac{-1}{4} - \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right) \]
                                          14. metadata-eval32.0%

                                            \[\leadsto 2 \cdot \left(\left(re \cdot re\right) \cdot -0.25 - -0.5\right) \]
                                        6. Applied rewrites32.0%

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

                                        if -0.02 < (*.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. 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 rewrites51.4%

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

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

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

                                          Alternative 13: 28.4% accurate, 52.7× 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 rewrites51.4%

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

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

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

                                              Reproduce

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