math.exp on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 4.1s
Alternatives: 12
Speedup: 1.0×

Specification

?
\[e^{re} \cdot \cos im \]
(FPCore (re im)
  :precision binary64
  (* (exp re) (cos im)))
double code(double re, double im) {
	return exp(re) * cos(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 = exp(re) * cos(im)
end function
public static double code(double re, double im) {
	return Math.exp(re) * Math.cos(im);
}
def code(re, im):
	return math.exp(re) * math.cos(im)
function code(re, im)
	return Float64(exp(re) * cos(im))
end
function tmp = code(re, im)
	tmp = exp(re) * cos(im);
end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
e^{re} \cdot \cos im

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 12 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?

\[e^{re} \cdot \cos im \]
(FPCore (re im)
  :precision binary64
  (* (exp re) (cos im)))
double code(double re, double im) {
	return exp(re) * cos(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 = exp(re) * cos(im)
end function
public static double code(double re, double im) {
	return Math.exp(re) * Math.cos(im);
}
def code(re, im):
	return math.exp(re) * math.cos(im)
function code(re, im)
	return Float64(exp(re) * cos(im))
end
function tmp = code(re, im)
	tmp = exp(re) * cos(im);
end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
e^{re} \cdot \cos im

Alternative 1: 70.7% accurate, 1.1× speedup?

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

\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\right) \cdot \cos im\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 1e103

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + \left(\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \cdot re + re\right)\right) \cdot \cos im \]
      6. flip-+N/A

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

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

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

    if 1e103 < re

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

Alternative 2: 70.0% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := 0.5 + 0.16666666666666666 \cdot re\\ t_1 := e^{re} \cdot \cos im\\ t_2 := 1 + re \cdot \left(1 + re \cdot t\_0\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;t\_2 \cdot \left(1 + -0.5 \cdot {im}^{2}\right)\\ \mathbf{elif}\;t\_1 \leq 0.99998:\\ \;\;\;\;t\_2 \cdot \cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot t\_0\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (+ 0.5 (* 0.16666666666666666 re)))
       (t_1 (* (exp re) (cos im)))
       (t_2 (+ 1.0 (* re (+ 1.0 (* re t_0))))))
  (if (<= t_1 (- INFINITY))
    (* t_2 (+ 1.0 (* -0.5 (pow im 2.0))))
    (if (<= t_1 0.99998)
      (* t_2 (cos im))
      (-
       (+ 1.0 re)
       (* -1.0 (* (sqrt (* (* re re) (* re re))) t_0)))))))
double code(double re, double im) {
	double t_0 = 0.5 + (0.16666666666666666 * re);
	double t_1 = exp(re) * cos(im);
	double t_2 = 1.0 + (re * (1.0 + (re * t_0)));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_2 * (1.0 + (-0.5 * pow(im, 2.0)));
	} else if (t_1 <= 0.99998) {
		tmp = t_2 * cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * t_0));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = 0.5 + (0.16666666666666666 * re);
	double t_1 = Math.exp(re) * Math.cos(im);
	double t_2 = 1.0 + (re * (1.0 + (re * t_0)));
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = t_2 * (1.0 + (-0.5 * Math.pow(im, 2.0)));
	} else if (t_1 <= 0.99998) {
		tmp = t_2 * Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * t_0));
	}
	return tmp;
}
def code(re, im):
	t_0 = 0.5 + (0.16666666666666666 * re)
	t_1 = math.exp(re) * math.cos(im)
	t_2 = 1.0 + (re * (1.0 + (re * t_0)))
	tmp = 0
	if t_1 <= -math.inf:
		tmp = t_2 * (1.0 + (-0.5 * math.pow(im, 2.0)))
	elif t_1 <= 0.99998:
		tmp = t_2 * math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * t_0))
	return tmp
function code(re, im)
	t_0 = Float64(0.5 + Float64(0.16666666666666666 * re))
	t_1 = Float64(exp(re) * cos(im))
	t_2 = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * t_0))))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(t_2 * Float64(1.0 + Float64(-0.5 * (im ^ 2.0))));
	elseif (t_1 <= 0.99998)
		tmp = Float64(t_2 * cos(im));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * t_0)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = 0.5 + (0.16666666666666666 * re);
	t_1 = exp(re) * cos(im);
	t_2 = 1.0 + (re * (1.0 + (re * t_0)));
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = t_2 * (1.0 + (-0.5 * (im ^ 2.0)));
	elseif (t_1 <= 0.99998)
		tmp = t_2 * cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * t_0));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[(re * N[(1.0 + N[(re * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(t$95$2 * N[(1.0 + N[(-0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.99998], N[(t$95$2 * N[Cos[im], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
t_0 := 0.5 + 0.16666666666666666 \cdot re\\
t_1 := e^{re} \cdot \cos im\\
t_2 := 1 + re \cdot \left(1 + re \cdot t\_0\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;t\_2 \cdot \left(1 + -0.5 \cdot {im}^{2}\right)\\

\mathbf{elif}\;t\_1 \leq 0.99998:\\
\;\;\;\;t\_2 \cdot \cos im\\

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


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re \cdot \left(1 + re \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\right) \cdot \left(1 + -0.5 \cdot {im}^{\color{blue}{2}}\right) \]
    7. Applied rewrites40.0%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 3: 69.8% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := e^{re} \cdot \cos im\\ t_1 := 0.5 + 0.16666666666666666 \cdot re\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{elif}\;t\_0 \leq 0.99998:\\ \;\;\;\;\left(1 + re \cdot \left(1 + re \cdot t\_1\right)\right) \cdot \cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot t\_1\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* (exp re) (cos im)))
       (t_1 (+ 0.5 (* 0.16666666666666666 re))))
  (if (<= t_0 (- INFINITY))
    (*
     (- (* (- (* 0.5 re) -1.0) re) -1.0)
     (- (* (* im im) -0.5) -1.0))
    (if (<= t_0 0.99998)
      (* (+ 1.0 (* re (+ 1.0 (* re t_1)))) (cos im))
      (-
       (+ 1.0 re)
       (* -1.0 (* (sqrt (* (* re re) (* re re))) t_1)))))))
double code(double re, double im) {
	double t_0 = exp(re) * cos(im);
	double t_1 = 0.5 + (0.16666666666666666 * re);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + (re * (1.0 + (re * t_1)))) * cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * t_1));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(re) * Math.cos(im);
	double t_1 = 0.5 + (0.16666666666666666 * re);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + (re * (1.0 + (re * t_1)))) * Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * t_1));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(re) * math.cos(im)
	t_1 = 0.5 + (0.16666666666666666 * re)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	elif t_0 <= 0.99998:
		tmp = (1.0 + (re * (1.0 + (re * t_1)))) * math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * t_1))
	return tmp
function code(re, im)
	t_0 = Float64(exp(re) * cos(im))
	t_1 = Float64(0.5 + Float64(0.16666666666666666 * re))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	elseif (t_0 <= 0.99998)
		tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * t_1)))) * cos(im));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * t_1)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(re) * cos(im);
	t_1 = 0.5 + (0.16666666666666666 * re);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	elseif (t_0 <= 0.99998)
		tmp = (1.0 + (re * (1.0 + (re * t_1)))) * cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * t_1));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99998], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := e^{re} \cdot \cos im\\
t_1 := 0.5 + 0.16666666666666666 \cdot re\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{elif}\;t\_0 \leq 0.99998:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot t\_1\right)\right) \cdot \cos im\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot t\_1\right)\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 4: 69.8% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := e^{re} \cdot \cos im\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{elif}\;t\_0 \leq 0.99998:\\ \;\;\;\;\left(re + \left(\left(0.5 \cdot re\right) \cdot re - -1\right)\right) \cdot \cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* (exp re) (cos im))))
  (if (<= t_0 (- INFINITY))
    (*
     (- (* (- (* 0.5 re) -1.0) re) -1.0)
     (- (* (* im im) -0.5) -1.0))
    (if (<= t_0 0.99998)
      (* (+ re (- (* (* 0.5 re) re) -1.0)) (cos im))
      (-
       (+ 1.0 re)
       (*
        -1.0
        (*
         (sqrt (* (* re re) (* re re)))
         (+ 0.5 (* 0.16666666666666666 re)))))))))
double code(double re, double im) {
	double t_0 = exp(re) * cos(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (re + (((0.5 * re) * re) - -1.0)) * cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(re) * Math.cos(im);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (re + (((0.5 * re) * re) - -1.0)) * Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(re) * math.cos(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	elif t_0 <= 0.99998:
		tmp = (re + (((0.5 * re) * re) - -1.0)) * math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(re) * cos(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	elseif (t_0 <= 0.99998)
		tmp = Float64(Float64(re + Float64(Float64(Float64(0.5 * re) * re) - -1.0)) * cos(im));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * Float64(0.5 + Float64(0.16666666666666666 * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(re) * cos(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	elseif (t_0 <= 0.99998)
		tmp = (re + (((0.5 * re) * re) - -1.0)) * cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99998], N[(N[(re + N[(N[(N[(0.5 * re), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := e^{re} \cdot \cos im\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{elif}\;t\_0 \leq 0.99998:\\
\;\;\;\;\left(re + \left(\left(0.5 \cdot re\right) \cdot re - -1\right)\right) \cdot \cos im\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(1 \cdot re + \left(\frac{1}{2} \cdot re\right) \cdot re\right) + 1\right) \cdot \cos im \]
      6. *-lft-identityN/A

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

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

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

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

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

        \[\leadsto \left(re + \left(\left(\frac{1}{2} \cdot re\right) \cdot re - \left(\mathsf{neg}\left(\color{blue}{1}\right)\right)\right)\right) \cdot \cos im \]
      12. metadata-eval63.2%

        \[\leadsto \left(re + \left(\left(0.5 \cdot re\right) \cdot re - -1\right)\right) \cdot \cos im \]
    6. Applied rewrites63.2%

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

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 5: 69.8% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := e^{re} \cdot \cos im\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{elif}\;t\_0 \leq 0.99998:\\ \;\;\;\;\left(1 + re \cdot \left(1 + 0.5 \cdot re\right)\right) \cdot \cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* (exp re) (cos im))))
  (if (<= t_0 (- INFINITY))
    (*
     (- (* (- (* 0.5 re) -1.0) re) -1.0)
     (- (* (* im im) -0.5) -1.0))
    (if (<= t_0 0.99998)
      (* (+ 1.0 (* re (+ 1.0 (* 0.5 re)))) (cos im))
      (-
       (+ 1.0 re)
       (*
        -1.0
        (*
         (sqrt (* (* re re) (* re re)))
         (+ 0.5 (* 0.16666666666666666 re)))))))))
double code(double re, double im) {
	double t_0 = exp(re) * cos(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + (re * (1.0 + (0.5 * re)))) * cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(re) * Math.cos(im);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + (re * (1.0 + (0.5 * re)))) * Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(re) * math.cos(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	elif t_0 <= 0.99998:
		tmp = (1.0 + (re * (1.0 + (0.5 * re)))) * math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(re) * cos(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	elseif (t_0 <= 0.99998)
		tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(0.5 * re)))) * cos(im));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * Float64(0.5 + Float64(0.16666666666666666 * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(re) * cos(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	elseif (t_0 <= 0.99998)
		tmp = (1.0 + (re * (1.0 + (0.5 * re)))) * cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99998], N[(N[(1.0 + N[(re * N[(1.0 + N[(0.5 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := e^{re} \cdot \cos im\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{elif}\;t\_0 \leq 0.99998:\\
\;\;\;\;\left(1 + re \cdot \left(1 + 0.5 \cdot re\right)\right) \cdot \cos im\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 6: 69.8% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := e^{re} \cdot \cos im\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{elif}\;t\_0 \leq 0.99998:\\ \;\;\;\;\left(1 + re\right) \cdot \cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* (exp re) (cos im))))
  (if (<= t_0 (- INFINITY))
    (*
     (- (* (- (* 0.5 re) -1.0) re) -1.0)
     (- (* (* im im) -0.5) -1.0))
    (if (<= t_0 0.99998)
      (* (+ 1.0 re) (cos im))
      (-
       (+ 1.0 re)
       (*
        -1.0
        (*
         (sqrt (* (* re re) (* re re)))
         (+ 0.5 (* 0.16666666666666666 re)))))))))
double code(double re, double im) {
	double t_0 = exp(re) * cos(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + re) * cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(re) * Math.cos(im);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = (1.0 + re) * Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(re) * math.cos(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	elif t_0 <= 0.99998:
		tmp = (1.0 + re) * math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(re) * cos(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	elseif (t_0 <= 0.99998)
		tmp = Float64(Float64(1.0 + re) * cos(im));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * Float64(0.5 + Float64(0.16666666666666666 * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(re) * cos(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	elseif (t_0 <= 0.99998)
		tmp = (1.0 + re) * cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99998], N[(N[(1.0 + re), $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := e^{re} \cdot \cos im\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{elif}\;t\_0 \leq 0.99998:\\
\;\;\;\;\left(1 + re\right) \cdot \cos im\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

        \[\leadsto \left(1 + \color{blue}{re}\right) \cdot \cos im \]
    4. Applied rewrites51.5%

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

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 7: 69.7% accurate, 0.4× speedup?

\[\begin{array}{l} t_0 := e^{re} \cdot \cos im\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{elif}\;t\_0 \leq 0.99998:\\ \;\;\;\;\cos im\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (let* ((t_0 (* (exp re) (cos im))))
  (if (<= t_0 (- INFINITY))
    (*
     (- (* (- (* 0.5 re) -1.0) re) -1.0)
     (- (* (* im im) -0.5) -1.0))
    (if (<= t_0 0.99998)
      (cos im)
      (-
       (+ 1.0 re)
       (*
        -1.0
        (*
         (sqrt (* (* re re) (* re re)))
         (+ 0.5 (* 0.16666666666666666 re)))))))))
double code(double re, double im) {
	double t_0 = exp(re) * cos(im);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
public static double code(double re, double im) {
	double t_0 = Math.exp(re) * Math.cos(im);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else if (t_0 <= 0.99998) {
		tmp = Math.cos(im);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
def code(re, im):
	t_0 = math.exp(re) * math.cos(im)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	elif t_0 <= 0.99998:
		tmp = math.cos(im)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))))
	return tmp
function code(re, im)
	t_0 = Float64(exp(re) * cos(im))
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	elseif (t_0 <= 0.99998)
		tmp = cos(im);
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * Float64(0.5 + Float64(0.16666666666666666 * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	t_0 = exp(re) * cos(im);
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	elseif (t_0 <= 0.99998)
		tmp = cos(im);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.99998], N[Cos[im], $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := e^{re} \cdot \cos im\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{elif}\;t\_0 \leq 0.99998:\\
\;\;\;\;\cos im\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\


\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -inf.0

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -inf.0 < (*.f64 (exp.f64 re) (cos.f64 im)) < 0.99997999999999998

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\cos im} \]
    3. Step-by-step derivation
      1. lower-cos.f6450.7%

        \[\leadsto \cos im \]
    4. Applied rewrites50.7%

      \[\leadsto \color{blue}{\cos im} \]

    if 0.99997999999999998 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 8: 69.1% accurate, 1.4× speedup?

\[\frac{\left(re - \left(-1 - \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right)\right) \cdot re}{re} \cdot \cos im \]
(FPCore (re im)
  :precision binary64
  (*
 (/
  (*
   (- re (- -1.0 (* (* (- (* 0.16666666666666666 re) -0.5) re) re)))
   re)
  re)
 (cos im)))
double code(double re, double im) {
	return (((re - (-1.0 - ((((0.16666666666666666 * re) - -0.5) * re) * re))) * re) / re) * cos(im);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (((re - ((-1.0d0) - ((((0.16666666666666666d0 * re) - (-0.5d0)) * re) * re))) * re) / re) * cos(im)
end function
public static double code(double re, double im) {
	return (((re - (-1.0 - ((((0.16666666666666666 * re) - -0.5) * re) * re))) * re) / re) * Math.cos(im);
}
def code(re, im):
	return (((re - (-1.0 - ((((0.16666666666666666 * re) - -0.5) * re) * re))) * re) / re) * math.cos(im)
function code(re, im)
	return Float64(Float64(Float64(Float64(re - Float64(-1.0 - Float64(Float64(Float64(Float64(0.16666666666666666 * re) - -0.5) * re) * re))) * re) / re) * cos(im))
end
function tmp = code(re, im)
	tmp = (((re - (-1.0 - ((((0.16666666666666666 * re) - -0.5) * re) * re))) * re) / re) * cos(im);
end
code[re_, im_] := N[(N[(N[(N[(re - N[(-1.0 - N[(N[(N[(N[(0.16666666666666666 * re), $MachinePrecision] - -0.5), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision] / re), $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\frac{\left(re - \left(-1 - \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right)\right) \cdot re}{re} \cdot \cos im
Derivation
  1. Initial program 100.0%

    \[e^{re} \cdot \cos im \]
  2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\left(1 \cdot re + \left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \cdot re\right) + 1\right) \cdot \cos im \]
    6. *-lft-identityN/A

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

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

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

      \[\leadsto \left(\left(1 + \frac{\left(re \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \cdot re + 1}{re}\right) \cdot \color{blue}{re}\right) \cdot \cos im \]
  6. Applied rewrites67.0%

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

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

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

      \[\leadsto \left(\left(1 + \frac{\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1}{re}\right) \cdot re\right) \cdot \cos im \]
    4. add-to-fractionN/A

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

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

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

      \[\leadsto \frac{\left(1 \cdot re + \left(\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1\right)\right) \cdot re}{re} \cdot \cos im \]
    8. *-lft-identityN/A

      \[\leadsto \frac{\left(re + \left(\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1\right)\right) \cdot re}{re} \cdot \cos im \]
    9. add-flipN/A

      \[\leadsto \frac{\left(re - \left(\mathsf{neg}\left(\left(\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1\right)\right)\right)\right) \cdot re}{re} \cdot \cos im \]
    10. lower--.f64N/A

      \[\leadsto \frac{\left(re - \left(\mathsf{neg}\left(\left(\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1\right)\right)\right)\right) \cdot re}{re} \cdot \cos im \]
    11. lift--.f64N/A

      \[\leadsto \frac{\left(re - \left(\mathsf{neg}\left(\left(\left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re - -1\right)\right)\right)\right) \cdot re}{re} \cdot \cos im \]
    12. sub-negate-revN/A

      \[\leadsto \frac{\left(re - \left(-1 - \left(\left(\frac{1}{6} \cdot re - \frac{-1}{2}\right) \cdot re\right) \cdot re\right)\right) \cdot re}{re} \cdot \cos im \]
    13. lower--.f6469.1%

      \[\leadsto \frac{\left(re - \left(-1 - \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right)\right) \cdot re}{re} \cdot \cos im \]
  8. Applied rewrites69.1%

    \[\leadsto \frac{\left(re - \left(-1 - \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right)\right) \cdot re}{\color{blue}{re}} \cdot \cos im \]
  9. Add Preprocessing

Alternative 9: 47.6% accurate, 0.8× speedup?

\[\begin{array}{l} \mathbf{if}\;e^{re} \cdot \cos im \leq -0.05:\\ \;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\ \end{array} \]
(FPCore (re im)
  :precision binary64
  (if (<= (* (exp re) (cos im)) -0.05)
  (* (- (* (- (* 0.5 re) -1.0) re) -1.0) (- (* (* im im) -0.5) -1.0))
  (-
   (+ 1.0 re)
   (*
    -1.0
    (*
     (sqrt (* (* re re) (* re re)))
     (+ 0.5 (* 0.16666666666666666 re)))))))
double code(double re, double im) {
	double tmp;
	if ((exp(re) * cos(im)) <= -0.05) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else {
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	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 ((exp(re) * cos(im)) <= (-0.05d0)) then
        tmp = ((((0.5d0 * re) - (-1.0d0)) * re) - (-1.0d0)) * (((im * im) * (-0.5d0)) - (-1.0d0))
    else
        tmp = (1.0d0 + re) - ((-1.0d0) * (sqrt(((re * re) * (re * re))) * (0.5d0 + (0.16666666666666666d0 * re))))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((Math.exp(re) * Math.cos(im)) <= -0.05) {
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	} else {
		tmp = (1.0 + re) - (-1.0 * (Math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (math.exp(re) * math.cos(im)) <= -0.05:
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0)
	else:
		tmp = (1.0 + re) - (-1.0 * (math.sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))))
	return tmp
function code(re, im)
	tmp = 0.0
	if (Float64(exp(re) * cos(im)) <= -0.05)
		tmp = Float64(Float64(Float64(Float64(Float64(0.5 * re) - -1.0) * re) - -1.0) * Float64(Float64(Float64(im * im) * -0.5) - -1.0));
	else
		tmp = Float64(Float64(1.0 + re) - Float64(-1.0 * Float64(sqrt(Float64(Float64(re * re) * Float64(re * re))) * Float64(0.5 + Float64(0.16666666666666666 * re)))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((exp(re) * cos(im)) <= -0.05)
		tmp = ((((0.5 * re) - -1.0) * re) - -1.0) * (((im * im) * -0.5) - -1.0);
	else
		tmp = (1.0 + re) - (-1.0 * (sqrt(((re * re) * (re * re))) * (0.5 + (0.16666666666666666 * re))));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision], -0.05], N[(N[(N[(N[(N[(0.5 * re), $MachinePrecision] - -1.0), $MachinePrecision] * re), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + re), $MachinePrecision] - N[(-1.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] * N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(0.5 + N[(0.16666666666666666 * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;e^{re} \cdot \cos im \leq -0.05:\\
\;\;\;\;\left(\left(0.5 \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\left(im \cdot im\right) \cdot -0.5 - -1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -0.050000000000000003

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -0.050000000000000003 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot {re}^{2}} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      9. lower-*.f6441.9%

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right) \]
      12. lower-*.f6441.9%

        \[\leadsto \left(1 + re\right) - -1 \cdot \left(\sqrt{\left(re \cdot re\right) \cdot \left(re \cdot re\right)} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    10. Applied rewrites41.9%

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

Alternative 10: 46.1% accurate, 0.8× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (exp.f64 re) (cos.f64 im)) < -0.050000000000000003

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lift-+.f64, \left(1 + \frac{-1}{2} \cdot {im}^{2}\right)\right) \]
      15. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(+-commutative, \left(\frac{-1}{2} \cdot {im}^{2} + 1\right)\right) \]
      16. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(add-flip, \left(\frac{-1}{2} \cdot {im}^{2} - \left(\mathsf{neg}\left(1\right)\right)\right)\right) \]
      17. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \left(\frac{-1}{2} \cdot {im}^{2} - \mathsf{Rewrite=>}\left(metadata-eval, -1\right)\right) \]
      18. lower--.f64N/A

        \[\leadsto \left(\left(\frac{1}{2} \cdot re - -1\right) \cdot re - -1\right) \cdot \mathsf{Rewrite=>}\left(lower--.f64, \left(\frac{-1}{2} \cdot {im}^{2} - -1\right)\right) \]
    9. Applied rewrites37.6%

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

    if -0.050000000000000003 < (*.f64 (exp.f64 re) (cos.f64 im))

    1. Initial program 100.0%

      \[e^{re} \cdot \cos im \]
    2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
      12. lower-cos.f6467.2%

        \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
    4. Applied rewrites67.2%

      \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
    5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

        \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
    8. Applied rewrites40.4%

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

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

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

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

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

        \[\leadsto \left(re - -1 \cdot \left({re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right) + 1 \]
    10. Applied rewrites40.4%

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

Alternative 11: 40.4% accurate, 8.2× speedup?

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

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

real(8) function code(re, im)
use fmin_fmax_functions
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (re + ((((0.16666666666666666d0 * re) - (-0.5d0)) * re) * re)) + 1.0d0
end function
public static double code(double re, double im) {
	return (re + ((((0.16666666666666666 * re) - -0.5) * re) * re)) + 1.0;
}
def code(re, im):
	return (re + ((((0.16666666666666666 * re) - -0.5) * re) * re)) + 1.0
function code(re, im)
	return Float64(Float64(re + Float64(Float64(Float64(Float64(0.16666666666666666 * re) - -0.5) * re) * re)) + 1.0)
end
function tmp = code(re, im)
	tmp = (re + ((((0.16666666666666666 * re) - -0.5) * re) * re)) + 1.0;
end
code[re_, im_] := N[(N[(re + N[(N[(N[(N[(0.16666666666666666 * re), $MachinePrecision] - -0.5), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]
\left(re + \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right) + 1
Derivation
  1. Initial program 100.0%

    \[e^{re} \cdot \cos im \]
  2. Taylor expanded in re around 0

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(\frac{1}{6} \cdot \left(re \cdot \cos im\right) + \frac{1}{2} \cdot \color{blue}{\cos im}\right)\right) \]
    12. lower-cos.f6467.2%

      \[\leadsto \cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right) \]
  4. Applied rewrites67.2%

    \[\leadsto \color{blue}{\cos im + re \cdot \left(\cos im + re \cdot \left(0.16666666666666666 \cdot \left(re \cdot \cos im\right) + 0.5 \cdot \cos im\right)\right)} \]
  5. Applied rewrites67.2%

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

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

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

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

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

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

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

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

      \[\leadsto \left(1 + re\right) - -1 \cdot \left({re}^{2} \cdot \left(0.5 + 0.16666666666666666 \cdot re\right)\right) \]
  8. Applied rewrites40.4%

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

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

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

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

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

      \[\leadsto \left(re - -1 \cdot \left({re}^{2} \cdot \left(\frac{1}{2} + \frac{1}{6} \cdot re\right)\right)\right) + 1 \]
  10. Applied rewrites40.4%

    \[\leadsto \left(re + \left(\left(0.16666666666666666 \cdot re - -0.5\right) \cdot re\right) \cdot re\right) + \color{blue}{1} \]
  11. Add Preprocessing

Reproduce

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