math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 10.6s
Alternatives: 20
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 20 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} im_m = \left|im\right| \\ \mathsf{fma}\left(0.5 \cdot \sin re, e^{-im\_m}, \sin re \cdot \left(0.5 \cdot e^{im\_m}\right)\right) \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (fma (* 0.5 (sin re)) (exp (- im_m)) (* (sin re) (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
	return fma((0.5 * sin(re)), exp(-im_m), (sin(re) * (0.5 * exp(im_m))));
}
im_m = abs(im)
function code(re, im_m)
	return fma(Float64(0.5 * sin(re)), exp(Float64(-im_m)), Float64(sin(re) * Float64(0.5 * exp(im_m))))
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[Exp[(-im$95$m)], $MachinePrecision] + N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 84.5% accurate, 0.4× speedup?

\[\begin{array}{l} im_m = \left|im\right| \\ \begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t\_0 \cdot \left(e^{im\_m} + e^{-im\_m}\right)\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+290}:\\ \;\;\;\;\cosh im\_m \cdot \mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+22}:\\ \;\;\;\;t\_0 \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \mathsf{fma}\left(im\_m, \mathsf{fma}\left(\mathsf{fma}\left(im\_m \cdot im\_m, 0.002777777777777778, 0.08333333333333333\right), im\_m \cdot \left(im\_m \cdot im\_m\right), im\_m\right), 2\right)\\ \end{array} \end{array} \]
im_m = (fabs.f64 im)
(FPCore (re im_m)
 :precision binary64
 (let* ((t_0 (* 0.5 (sin re))) (t_1 (* t_0 (+ (exp im_m) (exp (- im_m))))))
   (if (<= t_1 -5e+290)
     (* (cosh im_m) (fma re (* (* re re) -0.16666666666666666) re))
     (if (<= t_1 5e+22)
       (* t_0 (fma im_m im_m 2.0))
       (*
        (* 0.5 re)
        (fma
         im_m
         (fma
          (fma (* im_m im_m) 0.002777777777777778 0.08333333333333333)
          (* im_m (* im_m im_m))
          im_m)
         2.0))))))
im_m = fabs(im);
double code(double re, double im_m) {
	double t_0 = 0.5 * sin(re);
	double t_1 = t_0 * (exp(im_m) + exp(-im_m));
	double tmp;
	if (t_1 <= -5e+290) {
		tmp = cosh(im_m) * fma(re, ((re * re) * -0.16666666666666666), re);
	} else if (t_1 <= 5e+22) {
		tmp = t_0 * fma(im_m, im_m, 2.0);
	} else {
		tmp = (0.5 * re) * fma(im_m, fma(fma((im_m * im_m), 0.002777777777777778, 0.08333333333333333), (im_m * (im_m * im_m)), im_m), 2.0);
	}
	return tmp;
}
im_m = abs(im)
function code(re, im_m)
	t_0 = Float64(0.5 * sin(re))
	t_1 = Float64(t_0 * Float64(exp(im_m) + exp(Float64(-im_m))))
	tmp = 0.0
	if (t_1 <= -5e+290)
		tmp = Float64(cosh(im_m) * fma(re, Float64(Float64(re * re) * -0.16666666666666666), re));
	elseif (t_1 <= 5e+22)
		tmp = Float64(t_0 * fma(im_m, im_m, 2.0));
	else
		tmp = Float64(Float64(0.5 * re) * fma(im_m, fma(fma(Float64(im_m * im_m), 0.002777777777777778, 0.08333333333333333), Float64(im_m * Float64(im_m * im_m)), im_m), 2.0));
	end
	return tmp
end
im_m = N[Abs[im], $MachinePrecision]
code[re_, im$95$m_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[im$95$m], $MachinePrecision] + N[Exp[(-im$95$m)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+290], N[(N[Cosh[im$95$m], $MachinePrecision] * N[(re * N[(N[(re * re), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+22], N[(t$95$0 * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(im$95$m * N[(N[(N[(im$95$m * im$95$m), $MachinePrecision] * 0.002777777777777778 + 0.08333333333333333), $MachinePrecision] * N[(im$95$m * N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision] + im$95$m), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
im_m = \left|im\right|

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

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+22}:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \mathsf{fma}\left(im\_m, \mathsf{fma}\left(\mathsf{fma}\left(im\_m \cdot im\_m, 0.002777777777777778, 0.08333333333333333\right), im\_m \cdot \left(im\_m \cdot im\_m\right), im\_m\right), 2\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))) < -4.9999999999999998e290

    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-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin re \cdot \frac{e^{0 - im} + e^{im}}{2}} \]
    6. Applied rewrites100.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-*.f6474.6

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

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

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

    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}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \left(\color{blue}{im \cdot im} + 2\right) \]
      3. lower-fma.f6498.9

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

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

    if 4.9999999999999996e22 < (*.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 99.9%

      \[\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. Applied rewrites84.1%

      \[\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. Taylor expanded in re around 0

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot re\right)} \cdot \mathsf{fma}\left(im, \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) \]
    7. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{\left(re \cdot \frac{1}{2}\right)} \cdot \mathsf{fma}\left(im, \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) \]
      2. lower-*.f6464.9

        \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \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) \]
    8. Applied rewrites64.9%

      \[\leadsto \color{blue}{\left(re \cdot 0.5\right)} \cdot \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) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification84.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{im} + e^{-im}\right) \leq -5 \cdot 10^{+290}:\\ \;\;\;\;\cosh im \cdot \mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)\\ \mathbf{elif}\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{im} + e^{-im}\right) \leq 5 \cdot 10^{+22}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \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)\\ \end{array} \]
  5. Add Preprocessing

Reproduce

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