math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 7.4s
Alternatives: 10
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 10 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));
}
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: 100.0% accurate, 0.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \sin re \cdot \mathsf{fma}\left(0.5, e^{im\_m}, \frac{0.5}{e^{im\_m}}\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (* (sin re) (fma 0.5 (exp im_m) (/ 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	return sin(re) * fma(0.5, exp(im_m), (0.5 / exp(im_m)));
}
im_m = abs(im)
function code(re, im_m)
	return Float64(sin(re) * fma(0.5, exp(im_m), Float64(0.5 / exp(im_m))))
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision] + N[(0.5 / N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\sin re \cdot \mathsf{fma}\left(0.5, e^{im\_m}, \frac{0.5}{e^{im\_m}}\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. +-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
    4. associate-*r*100.0%

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

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

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

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

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

      \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
    10. exp-diff100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    11. associate-*l/100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    12. exp-0100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    13. metadata-eval100.0%

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

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

    \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right) \]
  6. Add Preprocessing

Alternative 2: 100.0% accurate, 1.0× speedup?

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

\\
\left(\sin re \cdot 0.5\right) \cdot \left(e^{im\_m} + e^{-im\_m}\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. remove-double-neg100.0%

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

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + 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(\sin re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right) \]
  6. Add Preprocessing

Alternative 3: 99.7% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 1.35:\\ \;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot e^{im\_m}\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 1.35)
   (* (* (sin re) 0.5) (fma im_m im_m 2.0))
   (* 0.5 (* (sin re) (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1.35) {
		tmp = (sin(re) * 0.5) * fma(im_m, im_m, 2.0);
	} else {
		tmp = 0.5 * (sin(re) * exp(im_m));
	}
	return tmp;
}
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 1.35)
		tmp = Float64(Float64(sin(re) * 0.5) * fma(im_m, im_m, 2.0));
	else
		tmp = Float64(0.5 * Float64(sin(re) * exp(im_m)));
	end
	return tmp
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 1.35], N[(N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 1.35:\\
\;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\

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


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

    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. remove-double-neg100.0%

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

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + 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.9%

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

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

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

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

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

    if 1.3500000000000001 < 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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr99.3%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{0}\right) \]
    6. Taylor expanded in re around inf 99.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.35:\\ \;\;\;\;\left(\sin re \cdot 0.5\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot e^{im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.4% accurate, 1.5× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 0.68:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot e^{im\_m}\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 0.68) (sin re) (* 0.5 (* (sin re) (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 0.68) {
		tmp = sin(re);
	} else {
		tmp = 0.5 * (sin(re) * exp(im_m));
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 0.68d0) then
        tmp = sin(re)
    else
        tmp = 0.5d0 * (sin(re) * exp(im_m))
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 0.68) {
		tmp = Math.sin(re);
	} else {
		tmp = 0.5 * (Math.sin(re) * Math.exp(im_m));
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 0.68:
		tmp = math.sin(re)
	else:
		tmp = 0.5 * (math.sin(re) * math.exp(im_m))
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 0.68)
		tmp = sin(re);
	else
		tmp = Float64(0.5 * Float64(sin(re) * exp(im_m)));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 0.68)
		tmp = sin(re);
	else
		tmp = 0.5 * (sin(re) * exp(im_m));
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 0.68], N[Sin[re], $MachinePrecision], N[(0.5 * N[(N[Sin[re], $MachinePrecision] * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 0.68:\\
\;\;\;\;\sin re\\

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


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

    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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 68.6%

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

    if 0.680000000000000049 < 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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr99.3%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{0}\right) \]
    6. Taylor expanded in re around inf 99.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.68:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\sin re \cdot e^{im}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 86.9% accurate, 2.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 215:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;e^{im\_m} \cdot \left(re \cdot 0.5\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 215.0) (sin re) (* (exp im_m) (* re 0.5))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 215.0) {
		tmp = sin(re);
	} else {
		tmp = exp(im_m) * (re * 0.5);
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 215.0d0) then
        tmp = sin(re)
    else
        tmp = exp(im_m) * (re * 0.5d0)
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 215.0) {
		tmp = Math.sin(re);
	} else {
		tmp = Math.exp(im_m) * (re * 0.5);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 215.0:
		tmp = math.sin(re)
	else:
		tmp = math.exp(im_m) * (re * 0.5)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 215.0)
		tmp = sin(re);
	else
		tmp = Float64(exp(im_m) * Float64(re * 0.5));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 215.0)
		tmp = sin(re);
	else
		tmp = exp(im_m) * (re * 0.5);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 215.0], N[Sin[re], $MachinePrecision], N[(N[Exp[im$95$m], $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 215:\\
\;\;\;\;\sin re\\

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


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

    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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 68.0%

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

    if 215 < 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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{0}\right) \]
    6. Taylor expanded in re around 0 74.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 215:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;e^{im} \cdot \left(re \cdot 0.5\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 58.6% accurate, 2.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 1300:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot {re}^{3}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 1300.0) (sin re) (* -0.16666666666666666 (pow re 3.0))))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1300.0) {
		tmp = sin(re);
	} else {
		tmp = -0.16666666666666666 * pow(re, 3.0);
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 1300.0d0) then
        tmp = sin(re)
    else
        tmp = (-0.16666666666666666d0) * (re ** 3.0d0)
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 1300.0) {
		tmp = Math.sin(re);
	} else {
		tmp = -0.16666666666666666 * Math.pow(re, 3.0);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 1300.0:
		tmp = math.sin(re)
	else:
		tmp = -0.16666666666666666 * math.pow(re, 3.0)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 1300.0)
		tmp = sin(re);
	else
		tmp = Float64(-0.16666666666666666 * (re ^ 3.0));
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 1300.0)
		tmp = sin(re);
	else
		tmp = -0.16666666666666666 * (re ^ 3.0);
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 1300.0], N[Sin[re], $MachinePrecision], N[(-0.16666666666666666 * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 1300:\\
\;\;\;\;\sin re\\

\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot {re}^{3}\\


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

    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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 67.6%

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

    if 1300 < 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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 2.7%

      \[\leadsto \color{blue}{\sin re} \]
    6. Taylor expanded in re around 0 16.6%

      \[\leadsto \color{blue}{re \cdot \left(1 + -0.16666666666666666 \cdot {re}^{2}\right)} \]
    7. Taylor expanded in re around inf 16.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1300:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;-0.16666666666666666 \cdot {re}^{3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 56.6% accurate, 2.8× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} \mathbf{if}\;im\_m \leq 820:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{\left(re \cdot -2\right)}^{-2}\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (if (<= im_m 820.0) (sin re) (pow (* re -2.0) -2.0)))
im_m = fabs(im);
double code(double re, double im_m) {
	double tmp;
	if (im_m <= 820.0) {
		tmp = sin(re);
	} else {
		tmp = pow((re * -2.0), -2.0);
	}
	return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    real(8) :: tmp
    if (im_m <= 820.0d0) then
        tmp = sin(re)
    else
        tmp = (re * (-2.0d0)) ** (-2.0d0)
    end if
    code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	double tmp;
	if (im_m <= 820.0) {
		tmp = Math.sin(re);
	} else {
		tmp = Math.pow((re * -2.0), -2.0);
	}
	return tmp;
}
im_m = math.fabs(im)
def code(re, im_m):
	tmp = 0
	if im_m <= 820.0:
		tmp = math.sin(re)
	else:
		tmp = math.pow((re * -2.0), -2.0)
	return tmp
im_m = abs(im)
function code(re, im_m)
	tmp = 0.0
	if (im_m <= 820.0)
		tmp = sin(re);
	else
		tmp = Float64(re * -2.0) ^ -2.0;
	end
	return tmp
end
im_m = abs(im);
function tmp_2 = code(re, im_m)
	tmp = 0.0;
	if (im_m <= 820.0)
		tmp = sin(re);
	else
		tmp = (re * -2.0) ^ -2.0;
	end
	tmp_2 = tmp;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := If[LessEqual[im$95$m, 820.0], N[Sin[re], $MachinePrecision], N[Power[N[(re * -2.0), $MachinePrecision], -2.0], $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|

\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 820:\\
\;\;\;\;\sin re\\

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


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

    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. +-commutative100.0%

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

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

        \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
      4. associate-*r*100.0%

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

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

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

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

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

        \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
      10. exp-diff100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
      11. associate-*l/100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
      12. exp-0100.0%

        \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
      13. metadata-eval100.0%

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

      \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in im around 0 68.0%

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

    if 820 < 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. remove-double-neg100.0%

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

        \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + 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 \left(0.5 \cdot \color{blue}{re}\right) \cdot \left(e^{-im} + e^{im}\right) \]
    6. Applied egg-rr11.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 820:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;{\left(re \cdot -2\right)}^{-2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 51.1% accurate, 3.1× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \sin re \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 (sin re))
im_m = fabs(im);
double code(double re, double im_m) {
	return sin(re);
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = sin(re)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return Math.sin(re);
}
im_m = math.fabs(im)
def code(re, im_m):
	return math.sin(re)
im_m = abs(im)
function code(re, im_m)
	return sin(re)
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = sin(re);
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[Sin[re], $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

\\
\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. +-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
    4. associate-*r*100.0%

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

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

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

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

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

      \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
    10. exp-diff100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    11. associate-*l/100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    12. exp-0100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    13. metadata-eval100.0%

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

    \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in im around 0 52.2%

    \[\leadsto \color{blue}{\sin re} \]
  6. Final simplification52.2%

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

Alternative 9: 4.3% accurate, 309.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ 2 \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 2.0)
im_m = fabs(im);
double code(double re, double im_m) {
	return 2.0;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = 2.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return 2.0;
}
im_m = math.fabs(im)
def code(re, im_m):
	return 2.0
im_m = abs(im)
function code(re, im_m)
	return 2.0
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = 2.0;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := 2.0
\begin{array}{l}
im_m = \left|im\right|

\\
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. +-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
    4. associate-*r*100.0%

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

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

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

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

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

      \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
    10. exp-diff100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    11. associate-*l/100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    12. exp-0100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    13. metadata-eval100.0%

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

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

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-0.5 \cdot \sin re\right)} - -1} \]
  6. Step-by-step derivation
    1. sub-neg4.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(-0.5 \cdot \sin re\right)} + \left(--1\right)} \]
    2. metadata-eval4.4%

      \[\leadsto e^{\mathsf{log1p}\left(-0.5 \cdot \sin re\right)} + \color{blue}{1} \]
    3. +-commutative4.4%

      \[\leadsto \color{blue}{1 + e^{\mathsf{log1p}\left(-0.5 \cdot \sin re\right)}} \]
    4. log1p-undefine4.4%

      \[\leadsto 1 + e^{\color{blue}{\log \left(1 + -0.5 \cdot \sin re\right)}} \]
    5. rem-exp-log4.4%

      \[\leadsto 1 + \color{blue}{\left(1 + -0.5 \cdot \sin re\right)} \]
    6. associate-+r+4.4%

      \[\leadsto \color{blue}{\left(1 + 1\right) + -0.5 \cdot \sin re} \]
    7. metadata-eval4.4%

      \[\leadsto \color{blue}{2} + -0.5 \cdot \sin re \]
  7. Simplified4.4%

    \[\leadsto \color{blue}{2 + -0.5 \cdot \sin re} \]
  8. Taylor expanded in re around 0 4.3%

    \[\leadsto \color{blue}{2} \]
  9. Final simplification4.3%

    \[\leadsto 2 \]
  10. Add Preprocessing

Alternative 10: 26.5% accurate, 309.0× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ re \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m) :precision binary64 re)
im_m = fabs(im);
double code(double re, double im_m) {
	return re;
}
im_m = abs(im)
real(8) function code(re, im_m)
    real(8), intent (in) :: re
    real(8), intent (in) :: im_m
    code = re
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
	return re;
}
im_m = math.fabs(im)
def code(re, im_m):
	return re
im_m = abs(im)
function code(re, im_m)
	return re
end
im_m = abs(im);
function tmp = code(re, im_m)
	tmp = re;
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := re
\begin{array}{l}
im_m = \left|im\right|

\\
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. +-commutative100.0%

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

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

      \[\leadsto \color{blue}{\left(e^{im} \cdot 0.5\right) \cdot \sin re} + e^{0 - im} \cdot \left(0.5 \cdot \sin re\right) \]
    4. associate-*r*100.0%

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

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

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

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

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

      \[\leadsto \sin re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, e^{0 - im} \cdot 0.5\right)} \]
    10. exp-diff100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0}}{e^{im}}} \cdot 0.5\right) \]
    11. associate-*l/100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{e^{0} \cdot 0.5}{e^{im}}}\right) \]
    12. exp-0100.0%

      \[\leadsto \sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{1} \cdot 0.5}{e^{im}}\right) \]
    13. metadata-eval100.0%

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

    \[\leadsto \color{blue}{\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in im around 0 52.2%

    \[\leadsto \color{blue}{\sin re} \]
  6. Taylor expanded in re around 0 30.4%

    \[\leadsto \color{blue}{re} \]
  7. Final simplification30.4%

    \[\leadsto re \]
  8. Add Preprocessing

Reproduce

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