math.sin on complex, real part

Percentage Accurate: 99.9% → 99.9%
Time: 7.7s
Alternatives: 13
Speedup: 1.0×

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));
}
real(8) function code(re, im)
    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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% 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));
}
real(8) function code(re, im)
    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: 99.9% accurate, 1.0× speedup?

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

\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\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. Step-by-step derivation
    1. distribute-rgt-in100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
    2. cancel-sign-sub100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
    3. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
    4. sub-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
    5. neg-sub0100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
    6. remove-double-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
  4. Add Preprocessing
  5. Final simplification100.0%

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

Alternative 2: 84.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ t_1 := \left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{if}\;im \leq 0.1:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;im \leq 7.5 \cdot 10^{+105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)\\ \mathbf{elif}\;im \leq 2.65 \cdot 10^{+147}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 re) (+ (exp (- im)) (exp im))))
        (t_1 (* (* 0.5 (sin re)) (fma im im 2.0))))
   (if (<= im 0.1)
     t_1
     (if (<= im 7.5e+105)
       t_0
       (if (<= im 6.8e+115)
         (*
          (fma im im 2.0)
          (+ (* 0.5 re) (* -0.08333333333333333 (pow re 3.0))))
         (if (<= im 2.65e+147) t_0 t_1))))))
double code(double re, double im) {
	double t_0 = (0.5 * re) * (exp(-im) + exp(im));
	double t_1 = (0.5 * sin(re)) * fma(im, im, 2.0);
	double tmp;
	if (im <= 0.1) {
		tmp = t_1;
	} else if (im <= 7.5e+105) {
		tmp = t_0;
	} else if (im <= 6.8e+115) {
		tmp = fma(im, im, 2.0) * ((0.5 * re) + (-0.08333333333333333 * pow(re, 3.0)));
	} else if (im <= 2.65e+147) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)))
	t_1 = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0))
	tmp = 0.0
	if (im <= 0.1)
		tmp = t_1;
	elseif (im <= 7.5e+105)
		tmp = t_0;
	elseif (im <= 6.8e+115)
		tmp = Float64(fma(im, im, 2.0) * Float64(Float64(0.5 * re) + Float64(-0.08333333333333333 * (re ^ 3.0))));
	elseif (im <= 2.65e+147)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 0.1], t$95$1, If[LessEqual[im, 7.5e+105], t$95$0, If[LessEqual[im, 6.8e+115], N[(N[(im * im + 2.0), $MachinePrecision] * N[(N[(0.5 * re), $MachinePrecision] + N[(-0.08333333333333333 * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.65e+147], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
t_1 := \left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{if}\;im \leq 0.1:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;im \leq 7.5 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)\\

\mathbf{elif}\;im \leq 2.65 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 0.10000000000000001 or 2.6500000000000001e147 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 84.8%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. +-commutative84.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow284.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define84.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    7. Simplified84.8%

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

    if 0.10000000000000001 < im < 7.5000000000000002e105 or 6.8000000000000001e115 < im < 2.6500000000000001e147

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 77.5%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*77.5%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified77.5%

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

    if 7.5000000000000002e105 < im < 6.8000000000000001e115

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 5.7%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. +-commutative5.7%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow25.7%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define5.7%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    7. Simplified5.7%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    8. Taylor expanded in re around 0 1.8%

      \[\leadsto \color{blue}{-0.08333333333333333 \cdot \left({re}^{3} \cdot \left(2 + {im}^{2}\right)\right) + 0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right)} \]
    9. Step-by-step derivation
      1. +-commutative1.8%

        \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(2 + {im}^{2}\right)\right) + -0.08333333333333333 \cdot \left({re}^{3} \cdot \left(2 + {im}^{2}\right)\right)} \]
      2. associate-*r*1.8%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(2 + {im}^{2}\right)} + -0.08333333333333333 \cdot \left({re}^{3} \cdot \left(2 + {im}^{2}\right)\right) \]
      3. *-commutative1.8%

        \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \left(2 + {im}^{2}\right) + -0.08333333333333333 \cdot \left({re}^{3} \cdot \left(2 + {im}^{2}\right)\right) \]
      4. associate-*r*1.8%

        \[\leadsto \left(re \cdot 0.5\right) \cdot \left(2 + {im}^{2}\right) + \color{blue}{\left(-0.08333333333333333 \cdot {re}^{3}\right) \cdot \left(2 + {im}^{2}\right)} \]
      5. distribute-rgt-out68.5%

        \[\leadsto \color{blue}{\left(2 + {im}^{2}\right) \cdot \left(re \cdot 0.5 + -0.08333333333333333 \cdot {re}^{3}\right)} \]
      6. +-commutative68.5%

        \[\leadsto \color{blue}{\left({im}^{2} + 2\right)} \cdot \left(re \cdot 0.5 + -0.08333333333333333 \cdot {re}^{3}\right) \]
      7. unpow268.5%

        \[\leadsto \left(\color{blue}{im \cdot im} + 2\right) \cdot \left(re \cdot 0.5 + -0.08333333333333333 \cdot {re}^{3}\right) \]
      8. fma-undefine68.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \cdot \left(re \cdot 0.5 + -0.08333333333333333 \cdot {re}^{3}\right) \]
      9. *-commutative68.5%

        \[\leadsto \mathsf{fma}\left(im, im, 2\right) \cdot \left(\color{blue}{0.5 \cdot re} + -0.08333333333333333 \cdot {re}^{3}\right) \]
    10. Simplified68.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.1:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{elif}\;im \leq 7.5 \cdot 10^{+105}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)\\ \mathbf{elif}\;im \leq 2.65 \cdot 10^{+147}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;im \leq 7.3 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (* 0.5 (sin re)) (fma im im 2.0))))
   (if (<= im 2.3e+14)
     t_0
     (if (<= im 7.3e+105)
       (pow re -4.0)
       (if (<= im 6.8e+115)
         (- (+ re (* (pow re 3.0) -0.16666666666666666)) 2.0)
         (if (<= im 1.46e+144) (pow re -4.0) t_0))))))
double code(double re, double im) {
	double t_0 = (0.5 * sin(re)) * fma(im, im, 2.0);
	double tmp;
	if (im <= 2.3e+14) {
		tmp = t_0;
	} else if (im <= 7.3e+105) {
		tmp = pow(re, -4.0);
	} else if (im <= 6.8e+115) {
		tmp = (re + (pow(re, 3.0) * -0.16666666666666666)) - 2.0;
	} else if (im <= 1.46e+144) {
		tmp = pow(re, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0))
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = t_0;
	elseif (im <= 7.3e+105)
		tmp = re ^ -4.0;
	elseif (im <= 6.8e+115)
		tmp = Float64(Float64(re + Float64((re ^ 3.0) * -0.16666666666666666)) - 2.0);
	elseif (im <= 1.46e+144)
		tmp = re ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 2.3e+14], t$95$0, If[LessEqual[im, 7.3e+105], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 6.8e+115], N[(N[(re + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[im, 1.46e+144], N[Power[re, -4.0], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;im \leq 7.3 \cdot 10^{+105}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\
\;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\

\mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 2.3e14 or 1.46e144 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 83.3%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. +-commutative83.3%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow283.3%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define83.3%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    7. Simplified83.3%

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

    if 2.3e14 < im < 7.30000000000000024e105 or 6.8000000000000001e115 < im < 1.46e144

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 80.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*80.8%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified80.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr27.6%

      \[\leadsto \color{blue}{{re}^{-4}} \]

    if 7.30000000000000024e105 < im < 6.8000000000000001e115

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 5.7%

      \[\leadsto \color{blue}{\sin re + 0.5 \cdot \left({im}^{2} \cdot \sin re\right)} \]
    6. Applied egg-rr2.3%

      \[\leadsto \sin re + 0.5 \cdot \color{blue}{-4} \]
    7. Taylor expanded in re around 0 67.7%

      \[\leadsto \color{blue}{\left(re + -0.16666666666666666 \cdot {re}^{3}\right) - 2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{elif}\;im \leq 7.3 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 65.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.3e+14)
   (sin re)
   (if (<= im 5e+105)
     (pow re -4.0)
     (if (<= im 6.8e+115)
       (- (+ re (* (pow re 3.0) -0.16666666666666666)) 2.0)
       (if (<= im 1.46e+144)
         (pow re -4.0)
         (* (* 0.5 (sin re)) (pow im 2.0)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = sin(re);
	} else if (im <= 5e+105) {
		tmp = pow(re, -4.0);
	} else if (im <= 6.8e+115) {
		tmp = (re + (pow(re, 3.0) * -0.16666666666666666)) - 2.0;
	} else if (im <= 1.46e+144) {
		tmp = pow(re, -4.0);
	} else {
		tmp = (0.5 * sin(re)) * pow(im, 2.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 2.3d+14) then
        tmp = sin(re)
    else if (im <= 5d+105) then
        tmp = re ** (-4.0d0)
    else if (im <= 6.8d+115) then
        tmp = (re + ((re ** 3.0d0) * (-0.16666666666666666d0))) - 2.0d0
    else if (im <= 1.46d+144) then
        tmp = re ** (-4.0d0)
    else
        tmp = (0.5d0 * sin(re)) * (im ** 2.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = Math.sin(re);
	} else if (im <= 5e+105) {
		tmp = Math.pow(re, -4.0);
	} else if (im <= 6.8e+115) {
		tmp = (re + (Math.pow(re, 3.0) * -0.16666666666666666)) - 2.0;
	} else if (im <= 1.46e+144) {
		tmp = Math.pow(re, -4.0);
	} else {
		tmp = (0.5 * Math.sin(re)) * Math.pow(im, 2.0);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 2.3e+14:
		tmp = math.sin(re)
	elif im <= 5e+105:
		tmp = math.pow(re, -4.0)
	elif im <= 6.8e+115:
		tmp = (re + (math.pow(re, 3.0) * -0.16666666666666666)) - 2.0
	elif im <= 1.46e+144:
		tmp = math.pow(re, -4.0)
	else:
		tmp = (0.5 * math.sin(re)) * math.pow(im, 2.0)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 5e+105)
		tmp = re ^ -4.0;
	elseif (im <= 6.8e+115)
		tmp = Float64(Float64(re + Float64((re ^ 3.0) * -0.16666666666666666)) - 2.0);
	elseif (im <= 1.46e+144)
		tmp = re ^ -4.0;
	else
		tmp = Float64(Float64(0.5 * sin(re)) * (im ^ 2.0));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 5e+105)
		tmp = re ^ -4.0;
	elseif (im <= 6.8e+115)
		tmp = (re + ((re ^ 3.0) * -0.16666666666666666)) - 2.0;
	elseif (im <= 1.46e+144)
		tmp = re ^ -4.0;
	else
		tmp = (0.5 * sin(re)) * (im ^ 2.0);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 2.3e+14], N[Sin[re], $MachinePrecision], If[LessEqual[im, 5e+105], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 6.8e+115], N[(N[(re + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[im, 1.46e+144], N[Power[re, -4.0], $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 5 \cdot 10^{+105}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\
\;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\

\mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < 2.3e14

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 63.0%

      \[\leadsto \color{blue}{\sin re} \]

    if 2.3e14 < im < 5.00000000000000046e105 or 6.8000000000000001e115 < im < 1.46e144

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 80.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*80.8%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified80.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr27.6%

      \[\leadsto \color{blue}{{re}^{-4}} \]

    if 5.00000000000000046e105 < im < 6.8000000000000001e115

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 5.7%

      \[\leadsto \color{blue}{\sin re + 0.5 \cdot \left({im}^{2} \cdot \sin re\right)} \]
    6. Applied egg-rr2.3%

      \[\leadsto \sin re + 0.5 \cdot \color{blue}{-4} \]
    7. Taylor expanded in re around 0 67.7%

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

    if 1.46e144 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 95.0%

      \[\leadsto \color{blue}{\sin re + 0.5 \cdot \left({im}^{2} \cdot \sin re\right)} \]
    6. Taylor expanded in im around inf 95.0%

      \[\leadsto \color{blue}{0.5 \cdot \left({im}^{2} \cdot \sin re\right)} \]
    7. Step-by-step derivation
      1. associate-*r*95.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot \sin re} \]
      2. *-commutative95.0%

        \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot \sin re \]
      3. associate-*l*95.0%

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 \cdot \sin re\right)} \]
    8. Simplified95.0%

      \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 \cdot \sin re\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification64.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 5 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 1.46 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 0.105 \lor \neg \left(im \leq 2.65 \cdot 10^{+147}\right):\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im 0.105) (not (<= im 2.65e+147)))
   (* (* 0.5 (sin re)) (fma im im 2.0))
   (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
	double tmp;
	if ((im <= 0.105) || !(im <= 2.65e+147)) {
		tmp = (0.5 * sin(re)) * fma(im, im, 2.0);
	} else {
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if ((im <= 0.105) || !(im <= 2.65e+147))
		tmp = Float64(Float64(0.5 * sin(re)) * fma(im, im, 2.0));
	else
		tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)));
	end
	return tmp
end
code[re_, im_] := If[Or[LessEqual[im, 0.105], N[Not[LessEqual[im, 2.65e+147]], $MachinePrecision]], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.105 \lor \neg \left(im \leq 2.65 \cdot 10^{+147}\right):\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 0.104999999999999996 or 2.6500000000000001e147 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 84.8%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    6. Step-by-step derivation
      1. +-commutative84.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow284.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define84.8%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    7. Simplified84.8%

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

    if 0.104999999999999996 < im < 2.6500000000000001e147

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 73.6%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*73.6%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified73.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.105 \lor \neg \left(im \leq 2.65 \cdot 10^{+147}\right):\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 62.5% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 2.65 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.3e+14)
   (sin re)
   (if (<= im 1.05e+105)
     (pow re -4.0)
     (if (<= im 6.8e+115)
       (- (+ re (* (pow re 3.0) -0.16666666666666666)) 2.0)
       (if (<= im 2.65e+144) (pow re -4.0) (* (fma im im 2.0) (* 0.5 re)))))))
double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = sin(re);
	} else if (im <= 1.05e+105) {
		tmp = pow(re, -4.0);
	} else if (im <= 6.8e+115) {
		tmp = (re + (pow(re, 3.0) * -0.16666666666666666)) - 2.0;
	} else if (im <= 2.65e+144) {
		tmp = pow(re, -4.0);
	} else {
		tmp = fma(im, im, 2.0) * (0.5 * re);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 1.05e+105)
		tmp = re ^ -4.0;
	elseif (im <= 6.8e+115)
		tmp = Float64(Float64(re + Float64((re ^ 3.0) * -0.16666666666666666)) - 2.0);
	elseif (im <= 2.65e+144)
		tmp = re ^ -4.0;
	else
		tmp = Float64(fma(im, im, 2.0) * Float64(0.5 * re));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 2.3e+14], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.05e+105], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 6.8e+115], N[(N[(re + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision], If[LessEqual[im, 2.65e+144], N[Power[re, -4.0], $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 1.05 \cdot 10^{+105}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\
\;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\

\mathbf{elif}\;im \leq 2.65 \cdot 10^{+144}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < 2.3e14

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 63.0%

      \[\leadsto \color{blue}{\sin re} \]

    if 2.3e14 < im < 1.05000000000000005e105 or 6.8000000000000001e115 < im < 2.6499999999999998e144

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 77.8%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*77.8%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified77.8%

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr26.6%

      \[\leadsto \color{blue}{{re}^{-4}} \]

    if 1.05000000000000005e105 < im < 6.8000000000000001e115

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 5.7%

      \[\leadsto \color{blue}{\sin re + 0.5 \cdot \left({im}^{2} \cdot \sin re\right)} \]
    6. Applied egg-rr2.3%

      \[\leadsto \sin re + 0.5 \cdot \color{blue}{-4} \]
    7. Taylor expanded in re around 0 67.7%

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

    if 2.6499999999999998e144 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 75.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*75.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified75.0%

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

      \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. +-commutative72.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow272.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define72.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    10. Simplified72.4%

      \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification60.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{+105}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+115}:\\ \;\;\;\;\left(re + {re}^{3} \cdot -0.16666666666666666\right) - 2\\ \mathbf{elif}\;im \leq 2.65 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 62.6% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.3e+14)
   (sin re)
   (if (<= im 1.8e+144) (pow re -4.0) (* (fma im im 2.0) (* 0.5 re)))))
double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = sin(re);
	} else if (im <= 1.8e+144) {
		tmp = pow(re, -4.0);
	} else {
		tmp = fma(im, im, 2.0) * (0.5 * re);
	}
	return tmp;
}
function code(re, im)
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 1.8e+144)
		tmp = re ^ -4.0;
	else
		tmp = Float64(fma(im, im, 2.0) * Float64(0.5 * re));
	end
	return tmp
end
code[re_, im_] := If[LessEqual[im, 2.3e+14], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.8e+144], N[Power[re, -4.0], $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 1.8 \cdot 10^{+144}:\\
\;\;\;\;{re}^{-4}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 2.3e14

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 63.0%

      \[\leadsto \color{blue}{\sin re} \]

    if 2.3e14 < im < 1.7999999999999999e144

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 73.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*73.3%

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

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr24.1%

      \[\leadsto \color{blue}{{re}^{-4}} \]

    if 1.7999999999999999e144 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 75.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*75.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified75.0%

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

      \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
    9. Step-by-step derivation
      1. +-commutative72.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\left({im}^{2} + 2\right)} \]
      2. unpow272.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. fma-define72.4%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
    10. Simplified72.4%

      \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im, 2\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.8 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 62.6% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot {im}^{2}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.3e+14)
   (sin re)
   (if (<= im 2.4e+144) (pow re -4.0) (* (* 0.5 re) (pow im 2.0)))))
double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = sin(re);
	} else if (im <= 2.4e+144) {
		tmp = pow(re, -4.0);
	} else {
		tmp = (0.5 * re) * pow(im, 2.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 2.3d+14) then
        tmp = sin(re)
    else if (im <= 2.4d+144) then
        tmp = re ** (-4.0d0)
    else
        tmp = (0.5d0 * re) * (im ** 2.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = Math.sin(re);
	} else if (im <= 2.4e+144) {
		tmp = Math.pow(re, -4.0);
	} else {
		tmp = (0.5 * re) * Math.pow(im, 2.0);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 2.3e+14:
		tmp = math.sin(re)
	elif im <= 2.4e+144:
		tmp = math.pow(re, -4.0)
	else:
		tmp = (0.5 * re) * math.pow(im, 2.0)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 2.4e+144)
		tmp = re ^ -4.0;
	else
		tmp = Float64(Float64(0.5 * re) * (im ^ 2.0));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 2.3e+14)
		tmp = sin(re);
	elseif (im <= 2.4e+144)
		tmp = re ^ -4.0;
	else
		tmp = (0.5 * re) * (im ^ 2.0);
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 2.3e+14], N[Sin[re], $MachinePrecision], If[LessEqual[im, 2.4e+144], N[Power[re, -4.0], $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\

\mathbf{elif}\;im \leq 2.4 \cdot 10^{+144}:\\
\;\;\;\;{re}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if im < 2.3e14

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 63.0%

      \[\leadsto \color{blue}{\sin re} \]

    if 2.3e14 < im < 2.4000000000000001e144

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 73.3%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*73.3%

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

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr24.1%

      \[\leadsto \color{blue}{{re}^{-4}} \]

    if 2.4000000000000001e144 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 75.0%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*75.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified75.0%

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

      \[\leadsto \color{blue}{re + 0.5 \cdot \left({im}^{2} \cdot re\right)} \]
    9. Taylor expanded in im around inf 72.4%

      \[\leadsto \color{blue}{0.5 \cdot \left({im}^{2} \cdot re\right)} \]
    10. Step-by-step derivation
      1. associate-*r*72.4%

        \[\leadsto \color{blue}{\left(0.5 \cdot {im}^{2}\right) \cdot re} \]
      2. *-commutative72.4%

        \[\leadsto \color{blue}{\left({im}^{2} \cdot 0.5\right)} \cdot re \]
      3. associate-*r*72.4%

        \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 \cdot re\right)} \]
    11. Simplified72.4%

      \[\leadsto \color{blue}{{im}^{2} \cdot \left(0.5 \cdot re\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+144}:\\ \;\;\;\;{re}^{-4}\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot {im}^{2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 55.8% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{re}^{-4}\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 2.3e+14) (sin re) (pow re -4.0)))
double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = sin(re);
	} else {
		tmp = pow(re, -4.0);
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 2.3d+14) then
        tmp = sin(re)
    else
        tmp = re ** (-4.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 2.3e+14) {
		tmp = Math.sin(re);
	} else {
		tmp = Math.pow(re, -4.0);
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 2.3e+14:
		tmp = math.sin(re)
	else:
		tmp = math.pow(re, -4.0)
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 2.3e+14)
		tmp = sin(re);
	else
		tmp = re ^ -4.0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 2.3e+14)
		tmp = sin(re);
	else
		tmp = re ^ -4.0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 2.3e+14], N[Sin[re], $MachinePrecision], N[Power[re, -4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\

\mathbf{else}:\\
\;\;\;\;{re}^{-4}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 2.3e14

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 63.0%

      \[\leadsto \color{blue}{\sin re} \]

    if 2.3e14 < im

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 74.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*74.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified74.2%

      \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    8. Applied egg-rr22.1%

      \[\leadsto \color{blue}{{re}^{-4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 2.3 \cdot 10^{+14}:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{re}^{-4}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 51.7% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \sin re \end{array} \]
(FPCore (re im) :precision binary64 (sin re))
double code(double re, double im) {
	return sin(re);
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = sin(re)
end function
public static double code(double re, double im) {
	return Math.sin(re);
}
def code(re, im):
	return math.sin(re)
function code(re, im)
	return sin(re)
end
function tmp = code(re, im)
	tmp = sin(re);
end
code[re_, im_] := N[Sin[re], $MachinePrecision]
\begin{array}{l}

\\
\sin re
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Step-by-step derivation
    1. distribute-rgt-in100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
    2. cancel-sign-sub100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
    3. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
    4. sub-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
    5. neg-sub0100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
    6. remove-double-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in im around 0 47.4%

    \[\leadsto \color{blue}{\sin re} \]
  6. Final simplification47.4%

    \[\leadsto \sin re \]
  7. Add Preprocessing

Alternative 11: 28.1% accurate, 51.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;re \leq 420000000:\\ \;\;\;\;re\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (re im) :precision binary64 (if (<= re 420000000.0) re 1.0))
double code(double re, double im) {
	double tmp;
	if (re <= 420000000.0) {
		tmp = re;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (re <= 420000000.0d0) then
        tmp = re
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (re <= 420000000.0) {
		tmp = re;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if re <= 420000000.0:
		tmp = re
	else:
		tmp = 1.0
	return tmp
function code(re, im)
	tmp = 0.0
	if (re <= 420000000.0)
		tmp = re;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (re <= 420000000.0)
		tmp = re;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[re, 420000000.0], re, 1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;re \leq 420000000:\\
\;\;\;\;re\\

\mathbf{else}:\\
\;\;\;\;1\\


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in re around 0 71.2%

      \[\leadsto \color{blue}{0.5 \cdot \left(re \cdot \left(e^{im} + e^{-im}\right)\right)} \]
    6. Step-by-step derivation
      1. associate-*r*71.2%

        \[\leadsto \color{blue}{\left(0.5 \cdot re\right) \cdot \left(e^{im} + e^{-im}\right)} \]
    7. Simplified71.2%

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

      \[\leadsto \color{blue}{re} \]

    if 4.2e8 < re

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Step-by-step derivation
      1. distribute-rgt-in100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
      2. cancel-sign-sub100.0%

        \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
      3. distribute-rgt-out--100.0%

        \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
      4. sub-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
      5. neg-sub0100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
      6. remove-double-neg100.0%

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr5.6%

      \[\leadsto \color{blue}{\frac{\sin re \cdot -2}{\sin re \cdot -2 + \left(\sin re \cdot -2 - \sin re \cdot -2\right)}} \]
    6. Step-by-step derivation
      1. +-inverses5.6%

        \[\leadsto \frac{\sin re \cdot -2}{\sin re \cdot -2 + \color{blue}{0}} \]
      2. +-rgt-identity5.6%

        \[\leadsto \frac{\sin re \cdot -2}{\color{blue}{\sin re \cdot -2}} \]
      3. *-inverses5.6%

        \[\leadsto \color{blue}{1} \]
    7. Simplified5.6%

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification22.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq 420000000:\\ \;\;\;\;re\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 4.3% accurate, 309.0× speedup?

\[\begin{array}{l} \\ -2 \end{array} \]
(FPCore (re im) :precision binary64 -2.0)
double code(double re, double im) {
	return -2.0;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = -2.0d0
end function
public static double code(double re, double im) {
	return -2.0;
}
def code(re, im):
	return -2.0
function code(re, im)
	return -2.0
end
function tmp = code(re, im)
	tmp = -2.0;
end
code[re_, im_] := -2.0
\begin{array}{l}

\\
-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. Step-by-step derivation
    1. distribute-rgt-in100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
    2. cancel-sign-sub100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
    3. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
    4. sub-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
    5. neg-sub0100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
    6. remove-double-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in im around 0 74.3%

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

    \[\leadsto \sin re + 0.5 \cdot \color{blue}{-4} \]
  7. Taylor expanded in re around 0 4.7%

    \[\leadsto \color{blue}{-2} \]
  8. Final simplification4.7%

    \[\leadsto -2 \]
  9. Add Preprocessing

Alternative 13: 4.7% accurate, 309.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
	return 1.0;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 1.0d0
end function
public static double code(double re, double im) {
	return 1.0;
}
def code(re, im):
	return 1.0
function code(re, im)
	return 1.0
end
function tmp = code(re, im)
	tmp = 1.0;
end
code[re_, im_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Step-by-step derivation
    1. distribute-rgt-in100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) + e^{im} \cdot \left(0.5 \cdot \sin re\right)} \]
    2. cancel-sign-sub100.0%

      \[\leadsto \color{blue}{e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) - \left(-e^{im}\right) \cdot \left(0.5 \cdot \sin re\right)} \]
    3. distribute-rgt-out--100.0%

      \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} - \left(-e^{im}\right)\right)} \]
    4. sub-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\left(e^{0 - im} + \left(-\left(-e^{im}\right)\right)\right)} \]
    5. neg-sub0100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + \left(-\left(-e^{im}\right)\right)\right) \]
    6. remove-double-neg100.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + \color{blue}{e^{im}}\right) \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
  4. Add Preprocessing
  5. Applied egg-rr4.6%

    \[\leadsto \color{blue}{\frac{\sin re \cdot -2}{\sin re \cdot -2 + \left(\sin re \cdot -2 - \sin re \cdot -2\right)}} \]
  6. Step-by-step derivation
    1. +-inverses4.6%

      \[\leadsto \frac{\sin re \cdot -2}{\sin re \cdot -2 + \color{blue}{0}} \]
    2. +-rgt-identity4.6%

      \[\leadsto \frac{\sin re \cdot -2}{\color{blue}{\sin re \cdot -2}} \]
    3. *-inverses4.6%

      \[\leadsto \color{blue}{1} \]
  7. Simplified4.6%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification4.6%

    \[\leadsto 1 \]
  9. Add Preprocessing

Reproduce

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