math.sin on complex, real part

Percentage Accurate: 100.0% → 75.3%
Time: 4.1s
Alternatives: 9
Speedup: N/A×

Specification

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

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 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?

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

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

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

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

Alternative 1: 75.3% accurate, 0.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\_m\\ t_1 := t\_0 \cdot \left(e^{0 - im\_m} + e^{im\_m}\right)\\ re\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -0.998:\\ \;\;\;\;\left(\left(\cosh im\_m \cdot 2\right) \cdot \left(\left(-0.16666666666666666 - 2\right) \cdot -0.16666666666666666\right)\right) \cdot 0.5\\ \mathbf{elif}\;t\_1 \leq 1:\\ \;\;\;\;t\_0 \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(re\_m \cdot \left(0.5 + -0.08333333333333333 \cdot {re\_m}^{2}\right)\right) \cdot \left(1 + e^{im\_m}\right)\\ \end{array} \end{array} \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re_m)))
        (t_1 (* t_0 (+ (exp (- 0.0 im_m)) (exp im_m)))))
   (*
    re_s
    (if (<= t_1 -0.998)
      (*
       (*
        (* (cosh im_m) 2.0)
        (* (- -0.16666666666666666 2.0) -0.16666666666666666))
       0.5)
      (if (<= t_1 1.0)
        (* t_0 2.0)
        (*
         (* re_m (+ 0.5 (* -0.08333333333333333 (pow re_m 2.0))))
         (+ 1.0 (exp im_m))))))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	double t_0 = 0.5 * sin(re_m);
	double t_1 = t_0 * (exp((0.0 - im_m)) + exp(im_m));
	double tmp;
	if (t_1 <= -0.998) {
		tmp = ((cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5;
	} else if (t_1 <= 1.0) {
		tmp = t_0 * 2.0;
	} else {
		tmp = (re_m * (0.5 + (-0.08333333333333333 * pow(re_m, 2.0)))) * (1.0 + exp(im_m));
	}
	return re_s * tmp;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = 0.5d0 * sin(re_m)
    t_1 = t_0 * (exp((0.0d0 - im_m)) + exp(im_m))
    if (t_1 <= (-0.998d0)) then
        tmp = ((cosh(im_m) * 2.0d0) * (((-0.16666666666666666d0) - 2.0d0) * (-0.16666666666666666d0))) * 0.5d0
    else if (t_1 <= 1.0d0) then
        tmp = t_0 * 2.0d0
    else
        tmp = (re_m * (0.5d0 + ((-0.08333333333333333d0) * (re_m ** 2.0d0)))) * (1.0d0 + exp(im_m))
    end if
    code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	double t_0 = 0.5 * Math.sin(re_m);
	double t_1 = t_0 * (Math.exp((0.0 - im_m)) + Math.exp(im_m));
	double tmp;
	if (t_1 <= -0.998) {
		tmp = ((Math.cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5;
	} else if (t_1 <= 1.0) {
		tmp = t_0 * 2.0;
	} else {
		tmp = (re_m * (0.5 + (-0.08333333333333333 * Math.pow(re_m, 2.0)))) * (1.0 + Math.exp(im_m));
	}
	return re_s * tmp;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	t_0 = 0.5 * math.sin(re_m)
	t_1 = t_0 * (math.exp((0.0 - im_m)) + math.exp(im_m))
	tmp = 0
	if t_1 <= -0.998:
		tmp = ((math.cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5
	elif t_1 <= 1.0:
		tmp = t_0 * 2.0
	else:
		tmp = (re_m * (0.5 + (-0.08333333333333333 * math.pow(re_m, 2.0)))) * (1.0 + math.exp(im_m))
	return re_s * tmp
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	t_0 = Float64(0.5 * sin(re_m))
	t_1 = Float64(t_0 * Float64(exp(Float64(0.0 - im_m)) + exp(im_m)))
	tmp = 0.0
	if (t_1 <= -0.998)
		tmp = Float64(Float64(Float64(cosh(im_m) * 2.0) * Float64(Float64(-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5);
	elseif (t_1 <= 1.0)
		tmp = Float64(t_0 * 2.0);
	else
		tmp = Float64(Float64(re_m * Float64(0.5 + Float64(-0.08333333333333333 * (re_m ^ 2.0)))) * Float64(1.0 + exp(im_m)));
	end
	return Float64(re_s * tmp)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp_2 = code(re_s, re_m, im_m)
	t_0 = 0.5 * sin(re_m);
	t_1 = t_0 * (exp((0.0 - im_m)) + exp(im_m));
	tmp = 0.0;
	if (t_1 <= -0.998)
		tmp = ((cosh(im_m) * 2.0) * ((-0.16666666666666666 - 2.0) * -0.16666666666666666)) * 0.5;
	elseif (t_1 <= 1.0)
		tmp = t_0 * 2.0;
	else
		tmp = (re_m * (0.5 + (-0.08333333333333333 * (re_m ^ 2.0)))) * (1.0 + exp(im_m));
	end
	tmp_2 = re_s * tmp;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[N[(0.0 - im$95$m), $MachinePrecision]], $MachinePrecision] + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(re$95$s * If[LessEqual[t$95$1, -0.998], N[(N[(N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision] * N[(N[(-0.16666666666666666 - 2.0), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$1, 1.0], N[(t$95$0 * 2.0), $MachinePrecision], N[(N[(re$95$m * N[(0.5 + N[(-0.08333333333333333 * N[Power[re$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\_m\\
t_1 := t\_0 \cdot \left(e^{0 - im\_m} + e^{im\_m}\right)\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -0.998:\\
\;\;\;\;\left(\left(\cosh im\_m \cdot 2\right) \cdot \left(\left(-0.16666666666666666 - 2\right) \cdot -0.16666666666666666\right)\right) \cdot 0.5\\

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

\mathbf{else}:\\
\;\;\;\;\left(re\_m \cdot \left(0.5 + -0.08333333333333333 \cdot {re\_m}^{2}\right)\right) \cdot \left(1 + e^{im\_m}\right)\\


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

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

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

      \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \left(\left(-0.16666666666666666 - 2\right) \cdot \color{blue}{-0.16666666666666666}\right)\right) \cdot 0.5 \]

    if -0.998 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 1

    1. Initial program 100.0%

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

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{2} \]
    3. Applied rewrites50.2%

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

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

    1. Initial program 100.0%

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

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

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

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

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

Alternative 2: 73.6% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ \begin{array}{l} t_0 := \cosh im\_m \cdot 2\\ re\_s \cdot \begin{array}{l} \mathbf{if}\;im\_m \leq 3.05 \cdot 10^{-5}:\\ \;\;\;\;\left(0.5 \cdot \sin re\_m\right) \cdot 2\\ \mathbf{elif}\;im\_m \leq 1.6 \cdot 10^{+181}:\\ \;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\ \end{array} \end{array} \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (let* ((t_0 (* (cosh im_m) 2.0)))
   (*
    re_s
    (if (<= im_m 3.05e-5)
      (* (* 0.5 (sin re_m)) 2.0)
      (if (<= im_m 1.6e+181)
        (* (* t_0 (* -0.16666666666666666 -0.16666666666666666)) 0.5)
        (* (* t_0 (- -0.16666666666666666 2.0)) 0.5))))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	double t_0 = cosh(im_m) * 2.0;
	double tmp;
	if (im_m <= 3.05e-5) {
		tmp = (0.5 * sin(re_m)) * 2.0;
	} else if (im_m <= 1.6e+181) {
		tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5;
	} else {
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	}
	return re_s * tmp;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cosh(im_m) * 2.0d0
    if (im_m <= 3.05d-5) then
        tmp = (0.5d0 * sin(re_m)) * 2.0d0
    else if (im_m <= 1.6d+181) then
        tmp = (t_0 * ((-0.16666666666666666d0) * (-0.16666666666666666d0))) * 0.5d0
    else
        tmp = (t_0 * ((-0.16666666666666666d0) - 2.0d0)) * 0.5d0
    end if
    code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	double t_0 = Math.cosh(im_m) * 2.0;
	double tmp;
	if (im_m <= 3.05e-5) {
		tmp = (0.5 * Math.sin(re_m)) * 2.0;
	} else if (im_m <= 1.6e+181) {
		tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5;
	} else {
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	}
	return re_s * tmp;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	t_0 = math.cosh(im_m) * 2.0
	tmp = 0
	if im_m <= 3.05e-5:
		tmp = (0.5 * math.sin(re_m)) * 2.0
	elif im_m <= 1.6e+181:
		tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5
	else:
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5
	return re_s * tmp
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	t_0 = Float64(cosh(im_m) * 2.0)
	tmp = 0.0
	if (im_m <= 3.05e-5)
		tmp = Float64(Float64(0.5 * sin(re_m)) * 2.0);
	elseif (im_m <= 1.6e+181)
		tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 * -0.16666666666666666)) * 0.5);
	else
		tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 - 2.0)) * 0.5);
	end
	return Float64(re_s * tmp)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp_2 = code(re_s, re_m, im_m)
	t_0 = cosh(im_m) * 2.0;
	tmp = 0.0;
	if (im_m <= 3.05e-5)
		tmp = (0.5 * sin(re_m)) * 2.0;
	elseif (im_m <= 1.6e+181)
		tmp = (t_0 * (-0.16666666666666666 * -0.16666666666666666)) * 0.5;
	else
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	end
	tmp_2 = re_s * tmp;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]}, N[(re$95$s * If[LessEqual[im$95$m, 3.05e-5], N[(N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[im$95$m, 1.6e+181], N[(N[(t$95$0 * N[(-0.16666666666666666 * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$0 * N[(-0.16666666666666666 - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
\begin{array}{l}
t_0 := \cosh im\_m \cdot 2\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;im\_m \leq 3.05 \cdot 10^{-5}:\\
\;\;\;\;\left(0.5 \cdot \sin re\_m\right) \cdot 2\\

\mathbf{elif}\;im\_m \leq 1.6 \cdot 10^{+181}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 \cdot -0.16666666666666666\right)\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 3.04999999999999994e-5

    1. Initial program 100.0%

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

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{2} \]
    3. Applied rewrites50.2%

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

    if 3.04999999999999994e-5 < im < 1.6e181

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

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

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

      \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \left(-0.16666666666666666 \cdot \color{blue}{-0.16666666666666666}\right)\right) \cdot 0.5 \]

    if 1.6e181 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

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

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

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

Alternative 3: 63.5% accurate, 1.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ \begin{array}{l} t_0 := \cosh im\_m \cdot 2\\ re\_s \cdot \begin{array}{l} \mathbf{if}\;0.5 \cdot \sin re\_m \leq 0.02:\\ \;\;\;\;\left(t\_0 \cdot re\_m\right) \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\ \end{array} \end{array} \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (let* ((t_0 (* (cosh im_m) 2.0)))
   (*
    re_s
    (if (<= (* 0.5 (sin re_m)) 0.02)
      (* (* t_0 re_m) 0.5)
      (* (* t_0 (- -0.16666666666666666 2.0)) 0.5)))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	double t_0 = cosh(im_m) * 2.0;
	double tmp;
	if ((0.5 * sin(re_m)) <= 0.02) {
		tmp = (t_0 * re_m) * 0.5;
	} else {
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	}
	return re_s * tmp;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = cosh(im_m) * 2.0d0
    if ((0.5d0 * sin(re_m)) <= 0.02d0) then
        tmp = (t_0 * re_m) * 0.5d0
    else
        tmp = (t_0 * ((-0.16666666666666666d0) - 2.0d0)) * 0.5d0
    end if
    code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	double t_0 = Math.cosh(im_m) * 2.0;
	double tmp;
	if ((0.5 * Math.sin(re_m)) <= 0.02) {
		tmp = (t_0 * re_m) * 0.5;
	} else {
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	}
	return re_s * tmp;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	t_0 = math.cosh(im_m) * 2.0
	tmp = 0
	if (0.5 * math.sin(re_m)) <= 0.02:
		tmp = (t_0 * re_m) * 0.5
	else:
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5
	return re_s * tmp
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	t_0 = Float64(cosh(im_m) * 2.0)
	tmp = 0.0
	if (Float64(0.5 * sin(re_m)) <= 0.02)
		tmp = Float64(Float64(t_0 * re_m) * 0.5);
	else
		tmp = Float64(Float64(t_0 * Float64(-0.16666666666666666 - 2.0)) * 0.5);
	end
	return Float64(re_s * tmp)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp_2 = code(re_s, re_m, im_m)
	t_0 = cosh(im_m) * 2.0;
	tmp = 0.0;
	if ((0.5 * sin(re_m)) <= 0.02)
		tmp = (t_0 * re_m) * 0.5;
	else
		tmp = (t_0 * (-0.16666666666666666 - 2.0)) * 0.5;
	end
	tmp_2 = re_s * tmp;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := Block[{t$95$0 = N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision]}, N[(re$95$s * If[LessEqual[N[(0.5 * N[Sin[re$95$m], $MachinePrecision]), $MachinePrecision], 0.02], N[(N[(t$95$0 * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$0 * N[(-0.16666666666666666 - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
\begin{array}{l}
t_0 := \cosh im\_m \cdot 2\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin re\_m \leq 0.02:\\
\;\;\;\;\left(t\_0 \cdot re\_m\right) \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \left(-0.16666666666666666 - 2\right)\right) \cdot 0.5\\


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

      \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \color{blue}{re}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites63.5%

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

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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

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

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

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

Alternative 4: 62.9% accurate, 3.1× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot \left(\left(\left(\cosh im\_m \cdot 2\right) \cdot re\_m\right) \cdot 0.5\right) \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (* re_s (* (* (* (cosh im_m) 2.0) re_m) 0.5)))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	return re_s * (((cosh(im_m) * 2.0) * re_m) * 0.5);
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = re_s * (((cosh(im_m) * 2.0d0) * re_m) * 0.5d0)
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	return re_s * (((Math.cosh(im_m) * 2.0) * re_m) * 0.5);
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	return re_s * (((math.cosh(im_m) * 2.0) * re_m) * 0.5)
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	return Float64(re_s * Float64(Float64(Float64(cosh(im_m) * 2.0) * re_m) * 0.5))
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp = code(re_s, re_m, im_m)
	tmp = re_s * (((cosh(im_m) * 2.0) * re_m) * 0.5);
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(N[(N[(N[Cosh[im$95$m], $MachinePrecision] * 2.0), $MachinePrecision] * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot \left(\left(\left(\cosh im\_m \cdot 2\right) \cdot re\_m\right) \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Applied rewrites100.0%

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

    \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \color{blue}{re}\right) \cdot \frac{1}{2} \]
  4. Applied rewrites63.5%

    \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \color{blue}{re}\right) \cdot 0.5 \]
  5. Add Preprocessing

Alternative 5: 51.0% accurate, 3.2× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot \left(\left(0.5 \cdot re\_m\right) \cdot \left(1 + e^{im\_m}\right)\right) \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (* re_s (* (* 0.5 re_m) (+ 1.0 (exp im_m)))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	return re_s * ((0.5 * re_m) * (1.0 + exp(im_m)));
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = re_s * ((0.5d0 * re_m) * (1.0d0 + exp(im_m)))
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	return re_s * ((0.5 * re_m) * (1.0 + Math.exp(im_m)));
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	return re_s * ((0.5 * re_m) * (1.0 + math.exp(im_m)))
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	return Float64(re_s * Float64(Float64(0.5 * re_m) * Float64(1.0 + exp(im_m))))
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp = code(re_s, re_m, im_m)
	tmp = re_s * ((0.5 * re_m) * (1.0 + exp(im_m)));
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(N[(0.5 * re$95$m), $MachinePrecision] * N[(1.0 + N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot \left(\left(0.5 \cdot re\_m\right) \cdot \left(1 + e^{im\_m}\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto \left(\frac{1}{2} \cdot \color{blue}{re}\right) \cdot \left(1 + e^{im}\right) \]
  5. Applied rewrites62.9%

    \[\leadsto \left(0.5 \cdot \color{blue}{re}\right) \cdot \left(1 + e^{im}\right) \]
  6. Add Preprocessing

Alternative 6: 32.9% accurate, 6.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot \begin{array}{l} \mathbf{if}\;re\_m \leq 1.2 \cdot 10^{+40}:\\ \;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\left(im\_m \cdot re\_m\right) \cdot 0.5\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (* re_s (if (<= re_m 1.2e+40) (* (* 0.5 re_m) 2.0) (* (* im_m re_m) 0.5))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	double tmp;
	if (re_m <= 1.2e+40) {
		tmp = (0.5 * re_m) * 2.0;
	} else {
		tmp = (im_m * re_m) * 0.5;
	}
	return re_s * tmp;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (re_m <= 1.2d+40) then
        tmp = (0.5d0 * re_m) * 2.0d0
    else
        tmp = (im_m * re_m) * 0.5d0
    end if
    code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	double tmp;
	if (re_m <= 1.2e+40) {
		tmp = (0.5 * re_m) * 2.0;
	} else {
		tmp = (im_m * re_m) * 0.5;
	}
	return re_s * tmp;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	tmp = 0
	if re_m <= 1.2e+40:
		tmp = (0.5 * re_m) * 2.0
	else:
		tmp = (im_m * re_m) * 0.5
	return re_s * tmp
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	tmp = 0.0
	if (re_m <= 1.2e+40)
		tmp = Float64(Float64(0.5 * re_m) * 2.0);
	else
		tmp = Float64(Float64(im_m * re_m) * 0.5);
	end
	return Float64(re_s * tmp)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp_2 = code(re_s, re_m, im_m)
	tmp = 0.0;
	if (re_m <= 1.2e+40)
		tmp = (0.5 * re_m) * 2.0;
	else
		tmp = (im_m * re_m) * 0.5;
	end
	tmp_2 = re_s * tmp;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * If[LessEqual[re$95$m, 1.2e+40], N[(N[(0.5 * re$95$m), $MachinePrecision] * 2.0), $MachinePrecision], N[(N[(im$95$m * re$95$m), $MachinePrecision] * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;re\_m \leq 1.2 \cdot 10^{+40}:\\
\;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\

\mathbf{else}:\\
\;\;\;\;\left(im\_m \cdot re\_m\right) \cdot 0.5\\


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

    1. Initial program 100.0%

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

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{2} \]
    3. Applied rewrites50.2%

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

      \[\leadsto \left(\frac{1}{2} \cdot \color{blue}{re}\right) \cdot 2 \]
    5. Applied rewrites26.7%

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

    if 1.2e40 < re

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Applied rewrites100.0%

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

      \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \color{blue}{re}\right) \cdot \frac{1}{2} \]
    4. Applied rewrites63.5%

      \[\leadsto \left(\left(\cosh im \cdot 2\right) \cdot \color{blue}{re}\right) \cdot 0.5 \]
    5. Applied rewrites10.3%

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

Alternative 7: 27.4% accurate, 6.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot \begin{array}{l} \mathbf{if}\;re\_m \leq 1.12 \cdot 10^{-18}:\\ \;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot 0.5\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m)
 :precision binary64
 (* re_s (if (<= re_m 1.12e-18) (* (* 0.5 re_m) 2.0) (* 2.0 0.5))))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	double tmp;
	if (re_m <= 1.12e-18) {
		tmp = (0.5 * re_m) * 2.0;
	} else {
		tmp = 2.0 * 0.5;
	}
	return re_s * tmp;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (re_m <= 1.12d-18) then
        tmp = (0.5d0 * re_m) * 2.0d0
    else
        tmp = 2.0d0 * 0.5d0
    end if
    code = re_s * tmp
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	double tmp;
	if (re_m <= 1.12e-18) {
		tmp = (0.5 * re_m) * 2.0;
	} else {
		tmp = 2.0 * 0.5;
	}
	return re_s * tmp;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	tmp = 0
	if re_m <= 1.12e-18:
		tmp = (0.5 * re_m) * 2.0
	else:
		tmp = 2.0 * 0.5
	return re_s * tmp
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	tmp = 0.0
	if (re_m <= 1.12e-18)
		tmp = Float64(Float64(0.5 * re_m) * 2.0);
	else
		tmp = Float64(2.0 * 0.5);
	end
	return Float64(re_s * tmp)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp_2 = code(re_s, re_m, im_m)
	tmp = 0.0;
	if (re_m <= 1.12e-18)
		tmp = (0.5 * re_m) * 2.0;
	else
		tmp = 2.0 * 0.5;
	end
	tmp_2 = re_s * tmp;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * If[LessEqual[re$95$m, 1.12e-18], N[(N[(0.5 * re$95$m), $MachinePrecision] * 2.0), $MachinePrecision], N[(2.0 * 0.5), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot \begin{array}{l}
\mathbf{if}\;re\_m \leq 1.12 \cdot 10^{-18}:\\
\;\;\;\;\left(0.5 \cdot re\_m\right) \cdot 2\\

\mathbf{else}:\\
\;\;\;\;2 \cdot 0.5\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if re < 1.12000000000000001e-18

    1. Initial program 100.0%

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

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{2} \]
    3. Applied rewrites50.2%

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

      \[\leadsto \left(\frac{1}{2} \cdot \color{blue}{re}\right) \cdot 2 \]
    5. Applied rewrites26.7%

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

    if 1.12000000000000001e-18 < re

    1. Initial program 100.0%

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

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

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

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

Alternative 8: 5.3% accurate, 16.2× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot \left(2 \cdot 0.5\right) \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m) :precision binary64 (* re_s (* 2.0 0.5)))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	return re_s * (2.0 * 0.5);
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = re_s * (2.0d0 * 0.5d0)
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	return re_s * (2.0 * 0.5);
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	return re_s * (2.0 * 0.5)
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	return Float64(re_s * Float64(2.0 * 0.5))
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp = code(re_s, re_m, im_m)
	tmp = re_s * (2.0 * 0.5);
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * N[(2.0 * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot \left(2 \cdot 0.5\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

Alternative 9: 4.9% accurate, 64.3× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re\_m = \left|re\right| \\ re\_s = \mathsf{copysign}\left(1, re\right) \\ re\_s \cdot 2 \end{array} \]
im_m = (fabs.f64 im)
re\_m = (fabs.f64 re)
re\_s = (copysign.f64 #s(literal 1 binary64) re)
(FPCore (re_s re_m im_m) :precision binary64 (* re_s 2.0))
im_m = fabs(im);
re\_m = fabs(re);
re\_s = copysign(1.0, re);
double code(double re_s, double re_m, double im_m) {
	return re_s * 2.0;
}
im_m =     private
re\_m =     private
re\_s =     private
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_s, re_m, im_m)
use fmin_fmax_functions
    real(8), intent (in) :: re_s
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = re_s * 2.0d0
end function
im_m = Math.abs(im);
re\_m = Math.abs(re);
re\_s = Math.copySign(1.0, re);
public static double code(double re_s, double re_m, double im_m) {
	return re_s * 2.0;
}
im_m = math.fabs(im)
re\_m = math.fabs(re)
re\_s = math.copysign(1.0, re)
def code(re_s, re_m, im_m):
	return re_s * 2.0
im_m = abs(im)
re\_m = abs(re)
re\_s = copysign(1.0, re)
function code(re_s, re_m, im_m)
	return Float64(re_s * 2.0)
end
im_m = abs(im);
re\_m = abs(re);
re\_s = sign(re) * abs(1.0);
function tmp = code(re_s, re_m, im_m)
	tmp = re_s * 2.0;
end
im_m = N[Abs[im], $MachinePrecision]
re\_m = N[Abs[re], $MachinePrecision]
re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[re$95$s_, re$95$m_, im$95$m_] := N[(re$95$s * 2.0), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
re\_m = \left|re\right|
\\
re\_s = \mathsf{copysign}\left(1, re\right)

\\
re\_s \cdot 2
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

    \[\leadsto 2 \cdot \color{blue}{0.5} \]
  5. Applied rewrites4.9%

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

Reproduce

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