math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 9.7s
Alternatives: 18
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 18 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-*.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-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)} \]
    4. 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) \]
    5. *-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) \]
    6. 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) \]
    7. 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)} \]
    8. *-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) \]
    9. 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) \]
    10. 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) \]
    11. 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) \]
    12. 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) \]
    13. *-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) \]
    14. 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) \]
    15. *-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) \]
    16. 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) \]
    17. 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) \]
    18. 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 rewrites100.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: 82.5% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t\_0 \leq 5:\\
\;\;\;\;\sin re \cdot \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot 0.041666666666666664, 0.5\right), 1\right)\\

\mathbf{else}:\\
\;\;\;\;\left(re \cdot 0.5\right) \cdot \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), 1\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))) < -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-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{2} \cdot \color{blue}{\left(2 \cdot \cosh im\right)}\right) \cdot \sin re \]
      14. associate-*r*N/A

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

        \[\leadsto \left(\color{blue}{1} \cdot \cosh im\right) \cdot \sin re \]
      16. exp-0N/A

        \[\leadsto \left(\color{blue}{e^{0}} \cdot \cosh im\right) \cdot \sin re \]
      17. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(e^{0} \cdot \cosh im\right)} \cdot \sin re \]
      18. exp-0N/A

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

        \[\leadsto \left(1 \cdot \color{blue}{\cosh im}\right) \cdot \sin re \]
    4. Applied rewrites100.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, \color{blue}{im \cdot \left(\frac{1}{24} + \frac{1}{720} \cdot {im}^{2}\right)}, \frac{1}{2}\right), 1\right) \cdot \sin re \]
      10. +-commutativeN/A

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

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

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \color{blue}{\mathsf{fma}\left({im}^{2}, \frac{1}{720}, \frac{1}{24}\right)}, \frac{1}{2}\right), 1\right) \cdot \sin re \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(\color{blue}{im \cdot im}, \frac{1}{720}, \frac{1}{24}\right), \frac{1}{2}\right), 1\right) \cdot \sin re \]
      14. lower-*.f6483.5

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(\color{blue}{im \cdot im}, 0.001388888888888889, 0.041666666666666664\right), 0.5\right), 1\right) \cdot \sin re \]
    7. Applied rewrites83.5%

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

      \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, \frac{1}{720}, \frac{1}{24}\right), \frac{1}{2}\right), 1\right) \cdot \color{blue}{\left(re \cdot \left(1 + \frac{-1}{6} \cdot {re}^{2}\right)\right)} \]
    9. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, \frac{1}{720}, \frac{1}{24}\right), \frac{1}{2}\right), 1\right) \cdot \left(re \cdot \color{blue}{\left(\frac{-1}{6} \cdot {re}^{2} + 1\right)}\right) \]
      2. distribute-rgt-inN/A

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

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, \frac{1}{720}, \frac{1}{24}\right), \frac{1}{2}\right), 1\right) \cdot \left(\color{blue}{\left({re}^{2} \cdot \frac{-1}{6}\right)} \cdot re + 1 \cdot re\right) \]
      4. associate-*l*N/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, \frac{1}{720}, \frac{1}{24}\right), \frac{1}{2}\right), 1\right) \cdot \mathsf{fma}\left(re \cdot re, \color{blue}{re \cdot \frac{-1}{6}}, re\right) \]
      10. lower-*.f6464.9

        \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, 0.001388888888888889, 0.041666666666666664\right), 0.5\right), 1\right) \cdot \mathsf{fma}\left(re \cdot re, \color{blue}{re \cdot -0.16666666666666666}, re\right) \]
    10. Applied rewrites64.9%

      \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \mathsf{fma}\left(im \cdot im, 0.001388888888888889, 0.041666666666666664\right), 0.5\right), 1\right) \cdot \color{blue}{\mathsf{fma}\left(re \cdot re, re \cdot -0.16666666666666666, re\right)} \]
    11. Taylor expanded in im around inf

      \[\leadsto \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im, im \cdot \left(\frac{1}{720} \cdot \color{blue}{{im}^{2}}\right), \frac{1}{2}\right), 1\right) \cdot \mathsf{fma}\left(re \cdot re, re \cdot \frac{-1}{6}, re\right) \]
    12. Step-by-step derivation
      1. Applied rewrites64.9%

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

      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

      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 \color{blue}{\sin re + {im}^{2} \cdot \left(\frac{1}{24} \cdot \left({im}^{2} \cdot \sin re\right) + \frac{1}{2} \cdot \sin re\right)} \]
      4. Step-by-step derivation
        1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left({im}^{2} \cdot \left(\frac{1}{24} \cdot {im}^{2}\right)\right) \cdot \sin re + \left(\color{blue}{\left(\frac{1}{2} \cdot {im}^{2}\right) \cdot \sin re} + \sin re\right) \]
        12. distribute-lft1-inN/A

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

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

      if 5 < (*.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. 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 rewrites85.3%

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

        \[\leadsto \left(\frac{1}{2} \cdot \sin re\right) \cdot \color{blue}{\left(2 + {im}^{2}\right)} \]
      7. 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.f6454.6

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

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

        \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot re\right)} \cdot \mathsf{fma}\left(im, im, 2\right) \]
      10. Step-by-step derivation
        1. lower-*.f6446.6

          \[\leadsto \color{blue}{\left(0.5 \cdot re\right)} \cdot \mathsf{fma}\left(im, im, 2\right) \]
      11. Applied rewrites46.6%

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

        \[\leadsto \left(\frac{1}{2} \cdot 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)} \]
      13. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \left(\frac{1}{2} \cdot 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. lower-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \left(\frac{1}{2} \cdot re\right) \cdot \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(\color{blue}{im \cdot im}, \frac{1}{360}, \frac{1}{12}\right), 1\right), 2\right) \]
        13. lower-*.f6465.7

          \[\leadsto \left(0.5 \cdot re\right) \cdot \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(\color{blue}{im \cdot im}, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right) \]
      14. Applied rewrites65.7%

        \[\leadsto \left(0.5 \cdot re\right) \cdot \color{blue}{\mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), 1\right), 2\right)} \]
    13. Recombined 3 regimes into one program.
    14. Final simplification82.5%

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

    Reproduce

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