math.cube on complex, imaginary part

Percentage Accurate: 83.3% → 99.8%
Time: 5.9s
Alternatives: 6
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
public static double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re)
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_im) + Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_re))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision] + N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\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 6 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: 83.3% accurate, 1.0× speedup?

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

\\
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\end{array}

Alternative 1: 99.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 1.55 \cdot 10^{+67}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right) - {x.im}^{3}\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -5e+102) (not (<= x.im 1.55e+67)))
   (* x.im (* (- x.re x.im) (+ x.im x.re)))
   (- (* (* x.im x.re) (* x.re 3.0)) (pow x.im 3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -5e+102) || !(x_46_im <= 1.55e+67)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = ((x_46_im * x_46_re) * (x_46_re * 3.0)) - pow(x_46_im, 3.0);
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46im <= (-5d+102)) .or. (.not. (x_46im <= 1.55d+67))) then
        tmp = x_46im * ((x_46re - x_46im) * (x_46im + x_46re))
    else
        tmp = ((x_46im * x_46re) * (x_46re * 3.0d0)) - (x_46im ** 3.0d0)
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -5e+102) || !(x_46_im <= 1.55e+67)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = ((x_46_im * x_46_re) * (x_46_re * 3.0)) - Math.pow(x_46_im, 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -5e+102) or not (x_46_im <= 1.55e+67):
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))
	else:
		tmp = ((x_46_im * x_46_re) * (x_46_re * 3.0)) - math.pow(x_46_im, 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -5e+102) || !(x_46_im <= 1.55e+67))
		tmp = Float64(x_46_im * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_im + x_46_re)));
	else
		tmp = Float64(Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re * 3.0)) - (x_46_im ^ 3.0));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_im <= -5e+102) || ~((x_46_im <= 1.55e+67)))
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	else
		tmp = ((x_46_im * x_46_re) * (x_46_re * 3.0)) - (x_46_im ^ 3.0);
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$im, -5e+102], N[Not[LessEqual[x$46$im, 1.55e+67]], $MachinePrecision]], N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision] - N[Power[x$46$im, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 1.55 \cdot 10^{+67}\right):\\
\;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right) - {x.im}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -5e102 or 1.54999999999999998e67 < x.im

    1. Initial program 67.4%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. difference-of-squares81.4%

        \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
      2. *-commutative81.4%

        \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied egg-rr81.4%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. expm1-log1p-u61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      2. expm1-udef61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)} - 1\right)} \]
      3. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right)} - 1\right) \]
      4. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right)} - 1\right) \]
      5. count-261.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      6. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      7. associate-*r*61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 2\right)\right)}\right)} - 1\right) \]
      8. associate-*r*61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      9. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      10. count-261.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)} - 1\right) \]
      11. flip-+0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}}\right)} - 1\right) \]
      12. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im}\right)} - 1\right) \]
      13. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{\color{blue}{0}}\right)} - 1\right) \]
    5. Applied egg-rr0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{0}\right)} - 1\right)} \]
    6. Simplified100.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{0} \]

    if -5e102 < x.im < 1.54999999999999998e67

    1. Initial program 89.9%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Simplified99.8%

      \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
    3. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 3\right)} - {x.im}^{3} \]
      2. associate-*l*99.8%

        \[\leadsto \color{blue}{\left(x.re \cdot \left(x.re \cdot x.im\right)\right) \cdot 3} - {x.im}^{3} \]
      3. add-sqr-sqrt63.3%

        \[\leadsto \color{blue}{\sqrt{\left(x.re \cdot \left(x.re \cdot x.im\right)\right) \cdot 3} \cdot \sqrt{\left(x.re \cdot \left(x.re \cdot x.im\right)\right) \cdot 3}} - {x.im}^{3} \]
      4. pow263.3%

        \[\leadsto \color{blue}{{\left(\sqrt{\left(x.re \cdot \left(x.re \cdot x.im\right)\right) \cdot 3}\right)}^{2}} - {x.im}^{3} \]
      5. associate-*r*58.5%

        \[\leadsto {\left(\sqrt{\color{blue}{\left(\left(x.re \cdot x.re\right) \cdot x.im\right)} \cdot 3}\right)}^{2} - {x.im}^{3} \]
      6. associate-*r*58.5%

        \[\leadsto {\left(\sqrt{\color{blue}{\left(x.re \cdot x.re\right) \cdot \left(x.im \cdot 3\right)}}\right)}^{2} - {x.im}^{3} \]
      7. sqrt-prod43.2%

        \[\leadsto {\color{blue}{\left(\sqrt{x.re \cdot x.re} \cdot \sqrt{x.im \cdot 3}\right)}}^{2} - {x.im}^{3} \]
      8. sqrt-prod25.1%

        \[\leadsto {\left(\color{blue}{\left(\sqrt{x.re} \cdot \sqrt{x.re}\right)} \cdot \sqrt{x.im \cdot 3}\right)}^{2} - {x.im}^{3} \]
      9. add-sqr-sqrt48.6%

        \[\leadsto {\left(\color{blue}{x.re} \cdot \sqrt{x.im \cdot 3}\right)}^{2} - {x.im}^{3} \]
    4. Applied egg-rr48.6%

      \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} - {x.im}^{3} \]
    5. Step-by-step derivation
      1. unpow248.6%

        \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} - {x.im}^{3} \]
      2. *-commutative48.6%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right) - {x.im}^{3} \]
      3. *-commutative48.6%

        \[\leadsto \left(\sqrt{x.im \cdot 3} \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} - {x.im}^{3} \]
      4. swap-sqr43.2%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot x.re\right)} - {x.im}^{3} \]
      5. add-sqr-sqrt89.9%

        \[\leadsto \color{blue}{\left(x.im \cdot 3\right)} \cdot \left(x.re \cdot x.re\right) - {x.im}^{3} \]
      6. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \cdot x.re\right) \cdot x.re} - {x.im}^{3} \]
      7. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right)} \cdot x.re - {x.im}^{3} \]
      8. *-commutative99.8%

        \[\leadsto \left(x.im \cdot \color{blue}{\left(x.re \cdot 3\right)}\right) \cdot x.re - {x.im}^{3} \]
      9. *-commutative99.8%

        \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)} - {x.im}^{3} \]
      10. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} - {x.im}^{3} \]
    6. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 1.55 \cdot 10^{+67}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right) - {x.im}^{3}\\ \end{array} \]

Alternative 2: 99.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 2 \cdot 10^{+65}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 3\right) - {x.im}^{3}\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -5e+102) (not (<= x.im 2e+65)))
   (* x.im (* (- x.re x.im) (+ x.im x.re)))
   (- (* x.re (* (* x.im x.re) 3.0)) (pow x.im 3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -5e+102) || !(x_46_im <= 2e+65)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = (x_46_re * ((x_46_im * x_46_re) * 3.0)) - pow(x_46_im, 3.0);
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46im <= (-5d+102)) .or. (.not. (x_46im <= 2d+65))) then
        tmp = x_46im * ((x_46re - x_46im) * (x_46im + x_46re))
    else
        tmp = (x_46re * ((x_46im * x_46re) * 3.0d0)) - (x_46im ** 3.0d0)
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -5e+102) || !(x_46_im <= 2e+65)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = (x_46_re * ((x_46_im * x_46_re) * 3.0)) - Math.pow(x_46_im, 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -5e+102) or not (x_46_im <= 2e+65):
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))
	else:
		tmp = (x_46_re * ((x_46_im * x_46_re) * 3.0)) - math.pow(x_46_im, 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -5e+102) || !(x_46_im <= 2e+65))
		tmp = Float64(x_46_im * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_im + x_46_re)));
	else
		tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_im * x_46_re) * 3.0)) - (x_46_im ^ 3.0));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_im <= -5e+102) || ~((x_46_im <= 2e+65)))
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	else
		tmp = (x_46_re * ((x_46_im * x_46_re) * 3.0)) - (x_46_im ^ 3.0);
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$im, -5e+102], N[Not[LessEqual[x$46$im, 2e+65]], $MachinePrecision]], N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re * N[(N[(x$46$im * x$46$re), $MachinePrecision] * 3.0), $MachinePrecision]), $MachinePrecision] - N[Power[x$46$im, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 2 \cdot 10^{+65}\right):\\
\;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 3\right) - {x.im}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -5e102 or 2e65 < x.im

    1. Initial program 67.4%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. difference-of-squares81.4%

        \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
      2. *-commutative81.4%

        \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied egg-rr81.4%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. expm1-log1p-u61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      2. expm1-udef61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)} - 1\right)} \]
      3. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right)} - 1\right) \]
      4. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right)} - 1\right) \]
      5. count-261.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      6. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      7. associate-*r*61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 2\right)\right)}\right)} - 1\right) \]
      8. associate-*r*61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      9. *-commutative61.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      10. count-261.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)} - 1\right) \]
      11. flip-+0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}}\right)} - 1\right) \]
      12. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im}\right)} - 1\right) \]
      13. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{\color{blue}{0}}\right)} - 1\right) \]
    5. Applied egg-rr0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{0}\right)} - 1\right)} \]
    6. Simplified100.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{0} \]

    if -5e102 < x.im < 2e65

    1. Initial program 89.9%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Simplified99.8%

      \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
    3. Taylor expanded in x.re around 0 99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -5 \cdot 10^{+102} \lor \neg \left(x.im \leq 2 \cdot 10^{+65}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 3\right) - {x.im}^{3}\\ \end{array} \]

Alternative 3: 97.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ t_1 := t_0 + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{if}\;x.im \leq -5 \cdot 10^{+142}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq -1.05 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x.im \leq 10^{-125}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\ \mathbf{elif}\;x.im \leq 0.00275:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (let* ((t_0 (* x.im (* (- x.re x.im) (+ x.im x.re))))
        (t_1 (+ t_0 (* x.re (* (* x.im x.re) 2.0)))))
   (if (<= x.im -5e+142)
     t_0
     (if (<= x.im -1.05e-66)
       t_1
       (if (<= x.im 1e-125)
         (* (* x.im x.re) (* x.re 3.0))
         (if (<= x.im 0.00275) t_1 t_0))))))
double code(double x_46_re, double x_46_im) {
	double t_0 = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	double t_1 = t_0 + (x_46_re * ((x_46_im * x_46_re) * 2.0));
	double tmp;
	if (x_46_im <= -5e+142) {
		tmp = t_0;
	} else if (x_46_im <= -1.05e-66) {
		tmp = t_1;
	} else if (x_46_im <= 1e-125) {
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	} else if (x_46_im <= 0.00275) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = x_46im * ((x_46re - x_46im) * (x_46im + x_46re))
    t_1 = t_0 + (x_46re * ((x_46im * x_46re) * 2.0d0))
    if (x_46im <= (-5d+142)) then
        tmp = t_0
    else if (x_46im <= (-1.05d-66)) then
        tmp = t_1
    else if (x_46im <= 1d-125) then
        tmp = (x_46im * x_46re) * (x_46re * 3.0d0)
    else if (x_46im <= 0.00275d0) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double t_0 = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	double t_1 = t_0 + (x_46_re * ((x_46_im * x_46_re) * 2.0));
	double tmp;
	if (x_46_im <= -5e+142) {
		tmp = t_0;
	} else if (x_46_im <= -1.05e-66) {
		tmp = t_1;
	} else if (x_46_im <= 1e-125) {
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	} else if (x_46_im <= 0.00275) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	t_0 = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))
	t_1 = t_0 + (x_46_re * ((x_46_im * x_46_re) * 2.0))
	tmp = 0
	if x_46_im <= -5e+142:
		tmp = t_0
	elif x_46_im <= -1.05e-66:
		tmp = t_1
	elif x_46_im <= 1e-125:
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0)
	elif x_46_im <= 0.00275:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(x_46_re, x_46_im)
	t_0 = Float64(x_46_im * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_im + x_46_re)))
	t_1 = Float64(t_0 + Float64(x_46_re * Float64(Float64(x_46_im * x_46_re) * 2.0)))
	tmp = 0.0
	if (x_46_im <= -5e+142)
		tmp = t_0;
	elseif (x_46_im <= -1.05e-66)
		tmp = t_1;
	elseif (x_46_im <= 1e-125)
		tmp = Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re * 3.0));
	elseif (x_46_im <= 0.00275)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	t_0 = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	t_1 = t_0 + (x_46_re * ((x_46_im * x_46_re) * 2.0));
	tmp = 0.0;
	if (x_46_im <= -5e+142)
		tmp = t_0;
	elseif (x_46_im <= -1.05e-66)
		tmp = t_1;
	elseif (x_46_im <= 1e-125)
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	elseif (x_46_im <= 0.00275)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := Block[{t$95$0 = N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(x$46$re * N[(N[(x$46$im * x$46$re), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$46$im, -5e+142], t$95$0, If[LessEqual[x$46$im, -1.05e-66], t$95$1, If[LessEqual[x$46$im, 1e-125], N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$im, 0.00275], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\
t_1 := t_0 + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\
\mathbf{if}\;x.im \leq -5 \cdot 10^{+142}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x.im \leq -1.05 \cdot 10^{-66}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;x.im \leq 10^{-125}:\\
\;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\

\mathbf{elif}\;x.im \leq 0.00275:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.im < -5.0000000000000001e142 or 0.0027499999999999998 < x.im

    1. Initial program 68.9%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. difference-of-squares82.2%

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

        \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied egg-rr82.2%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. expm1-log1p-u71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      2. expm1-udef71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)} - 1\right)} \]
      3. *-commutative71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right)} - 1\right) \]
      4. *-commutative71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right)} - 1\right) \]
      5. count-271.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      6. *-commutative71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      7. associate-*r*71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 2\right)\right)}\right)} - 1\right) \]
      8. associate-*r*71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      9. *-commutative71.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      10. count-271.1%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)} - 1\right) \]
      11. flip-+0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}}\right)} - 1\right) \]
      12. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im}\right)} - 1\right) \]
      13. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{\color{blue}{0}}\right)} - 1\right) \]
    5. Applied egg-rr0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{0}\right)} - 1\right)} \]
    6. Simplified100.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{0} \]

    if -5.0000000000000001e142 < x.im < -1.05e-66 or 1.00000000000000001e-125 < x.im < 0.0027499999999999998

    1. Initial program 99.8%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. difference-of-squares99.8%

        \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
      2. *-commutative99.8%

        \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. *-commutative99.8%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re \]
      2. *-un-lft-identity99.8%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\color{blue}{1 \cdot \left(x.re \cdot x.im\right)} + x.re \cdot x.im\right) \cdot x.re \]
      3. *-un-lft-identity99.8%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(1 \cdot \left(x.re \cdot x.im\right) + \color{blue}{1 \cdot \left(x.re \cdot x.im\right)}\right) \cdot x.re \]
      4. distribute-rgt-out99.8%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot \left(1 + 1\right)\right)} \cdot x.re \]
      5. metadata-eval99.8%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(\left(x.re \cdot x.im\right) \cdot \color{blue}{2}\right) \cdot x.re \]
    5. Applied egg-rr99.8%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)} \cdot x.re \]

    if -1.05e-66 < x.im < 1.00000000000000001e-125

    1. Initial program 83.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Taylor expanded in x.re around inf 83.2%

      \[\leadsto \color{blue}{{x.re}^{2} \cdot \left(x.im + 2 \cdot x.im\right)} \]
    3. Step-by-step derivation
      1. distribute-rgt1-in83.2%

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

        \[\leadsto {x.re}^{2} \cdot \left(\color{blue}{3} \cdot x.im\right) \]
      3. *-commutative83.2%

        \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(x.im \cdot 3\right)} \]
      4. add-sqr-sqrt37.1%

        \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right)} \]
      5. unpow237.1%

        \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot \left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \]
      6. swap-sqr46.3%

        \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} \]
      7. unpow246.3%

        \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
    4. Applied egg-rr46.3%

      \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
    5. Step-by-step derivation
      1. unpow246.3%

        \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} - {x.im}^{3} \]
      2. *-commutative46.3%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right) - {x.im}^{3} \]
      3. *-commutative46.3%

        \[\leadsto \left(\sqrt{x.im \cdot 3} \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} - {x.im}^{3} \]
      4. swap-sqr37.1%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot x.re\right)} - {x.im}^{3} \]
      5. add-sqr-sqrt83.2%

        \[\leadsto \color{blue}{\left(x.im \cdot 3\right)} \cdot \left(x.re \cdot x.re\right) - {x.im}^{3} \]
      6. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \cdot x.re\right) \cdot x.re} - {x.im}^{3} \]
      7. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right)} \cdot x.re - {x.im}^{3} \]
      8. *-commutative99.7%

        \[\leadsto \left(x.im \cdot \color{blue}{\left(x.re \cdot 3\right)}\right) \cdot x.re - {x.im}^{3} \]
      9. *-commutative99.7%

        \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)} - {x.im}^{3} \]
      10. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} - {x.im}^{3} \]
    6. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -5 \cdot 10^{+142}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{elif}\;x.im \leq -1.05 \cdot 10^{-66}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{elif}\;x.im \leq 10^{-125}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\ \mathbf{elif}\;x.im \leq 0.00275:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right) + x.re \cdot \left(\left(x.im \cdot x.re\right) \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \end{array} \]

Alternative 4: 92.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq -0.106 \lor \neg \left(x.im \leq 2.7 \cdot 10^{-48}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.im -0.106) (not (<= x.im 2.7e-48)))
   (* x.im (* (- x.re x.im) (+ x.im x.re)))
   (* (* x.im x.re) (* x.re 3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -0.106) || !(x_46_im <= 2.7e-48)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46im <= (-0.106d0)) .or. (.not. (x_46im <= 2.7d-48))) then
        tmp = x_46im * ((x_46re - x_46im) * (x_46im + x_46re))
    else
        tmp = (x_46im * x_46re) * (x_46re * 3.0d0)
    end if
    code = tmp
end function
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_im <= -0.106) || !(x_46_im <= 2.7e-48)) {
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	} else {
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_im <= -0.106) or not (x_46_im <= 2.7e-48):
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re))
	else:
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_im <= -0.106) || !(x_46_im <= 2.7e-48))
		tmp = Float64(x_46_im * Float64(Float64(x_46_re - x_46_im) * Float64(x_46_im + x_46_re)));
	else
		tmp = Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re * 3.0));
	end
	return tmp
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_im <= -0.106) || ~((x_46_im <= 2.7e-48)))
		tmp = x_46_im * ((x_46_re - x_46_im) * (x_46_im + x_46_re));
	else
		tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$im, -0.106], N[Not[LessEqual[x$46$im, 2.7e-48]], $MachinePrecision]], N[(x$46$im * N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$im + x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq -0.106 \lor \neg \left(x.im \leq 2.7 \cdot 10^{-48}\right):\\
\;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < -0.105999999999999997 or 2.70000000000000011e-48 < x.im

    1. Initial program 78.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Step-by-step derivation
      1. difference-of-squares87.5%

        \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
      2. *-commutative87.5%

        \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied egg-rr87.5%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    4. Step-by-step derivation
      1. expm1-log1p-u64.2%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
      2. expm1-udef63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)} - 1\right)} \]
      3. *-commutative63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right)} - 1\right) \]
      4. *-commutative63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right)} - 1\right) \]
      5. count-263.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      6. *-commutative63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      7. associate-*r*63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 2\right)\right)}\right)} - 1\right) \]
      8. associate-*r*63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
      9. *-commutative63.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
      10. count-263.6%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)} - 1\right) \]
      11. flip-+0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}}\right)} - 1\right) \]
      12. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im}\right)} - 1\right) \]
      13. +-inverses0.0%

        \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{\color{blue}{0}}\right)} - 1\right) \]
    5. Applied egg-rr0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{0}\right)} - 1\right)} \]
    6. Simplified96.9%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{0} \]

    if -0.105999999999999997 < x.im < 2.70000000000000011e-48

    1. Initial program 86.6%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Taylor expanded in x.re around inf 81.9%

      \[\leadsto \color{blue}{{x.re}^{2} \cdot \left(x.im + 2 \cdot x.im\right)} \]
    3. Step-by-step derivation
      1. distribute-rgt1-in81.9%

        \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(\left(2 + 1\right) \cdot x.im\right)} \]
      2. metadata-eval81.9%

        \[\leadsto {x.re}^{2} \cdot \left(\color{blue}{3} \cdot x.im\right) \]
      3. *-commutative81.9%

        \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(x.im \cdot 3\right)} \]
      4. add-sqr-sqrt37.6%

        \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right)} \]
      5. unpow237.6%

        \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot \left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \]
      6. swap-sqr44.9%

        \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} \]
      7. unpow244.9%

        \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
    4. Applied egg-rr44.9%

      \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
    5. Step-by-step derivation
      1. unpow247.0%

        \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} - {x.im}^{3} \]
      2. *-commutative47.0%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right) - {x.im}^{3} \]
      3. *-commutative47.0%

        \[\leadsto \left(\sqrt{x.im \cdot 3} \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} - {x.im}^{3} \]
      4. swap-sqr39.7%

        \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot x.re\right)} - {x.im}^{3} \]
      5. add-sqr-sqrt86.5%

        \[\leadsto \color{blue}{\left(x.im \cdot 3\right)} \cdot \left(x.re \cdot x.re\right) - {x.im}^{3} \]
      6. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \cdot x.re\right) \cdot x.re} - {x.im}^{3} \]
      7. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right)} \cdot x.re - {x.im}^{3} \]
      8. *-commutative99.7%

        \[\leadsto \left(x.im \cdot \color{blue}{\left(x.re \cdot 3\right)}\right) \cdot x.re - {x.im}^{3} \]
      9. *-commutative99.7%

        \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)} - {x.im}^{3} \]
      10. associate-*r*99.7%

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} - {x.im}^{3} \]
    6. Applied egg-rr95.1%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -0.106 \lor \neg \left(x.im \leq 2.7 \cdot 10^{-48}\right):\\ \;\;\;\;x.im \cdot \left(\left(x.re - x.im\right) \cdot \left(x.im + x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)\\ \end{array} \]

Alternative 5: 55.8% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* (* x.im x.re) (* x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	return (x_46_im * x_46_re) * (x_46_re * 3.0);
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (x_46im * x_46re) * (x_46re * 3.0d0)
end function
public static double code(double x_46_re, double x_46_im) {
	return (x_46_im * x_46_re) * (x_46_re * 3.0);
}
def code(x_46_re, x_46_im):
	return (x_46_im * x_46_re) * (x_46_re * 3.0)
function code(x_46_re, x_46_im)
	return Float64(Float64(x_46_im * x_46_re) * Float64(x_46_re * 3.0))
end
function tmp = code(x_46_re, x_46_im)
	tmp = (x_46_im * x_46_re) * (x_46_re * 3.0);
end
code[x$46$re_, x$46$im_] := N[(N[(x$46$im * x$46$re), $MachinePrecision] * N[(x$46$re * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right)
\end{array}
Derivation
  1. Initial program 82.4%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Taylor expanded in x.re around inf 58.9%

    \[\leadsto \color{blue}{{x.re}^{2} \cdot \left(x.im + 2 \cdot x.im\right)} \]
  3. Step-by-step derivation
    1. distribute-rgt1-in58.9%

      \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(\left(2 + 1\right) \cdot x.im\right)} \]
    2. metadata-eval58.9%

      \[\leadsto {x.re}^{2} \cdot \left(\color{blue}{3} \cdot x.im\right) \]
    3. *-commutative58.9%

      \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(x.im \cdot 3\right)} \]
    4. add-sqr-sqrt30.6%

      \[\leadsto {x.re}^{2} \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right)} \]
    5. unpow230.6%

      \[\leadsto \color{blue}{\left(x.re \cdot x.re\right)} \cdot \left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \]
    6. swap-sqr34.2%

      \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} \]
    7. unpow234.2%

      \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
  4. Applied egg-rr34.2%

    \[\leadsto \color{blue}{{\left(x.re \cdot \sqrt{x.im \cdot 3}\right)}^{2}} \]
  5. Step-by-step derivation
    1. unpow242.4%

      \[\leadsto \color{blue}{\left(x.re \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right)} - {x.im}^{3} \]
    2. *-commutative42.4%

      \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} \cdot \left(x.re \cdot \sqrt{x.im \cdot 3}\right) - {x.im}^{3} \]
    3. *-commutative42.4%

      \[\leadsto \left(\sqrt{x.im \cdot 3} \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot x.re\right)} - {x.im}^{3} \]
    4. swap-sqr38.8%

      \[\leadsto \color{blue}{\left(\sqrt{x.im \cdot 3} \cdot \sqrt{x.im \cdot 3}\right) \cdot \left(x.re \cdot x.re\right)} - {x.im}^{3} \]
    5. add-sqr-sqrt80.4%

      \[\leadsto \color{blue}{\left(x.im \cdot 3\right)} \cdot \left(x.re \cdot x.re\right) - {x.im}^{3} \]
    6. associate-*r*87.0%

      \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \cdot x.re\right) \cdot x.re} - {x.im}^{3} \]
    7. associate-*r*86.9%

      \[\leadsto \color{blue}{\left(x.im \cdot \left(3 \cdot x.re\right)\right)} \cdot x.re - {x.im}^{3} \]
    8. *-commutative86.9%

      \[\leadsto \left(x.im \cdot \color{blue}{\left(x.re \cdot 3\right)}\right) \cdot x.re - {x.im}^{3} \]
    9. *-commutative86.9%

      \[\leadsto \color{blue}{x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)} - {x.im}^{3} \]
    10. associate-*r*87.0%

      \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} - {x.im}^{3} \]
  6. Applied egg-rr65.4%

    \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot 3\right)} \]
  7. Final simplification65.4%

    \[\leadsto \left(x.im \cdot x.re\right) \cdot \left(x.re \cdot 3\right) \]

Alternative 6: 2.7% accurate, 19.0× speedup?

\[\begin{array}{l} \\ -3 \end{array} \]
(FPCore (x.re x.im) :precision binary64 -3.0)
double code(double x_46_re, double x_46_im) {
	return -3.0;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = -3.0d0
end function
public static double code(double x_46_re, double x_46_im) {
	return -3.0;
}
def code(x_46_re, x_46_im):
	return -3.0
function code(x_46_re, x_46_im)
	return -3.0
end
function tmp = code(x_46_re, x_46_im)
	tmp = -3.0;
end
code[x$46$re_, x$46$im_] := -3.0
\begin{array}{l}

\\
-3
\end{array}
Derivation
  1. Initial program 82.4%

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Step-by-step derivation
    1. difference-of-squares87.1%

      \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. *-commutative87.1%

      \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  3. Applied egg-rr87.1%

    \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  4. Taylor expanded in x.re around 0 65.9%

    \[\leadsto \color{blue}{-1 \cdot {x.im}^{3}} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  5. Simplified27.4%

    \[\leadsto \color{blue}{-3} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  6. Step-by-step derivation
    1. expm1-log1p-u66.4%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)\right)} \]
    2. expm1-udef56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \color{blue}{\left(e^{\mathsf{log1p}\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\right)} - 1\right)} \]
    3. *-commutative56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(\color{blue}{x.re \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}\right)} - 1\right) \]
    4. *-commutative56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right)\right)} - 1\right) \]
    5. count-256.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
    6. *-commutative56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
    7. associate-*r*56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot \left(x.im \cdot 2\right)\right)}\right)} - 1\right) \]
    8. associate-*r*56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(\left(x.re \cdot x.im\right) \cdot 2\right)}\right)} - 1\right) \]
    9. *-commutative56.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)}\right)} - 1\right) \]
    10. count-256.6%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)} - 1\right) \]
    11. flip-+0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \color{blue}{\frac{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right) - \left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}{x.re \cdot x.im - x.re \cdot x.im}}\right)} - 1\right) \]
    12. +-inverses0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im}\right)} - 1\right) \]
    13. +-inverses0.0%

      \[\leadsto \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) \cdot x.im + \left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{\color{blue}{0}}\right)} - 1\right) \]
  7. Applied egg-rr0.0%

    \[\leadsto -3 + \color{blue}{\left(e^{\mathsf{log1p}\left(x.re \cdot \frac{0}{0}\right)} - 1\right)} \]
  8. Simplified2.6%

    \[\leadsto -3 + \color{blue}{0} \]
  9. Final simplification2.6%

    \[\leadsto -3 \]

Developer target: 92.0% accurate, 1.1× speedup?

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

\\
\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)
\end{array}

Reproduce

?
herbie shell --seed 2023318 
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"
  :precision binary64

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))