math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 28.8s
Alternatives: 25
Speedup: 1.5×

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 25 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.7× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\sin re \cdot e^{-im}, 0.5, \sin re \cdot \left(0.5 \cdot e^{im}\right)\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (fma (* (sin re) (exp (- im))) 0.5 (* (sin re) (* 0.5 (exp im)))))
double code(double re, double im) {
	return fma((sin(re) * exp(-im)), 0.5, (sin(re) * (0.5 * exp(im))));
}
function code(re, im)
	return fma(Float64(sin(re) * exp(Float64(-im))), 0.5, Float64(sin(re) * Float64(0.5 * exp(im))))
end
code[re_, im_] := N[(N[(N[Sin[re], $MachinePrecision] * N[Exp[(-im)], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\sin re \cdot e^{-im}, 0.5, \sin re \cdot \left(0.5 \cdot e^{im}\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sin.f64N/A

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

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

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{\color{blue}{0 - im}} + e^{im}\right) \]
    4. lift-exp.f64N/A

      \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(\color{blue}{e^{0 - im}} + e^{im}\right) \]
    5. lift-exp.f64N/A

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

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

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

      \[\leadsto e^{0 - im} \cdot \color{blue}{\left(\sin re \cdot \frac{1}{2}\right)} + e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right) \]
    9. associate-*r*N/A

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(e^{0 - im} \cdot \sin re, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right)} \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\sin re \cdot e^{0 - im}}, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right) \]
    12. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{\sin re \cdot e^{0 - im}}, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right) \]
    13. lift--.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\color{blue}{0 - im}}, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right) \]
    14. sub0-negN/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\color{blue}{\mathsf{neg}\left(im\right)}}, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right) \]
    15. lower-neg.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\color{blue}{\mathsf{neg}\left(im\right)}}, \frac{1}{2}, e^{im} \cdot \left(\frac{1}{2} \cdot \sin re\right)\right) \]
    16. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\mathsf{neg}\left(im\right)}, \frac{1}{2}, \color{blue}{\left(\frac{1}{2} \cdot \sin re\right) \cdot e^{im}}\right) \]
    17. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\mathsf{neg}\left(im\right)}, \frac{1}{2}, \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \cdot e^{im}\right) \]
    18. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\mathsf{neg}\left(im\right)}, \frac{1}{2}, \color{blue}{\left(\sin re \cdot \frac{1}{2}\right)} \cdot e^{im}\right) \]
    19. associate-*l*N/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\mathsf{neg}\left(im\right)}, \frac{1}{2}, \color{blue}{\sin re \cdot \left(\frac{1}{2} \cdot e^{im}\right)}\right) \]
    20. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(\sin re \cdot e^{\mathsf{neg}\left(im\right)}, \frac{1}{2}, \color{blue}{\sin re \cdot \left(\frac{1}{2} \cdot e^{im}\right)}\right) \]
    21. lower-*.f64100.0

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

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

Alternative 2: 87.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin re \cdot 0.5\\ t_1 := t\_0 \cdot \left(e^{-im} + e^{im}\right)\\ \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+132}:\\ \;\;\;\;\frac{t\_0}{\frac{1}{\mathsf{fma}\left(im, \mathsf{fma}\left(im \cdot im, im \cdot \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), im\right), 2\right)}}\\ \mathbf{else}:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \left(re \cdot re\right), re\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* (sin re) 0.5)) (t_1 (* t_0 (+ (exp (- im)) (exp im)))))
   (if (<= t_1 (- INFINITY))
     (* (cosh im) (fma re (* (* re re) -0.16666666666666666) re))
     (if (<= t_1 5e+132)
       (/
        t_0
        (/
         1.0
         (fma
          im
          (fma
           (* im im)
           (* im (fma (* im im) 0.002777777777777778 0.08333333333333333))
           im)
          2.0)))
       (*
        (cosh im)
        (fma
         (fma (* re re) 0.008333333333333333 -0.16666666666666666)
         (* re (* re re))
         re))))))
double code(double re, double im) {
	double t_0 = sin(re) * 0.5;
	double t_1 = t_0 * (exp(-im) + exp(im));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = cosh(im) * fma(re, ((re * re) * -0.16666666666666666), re);
	} else if (t_1 <= 5e+132) {
		tmp = t_0 / (1.0 / fma(im, fma((im * im), (im * fma((im * im), 0.002777777777777778, 0.08333333333333333)), im), 2.0));
	} else {
		tmp = cosh(im) * fma(fma((re * re), 0.008333333333333333, -0.16666666666666666), (re * (re * re)), re);
	}
	return tmp;
}
function code(re, im)
	t_0 = Float64(sin(re) * 0.5)
	t_1 = Float64(t_0 * Float64(exp(Float64(-im)) + exp(im)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(cosh(im) * fma(re, Float64(Float64(re * re) * -0.16666666666666666), re));
	elseif (t_1 <= 5e+132)
		tmp = Float64(t_0 / Float64(1.0 / fma(im, fma(Float64(im * im), Float64(im * fma(Float64(im * im), 0.002777777777777778, 0.08333333333333333)), im), 2.0)));
	else
		tmp = Float64(cosh(im) * fma(fma(Float64(re * re), 0.008333333333333333, -0.16666666666666666), Float64(re * Float64(re * re)), re));
	end
	return tmp
end
code[re_, im_] := Block[{t$95$0 = N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[Cosh[im], $MachinePrecision] * N[(re * N[(N[(re * re), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+132], N[(t$95$0 / N[(1.0 / N[(im * N[(N[(im * im), $MachinePrecision] * N[(im * N[(N[(im * im), $MachinePrecision] * 0.002777777777777778 + 0.08333333333333333), $MachinePrecision]), $MachinePrecision] + im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * N[(N[(N[(re * re), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(re * N[(re * re), $MachinePrecision]), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+132}:\\
\;\;\;\;\frac{t\_0}{\frac{1}{\mathsf{fma}\left(im, \mathsf{fma}\left(im \cdot im, im \cdot \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), im\right), 2\right)}}\\

\mathbf{else}:\\
\;\;\;\;\cosh im \cdot \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \left(re \cdot re\right), re\right)\\


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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-sin.f64N/A

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{\color{blue}{0 - im}} + e^{im}\right) \]
      4. lift-exp.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(\color{blue}{e^{0 - im}} + e^{im}\right) \]
      5. lift-exp.f64N/A

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

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

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

        \[\leadsto \left(e^{0 - im} + e^{im}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \]
      9. associate-*r*N/A

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

        \[\leadsto \color{blue}{\left(\left(e^{0 - im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \sin re} \]
    4. Applied egg-rr100.0%

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

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

        \[\leadsto \color{blue}{\left(1 \cdot \cosh im\right)} \cdot \sin re \]
      3. lift-sin.f64N/A

        \[\leadsto \left(1 \cdot \cosh im\right) \cdot \color{blue}{\sin re} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\sin re \cdot \left(1 \cdot \cosh im\right)} \]
      5. lower-*.f64100.0

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

        \[\leadsto \sin re \cdot \color{blue}{\left(1 \cdot \cosh im\right)} \]
      7. *-lft-identity100.0

        \[\leadsto \sin re \cdot \color{blue}{\cosh im} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\sin re \cdot \cosh im} \]
    7. Taylor expanded in re around 0

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(re, \frac{-1}{6} \cdot {re}^{2}, re\right)} \cdot \cosh im \]
      5. *-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(re, \color{blue}{{re}^{2} \cdot \frac{-1}{6}}, re\right) \cdot \cosh im \]
      7. unpow2N/A

        \[\leadsto \mathsf{fma}\left(re, \color{blue}{\left(re \cdot re\right)} \cdot \frac{-1}{6}, re\right) \cdot \cosh im \]
      8. lower-*.f6475.7

        \[\leadsto \mathsf{fma}\left(re, \color{blue}{\left(re \cdot re\right)} \cdot -0.16666666666666666, re\right) \cdot \cosh im \]
    9. Simplified75.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)} \cdot \cosh im \]

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

    1. Initial program 100.0%

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left({im}^{2} \cdot \left(1 + {im}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {im}^{2}\right)\right) + 2\right)} \]
      2. unpow2N/A

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, im \cdot \left(1 + {im}^{2} \cdot \left(\frac{1}{12} + \frac{1}{360} \cdot {im}^{2}\right)\right), 2\right)} \]
    5. Simplified99.0%

      \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \color{blue}{\mathsf{fma}\left(im, \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), im \cdot \left(im \cdot im\right), im\right), 2\right)} \]
    6. Step-by-step derivation
      1. lift-sin.f64N/A

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(im \cdot \left(\left(\color{blue}{\left(im \cdot im\right)} \cdot \frac{1}{360} + \frac{1}{12}\right) \cdot \left(im \cdot \left(im \cdot im\right)\right) + im\right) + 2\right) \]
      4. lift-fma.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(im \cdot \left(\color{blue}{\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right)} \cdot \left(im \cdot \left(im \cdot im\right)\right) + im\right) + 2\right) \]
      5. lift-*.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(im \cdot \left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right) \cdot \left(im \cdot \color{blue}{\left(im \cdot im\right)}\right) + im\right) + 2\right) \]
      6. lift-*.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(im \cdot \left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right) \cdot \color{blue}{\left(im \cdot \left(im \cdot im\right)\right)} + im\right) + 2\right) \]
      7. lift-fma.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(im \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right)} + 2\right) \]
      8. flip-+N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{\left(im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right)\right) \cdot \left(im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right)\right) - 2 \cdot 2}{im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right) - 2}} \]
      9. clear-numN/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\frac{1}{\frac{im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right) - 2}{\left(im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right)\right) \cdot \left(im \cdot \mathsf{fma}\left(\mathsf{fma}\left(im \cdot im, \frac{1}{360}, \frac{1}{12}\right), im \cdot \left(im \cdot im\right), im\right)\right) - 2 \cdot 2}}} \]
    7. Applied egg-rr99.0%

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

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

    1. Initial program 100.0%

      \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-sin.f64N/A

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(e^{\color{blue}{0 - im}} + e^{im}\right) \]
      4. lift-exp.f64N/A

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(\color{blue}{e^{0 - im}} + e^{im}\right) \]
      5. lift-exp.f64N/A

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

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

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

        \[\leadsto \left(e^{0 - im} + e^{im}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot \sin re\right)} \]
      9. associate-*r*N/A

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

        \[\leadsto \color{blue}{\left(\left(e^{0 - im} + e^{im}\right) \cdot \frac{1}{2}\right) \cdot \sin re} \]
    4. Applied egg-rr100.0%

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

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

        \[\leadsto \color{blue}{\left(1 \cdot \cosh im\right)} \cdot \sin re \]
      3. lift-sin.f64N/A

        \[\leadsto \left(1 \cdot \cosh im\right) \cdot \color{blue}{\sin re} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\sin re \cdot \left(1 \cdot \cosh im\right)} \]
      5. lower-*.f64100.0

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

        \[\leadsto \sin re \cdot \color{blue}{\left(1 \cdot \cosh im\right)} \]
      7. *-lft-identity100.0

        \[\leadsto \sin re \cdot \color{blue}{\cosh im} \]
    6. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\sin re \cdot \cosh im} \]
    7. Taylor expanded in re around 0

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

        \[\leadsto \left(re \cdot \color{blue}{\left({re}^{2} \cdot \left(\frac{1}{120} \cdot {re}^{2} - \frac{1}{6}\right) + 1\right)}\right) \cdot \cosh im \]
      2. distribute-lft-inN/A

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

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

        \[\leadsto \left(\left(re \cdot \color{blue}{\left(re \cdot re\right)}\right) \cdot \left(\frac{1}{120} \cdot {re}^{2} - \frac{1}{6}\right) + re \cdot 1\right) \cdot \cosh im \]
      5. cube-multN/A

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

        \[\leadsto \left(\color{blue}{\left(\frac{1}{120} \cdot {re}^{2} - \frac{1}{6}\right) \cdot {re}^{3}} + re \cdot 1\right) \cdot \cosh im \]
      7. *-rgt-identityN/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{120} \cdot {re}^{2} - \frac{1}{6}, {re}^{3}, re\right)} \cdot \cosh im \]
      9. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{1}{120} \cdot {re}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)}, {re}^{3}, re\right) \cdot \cosh im \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{re}^{2} \cdot \frac{1}{120}} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right), {re}^{3}, re\right) \cdot \cosh im \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left({re}^{2} \cdot \frac{1}{120} + \color{blue}{\frac{-1}{6}}, {re}^{3}, re\right) \cdot \cosh im \]
      12. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left({re}^{2}, \frac{1}{120}, \frac{-1}{6}\right)}, {re}^{3}, re\right) \cdot \cosh im \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{re \cdot re}, \frac{1}{120}, \frac{-1}{6}\right), {re}^{3}, re\right) \cdot \cosh im \]
      14. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{re \cdot re}, \frac{1}{120}, \frac{-1}{6}\right), {re}^{3}, re\right) \cdot \cosh im \]
      15. cube-multN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, \frac{1}{120}, \frac{-1}{6}\right), \color{blue}{re \cdot \left(re \cdot re\right)}, re\right) \cdot \cosh im \]
      16. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, \frac{1}{120}, \frac{-1}{6}\right), re \cdot \color{blue}{{re}^{2}}, re\right) \cdot \cosh im \]
      17. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, \frac{1}{120}, \frac{-1}{6}\right), \color{blue}{re \cdot {re}^{2}}, re\right) \cdot \cosh im \]
      18. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, \frac{1}{120}, \frac{-1}{6}\right), re \cdot \color{blue}{\left(re \cdot re\right)}, re\right) \cdot \cosh im \]
      19. lower-*.f6476.1

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \color{blue}{\left(re \cdot re\right)}, re\right) \cdot \cosh im \]
    9. Simplified76.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \left(re \cdot re\right), re\right)} \cdot \cosh im \]
  3. Recombined 3 regimes into one program.
  4. Final simplification87.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(\sin re \cdot 0.5\right) \cdot \left(e^{-im} + e^{im}\right) \leq -\infty:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)\\ \mathbf{elif}\;\left(\sin re \cdot 0.5\right) \cdot \left(e^{-im} + e^{im}\right) \leq 5 \cdot 10^{+132}:\\ \;\;\;\;\frac{\sin re \cdot 0.5}{\frac{1}{\mathsf{fma}\left(im, \mathsf{fma}\left(im \cdot im, im \cdot \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), im\right), 2\right)}}\\ \mathbf{else}:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \left(re \cdot re\right), re\right)\\ \end{array} \]
  5. Add Preprocessing

Reproduce

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