math.sin on complex, real part

Percentage Accurate: 100.0% → 100.0%
Time: 5.5s
Alternatives: 7
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 7 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, 1.0× speedup?

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

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

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Step-by-step derivation
    1. sub0-neg100.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. Final simplification100.0%

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

Alternative 2: 85.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 0.06 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\ \;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (or (<= im 0.06) (not (<= im 1.35e+154)))
   (+ (sin re) (* (* 0.5 (sin re)) (* im im)))
   (* (* 0.5 re) (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
	double tmp;
	if ((im <= 0.06) || !(im <= 1.35e+154)) {
		tmp = sin(re) + ((0.5 * sin(re)) * (im * im));
	} else {
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if ((im <= 0.06d0) .or. (.not. (im <= 1.35d+154))) then
        tmp = sin(re) + ((0.5d0 * sin(re)) * (im * im))
    else
        tmp = (0.5d0 * re) * (exp(-im) + exp(im))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if ((im <= 0.06) || !(im <= 1.35e+154)) {
		tmp = Math.sin(re) + ((0.5 * Math.sin(re)) * (im * im));
	} else {
		tmp = (0.5 * re) * (Math.exp(-im) + Math.exp(im));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if (im <= 0.06) or not (im <= 1.35e+154):
		tmp = math.sin(re) + ((0.5 * math.sin(re)) * (im * im))
	else:
		tmp = (0.5 * re) * (math.exp(-im) + math.exp(im))
	return tmp
function code(re, im)
	tmp = 0.0
	if ((im <= 0.06) || !(im <= 1.35e+154))
		tmp = Float64(sin(re) + Float64(Float64(0.5 * sin(re)) * Float64(im * im)));
	else
		tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im)));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if ((im <= 0.06) || ~((im <= 1.35e+154)))
		tmp = sin(re) + ((0.5 * sin(re)) * (im * im));
	else
		tmp = (0.5 * re) * (exp(-im) + exp(im));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[Or[LessEqual[im, 0.06], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[Sin[re], $MachinePrecision] + N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.06 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 0.059999999999999998 or 1.35000000000000003e154 < 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. sub0-neg100.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. Taylor expanded in im around 0 85.5%

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

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

    if 0.059999999999999998 < im < 1.35000000000000003e154

    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. sub0-neg100.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. Taylor expanded in re around 0 86.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.06 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\ \;\;\;\;\sin re + \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \]

Alternative 3: 69.7% accurate, 1.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if im < 1.9000000000000001e-4

    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. sub0-neg100.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. Taylor expanded in im around 0 66.0%

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

    if 1.9000000000000001e-4 < 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. sub0-neg100.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. Taylor expanded in re around 0 83.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.00019:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\ \end{array} \]

Alternative 4: 62.8% accurate, 2.9× speedup?

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

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

\mathbf{elif}\;im \leq 1.45 \cdot 10^{+71}:\\
\;\;\;\;{re}^{-512}\\

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


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

    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. sub0-neg100.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. Taylor expanded in im around 0 65.7%

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

    if 4.6e9 < im < 1.45000000000000004e71

    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. sub0-neg100.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. Taylor expanded in re around 0 75.0%

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

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

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

    if 1.45000000000000004e71 < 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. sub0-neg100.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. Taylor expanded in re around 0 87.8%

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

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

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

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

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

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

        \[\leadsto re + 0.5 \cdot \left(\color{blue}{0} + \log \left(e^{re \cdot {im}^{2}}\right)\right) \]
      5. add-log-exp70.2%

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

        \[\leadsto re + 0.5 \cdot \left(0 + re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      7. *-commutative70.2%

        \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{\left(im \cdot im\right) \cdot re}\right) \]
      8. associate-*l*54.7%

        \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{im \cdot \left(im \cdot re\right)}\right) \]
    8. Applied egg-rr54.7%

      \[\leadsto re + 0.5 \cdot \color{blue}{\left(0 + im \cdot \left(im \cdot re\right)\right)} \]
    9. Step-by-step derivation
      1. +-lft-identity54.7%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 4600000000:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.45 \cdot 10^{+71}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 5: 62.1% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;im \leq 0.031:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ \end{array} \end{array} \]
(FPCore (re im)
 :precision binary64
 (if (<= im 0.031) (sin re) (+ re (* 0.5 (* re (* im im))))))
double code(double re, double im) {
	double tmp;
	if (im <= 0.031) {
		tmp = sin(re);
	} else {
		tmp = re + (0.5 * (re * (im * im)));
	}
	return tmp;
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8) :: tmp
    if (im <= 0.031d0) then
        tmp = sin(re)
    else
        tmp = re + (0.5d0 * (re * (im * im)))
    end if
    code = tmp
end function
public static double code(double re, double im) {
	double tmp;
	if (im <= 0.031) {
		tmp = Math.sin(re);
	} else {
		tmp = re + (0.5 * (re * (im * im)));
	}
	return tmp;
}
def code(re, im):
	tmp = 0
	if im <= 0.031:
		tmp = math.sin(re)
	else:
		tmp = re + (0.5 * (re * (im * im)))
	return tmp
function code(re, im)
	tmp = 0.0
	if (im <= 0.031)
		tmp = sin(re);
	else
		tmp = Float64(re + Float64(0.5 * Float64(re * Float64(im * im))));
	end
	return tmp
end
function tmp_2 = code(re, im)
	tmp = 0.0;
	if (im <= 0.031)
		tmp = sin(re);
	else
		tmp = re + (0.5 * (re * (im * im)));
	end
	tmp_2 = tmp;
end
code[re_, im_] := If[LessEqual[im, 0.031], N[Sin[re], $MachinePrecision], N[(re + N[(0.5 * N[(re * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    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. sub0-neg100.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. Taylor expanded in im around 0 65.7%

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

    if 0.031 < 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. sub0-neg100.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. Taylor expanded in re around 0 84.6%

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

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

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

        \[\leadsto re + 0.5 \cdot \color{blue}{\log \left(e^{re \cdot {im}^{2}}\right)} \]
      2. *-un-lft-identity72.5%

        \[\leadsto re + 0.5 \cdot \log \color{blue}{\left(1 \cdot e^{re \cdot {im}^{2}}\right)} \]
      3. log-prod72.5%

        \[\leadsto re + 0.5 \cdot \color{blue}{\left(\log 1 + \log \left(e^{re \cdot {im}^{2}}\right)\right)} \]
      4. metadata-eval72.5%

        \[\leadsto re + 0.5 \cdot \left(\color{blue}{0} + \log \left(e^{re \cdot {im}^{2}}\right)\right) \]
      5. add-log-exp53.5%

        \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{re \cdot {im}^{2}}\right) \]
      6. pow253.5%

        \[\leadsto re + 0.5 \cdot \left(0 + re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
      7. *-commutative53.5%

        \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{\left(im \cdot im\right) \cdot re}\right) \]
      8. associate-*l*41.8%

        \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{im \cdot \left(im \cdot re\right)}\right) \]
    8. Applied egg-rr41.8%

      \[\leadsto re + 0.5 \cdot \color{blue}{\left(0 + im \cdot \left(im \cdot re\right)\right)} \]
    9. Step-by-step derivation
      1. +-lft-identity41.8%

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

        \[\leadsto re + 0.5 \cdot \color{blue}{\left(\left(im \cdot im\right) \cdot re\right)} \]
      3. *-commutative53.5%

        \[\leadsto re + 0.5 \cdot \color{blue}{\left(re \cdot \left(im \cdot im\right)\right)} \]
    10. Simplified53.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 0.031:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ \end{array} \]

Alternative 6: 49.2% accurate, 34.3× speedup?

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

\\
re + 0.5 \cdot \left(re \cdot \left(im \cdot 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. Step-by-step derivation
    1. sub0-neg100.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. Taylor expanded in re around 0 67.5%

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

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

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

      \[\leadsto re + 0.5 \cdot \color{blue}{\log \left(e^{re \cdot {im}^{2}}\right)} \]
    2. *-un-lft-identity60.4%

      \[\leadsto re + 0.5 \cdot \log \color{blue}{\left(1 \cdot e^{re \cdot {im}^{2}}\right)} \]
    3. log-prod60.4%

      \[\leadsto re + 0.5 \cdot \color{blue}{\left(\log 1 + \log \left(e^{re \cdot {im}^{2}}\right)\right)} \]
    4. metadata-eval60.4%

      \[\leadsto re + 0.5 \cdot \left(\color{blue}{0} + \log \left(e^{re \cdot {im}^{2}}\right)\right) \]
    5. add-log-exp52.5%

      \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{re \cdot {im}^{2}}\right) \]
    6. pow252.5%

      \[\leadsto re + 0.5 \cdot \left(0 + re \cdot \color{blue}{\left(im \cdot im\right)}\right) \]
    7. *-commutative52.5%

      \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{\left(im \cdot im\right) \cdot re}\right) \]
    8. associate-*l*46.2%

      \[\leadsto re + 0.5 \cdot \left(0 + \color{blue}{im \cdot \left(im \cdot re\right)}\right) \]
  8. Applied egg-rr46.2%

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

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

      \[\leadsto re + 0.5 \cdot \color{blue}{\left(\left(im \cdot im\right) \cdot re\right)} \]
    3. *-commutative52.5%

      \[\leadsto re + 0.5 \cdot \color{blue}{\left(re \cdot \left(im \cdot im\right)\right)} \]
  10. Simplified52.5%

    \[\leadsto re + 0.5 \cdot \color{blue}{\left(re \cdot \left(im \cdot im\right)\right)} \]
  11. Final simplification52.5%

    \[\leadsto re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right) \]

Alternative 7: 27.4% accurate, 309.0× speedup?

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

\\
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. sub0-neg100.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. Taylor expanded in re around 0 67.5%

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

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

    \[\leadsto \color{blue}{re} \]
  7. Final simplification28.5%

    \[\leadsto re \]

Reproduce

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