math.cube on complex, real part

Percentage Accurate: 82.8% → 96.8%
Time: 6.9s
Alternatives: 7
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
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_re) - (((x_46_re * x_46_im) + (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_46re) - (x_46im * x_46im)) * x_46re) - (((x_46re * x_46im) + (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_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im)
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_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
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$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

\[\begin{array}{l} \\ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
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_re) - (((x_46_re * x_46_im) + (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_46re) - (x_46im * x_46im)) * x_46re) - (((x_46re * x_46im) + (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_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im)
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_re) - Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_im))
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_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
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$re), $MachinePrecision] - N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 96.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(x.re \cdot x.re, x.re, \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re}^{3}\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<=
      (-
       (* x.re (- (* x.re x.re) (* x.im x.im)))
       (* x.im (+ (* x.re x.im) (* x.re x.im))))
      INFINITY)
   (fma (* x.re x.re) x.re (* (* x.re x.im) (* x.im -3.0)))
   (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (((x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= ((double) INFINITY)) {
		tmp = fma((x_46_re * x_46_re), x_46_re, ((x_46_re * x_46_im) * (x_46_im * -3.0)));
	} else {
		tmp = pow(x_46_re, 3.0);
	}
	return tmp;
}
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) - Float64(x_46_im * Float64(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im)))) <= Inf)
		tmp = fma(Float64(x_46_re * x_46_re), x_46_re, Float64(Float64(x_46_re * x_46_im) * Float64(x_46_im * -3.0)));
	else
		tmp = x_46_re ^ 3.0;
	end
	return tmp
end
code[x$46$re_, x$46$im_] := If[LessEqual[N[(N[(x$46$re * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(x$46$re * x$46$re), $MachinePrecision] * x$46$re + N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$46$re, 3.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(x.re \cdot x.re, x.re, \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\right)\\

\mathbf{else}:\\
\;\;\;\;{x.re}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) < +inf.0

    1. Initial program 92.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re \cdot x.re, x.re, \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\right)} \]

    if +inf.0 < (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im))

    1. Initial program 0.0%

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

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

      \[\leadsto \color{blue}{{x.re}^{3}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(x.re \cdot x.re, x.re, \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re}^{3}\\ \end{array} \]

Alternative 2: 96.8% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\ \;\;\;\;\left(x.re + x.im\right) \cdot \left(x.re \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re}^{3}\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<=
      (-
       (* x.re (- (* x.re x.re) (* x.im x.im)))
       (* x.im (+ (* x.re x.im) (* x.re x.im))))
      INFINITY)
   (- (* (+ x.re x.im) (* x.re (- x.re x.im))) (* x.im (* x.re (+ x.im x.im))))
   (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (((x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= ((double) INFINITY)) {
		tmp = ((x_46_re + x_46_im) * (x_46_re * (x_46_re - x_46_im))) - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
	} else {
		tmp = pow(x_46_re, 3.0);
	}
	return tmp;
}
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if (((x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= Double.POSITIVE_INFINITY) {
		tmp = ((x_46_re + x_46_im) * (x_46_re * (x_46_re - x_46_im))) - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
	} else {
		tmp = Math.pow(x_46_re, 3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if ((x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= math.inf:
		tmp = ((x_46_re + x_46_im) * (x_46_re * (x_46_re - x_46_im))) - (x_46_im * (x_46_re * (x_46_im + x_46_im)))
	else:
		tmp = math.pow(x_46_re, 3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) - Float64(x_46_im * Float64(Float64(x_46_re * x_46_im) + Float64(x_46_re * x_46_im)))) <= Inf)
		tmp = Float64(Float64(Float64(x_46_re + x_46_im) * Float64(x_46_re * Float64(x_46_re - x_46_im))) - Float64(x_46_im * Float64(x_46_re * Float64(x_46_im + x_46_im))));
	else
		tmp = 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_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)))) <= Inf)
		tmp = ((x_46_re + x_46_im) * (x_46_re * (x_46_re - x_46_im))) - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
	else
		tmp = x_46_re ^ 3.0;
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[LessEqual[N[(N[(x$46$re * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(N[(x$46$re + x$46$im), $MachinePrecision] * N[(x$46$re * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(x$46$re * N[(x$46$im + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$46$re, 3.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right) \leq \infty:\\
\;\;\;\;\left(x.re + x.im\right) \cdot \left(x.re \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;{x.re}^{3}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) < +inf.0

    1. Initial program 92.8%

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

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

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

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

        \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re - \left(-x.im\right)\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      5. sub-neg99.7%

        \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      6. remove-double-neg99.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
    4. Step-by-step derivation
      1. cancel-sign-sub-inv99.7%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{\left(x.re + x.im\right) \cdot x.re}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
      2. add-cube-cbrt99.2%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{\left(\sqrt[3]{\left(x.re + x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re + x.im\right) \cdot x.re}\right) \cdot \sqrt[3]{\left(x.re + x.im\right) \cdot x.re}}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
      3. pow399.2%

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

        \[\leadsto \mathsf{fma}\left(x.re - x.im, {\left(\sqrt[3]{\color{blue}{x.re \cdot \left(x.re + x.im\right)}}\right)}^{3}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    7. Applied egg-rr99.2%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{{\left(\sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right)}^{3}}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    8. Step-by-step derivation
      1. fma-udef99.2%

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

        \[\leadsto \left(x.re - x.im\right) \cdot \color{blue}{\left(\left(\sqrt[3]{x.re \cdot \left(x.re + x.im\right)} \cdot \sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right) \cdot \sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right)} + \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
      3. add-cube-cbrt99.7%

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

      \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(x.re \cdot \left(x.re + x.im\right)\right) + \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
    10. Step-by-step derivation
      1. distribute-lft-neg-out99.7%

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

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

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

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

        \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re \cdot \left(x.re - x.im\right)\right)} - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
    11. Simplified99.7%

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

    if +inf.0 < (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im))

    1. Initial program 0.0%

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

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

      \[\leadsto \color{blue}{{x.re}^{3}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.6%

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

Alternative 3: 84.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.re \leq -1.9 \cdot 10^{-94} \lor \neg \left(x.re \leq 2.45 \cdot 10^{-67}\right):\\ \;\;\;\;\left(x.re - x.im\right) \cdot \left(x.re \cdot \left(x.re + x.im\right)\right) - x.re \cdot \left(x.im \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(\left(x.re \cdot x.im\right) \cdot -3\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.re -1.9e-94) (not (<= x.re 2.45e-67)))
   (- (* (- x.re x.im) (* x.re (+ x.re x.im))) (* x.re (* x.im x.im)))
   (* x.im (* (* x.re x.im) -3.0))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_re <= -1.9e-94) || !(x_46_re <= 2.45e-67)) {
		tmp = ((x_46_re - x_46_im) * (x_46_re * (x_46_re + x_46_im))) - (x_46_re * (x_46_im * x_46_im));
	} else {
		tmp = x_46_im * ((x_46_re * 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_46re <= (-1.9d-94)) .or. (.not. (x_46re <= 2.45d-67))) then
        tmp = ((x_46re - x_46im) * (x_46re * (x_46re + x_46im))) - (x_46re * (x_46im * x_46im))
    else
        tmp = x_46im * ((x_46re * 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_re <= -1.9e-94) || !(x_46_re <= 2.45e-67)) {
		tmp = ((x_46_re - x_46_im) * (x_46_re * (x_46_re + x_46_im))) - (x_46_re * (x_46_im * x_46_im));
	} else {
		tmp = x_46_im * ((x_46_re * x_46_im) * -3.0);
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_re <= -1.9e-94) or not (x_46_re <= 2.45e-67):
		tmp = ((x_46_re - x_46_im) * (x_46_re * (x_46_re + x_46_im))) - (x_46_re * (x_46_im * x_46_im))
	else:
		tmp = x_46_im * ((x_46_re * x_46_im) * -3.0)
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_re <= -1.9e-94) || !(x_46_re <= 2.45e-67))
		tmp = Float64(Float64(Float64(x_46_re - x_46_im) * Float64(x_46_re * Float64(x_46_re + x_46_im))) - Float64(x_46_re * Float64(x_46_im * x_46_im)));
	else
		tmp = Float64(x_46_im * Float64(Float64(x_46_re * 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_re <= -1.9e-94) || ~((x_46_re <= 2.45e-67)))
		tmp = ((x_46_re - x_46_im) * (x_46_re * (x_46_re + x_46_im))) - (x_46_re * (x_46_im * x_46_im));
	else
		tmp = x_46_im * ((x_46_re * x_46_im) * -3.0);
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$re, -1.9e-94], N[Not[LessEqual[x$46$re, 2.45e-67]], $MachinePrecision]], N[(N[(N[(x$46$re - x$46$im), $MachinePrecision] * N[(x$46$re * N[(x$46$re + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$re * N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(N[(x$46$re * x$46$im), $MachinePrecision] * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.re < -1.9e-94 or 2.44999999999999997e-67 < x.re

    1. Initial program 81.5%

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

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

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

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

        \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re - \left(-x.im\right)\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      5. sub-neg86.9%

        \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      6. remove-double-neg86.9%

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

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

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

        \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.re + \color{blue}{x.im \cdot x.re}\right) \]
      10. distribute-rgt-out86.9%

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

      \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
    4. Step-by-step derivation
      1. distribute-lft-in86.9%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right) \]
      2. add-cube-cbrt86.9%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(\color{blue}{\left(\sqrt[3]{x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im}} + x.re \cdot x.im\right)\right) \]
      3. fma-def86.9%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \color{blue}{\mathsf{fma}\left(\sqrt[3]{x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)}\right) \]
      4. pow286.9%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{x.re \cdot x.im}\right)}^{2}}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)\right) \]
    5. Applied egg-rr86.8%

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{x.re \cdot x.im}\right)}^{2}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)} \]
    6. Taylor expanded in x.im around 0 77.2%

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - \color{blue}{{x.im}^{2} \cdot x.re} \]
    7. Step-by-step derivation
      1. *-commutative77.2%

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

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

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

    if -1.9e-94 < x.re < 2.44999999999999997e-67

    1. Initial program 83.6%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    2. Step-by-step derivation
      1. sqr-neg83.6%

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

        \[\leadsto \color{blue}{\left(\left(x.re + \left(-x.im\right)\right) \cdot \left(x.re - \left(-x.im\right)\right)\right)} \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      3. sub-neg83.6%

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

        \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re - \left(-x.im\right)\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      5. sub-neg99.7%

        \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      6. remove-double-neg99.7%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
    4. Step-by-step derivation
      1. cancel-sign-sub-inv99.7%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, \left(x.re + x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
      3. *-commutative99.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
    6. Taylor expanded in x.re around 0 81.9%

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

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

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

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

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

      \[\leadsto \color{blue}{-3 \cdot \left({x.im}^{2} \cdot x.re\right)} \]
    10. Step-by-step derivation
      1. *-commutative81.8%

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

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

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

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

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

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

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

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

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

Alternative 4: 87.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \leq 8 \cdot 10^{+87}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.im \cdot x.im\right) \cdot \left(x.re \cdot -2\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.im \cdot -3\right)\right)\\ \end{array} \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (if (<= x.im 8e+87)
   (+ (* x.re (- (* x.re x.re) (* x.im x.im))) (* (* x.im x.im) (* x.re -2.0)))
   (* x.im (* x.re (* x.im -3.0)))))
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (x_46_im <= 8e+87) {
		tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + ((x_46_im * x_46_im) * (x_46_re * -2.0));
	} else {
		tmp = x_46_im * (x_46_re * (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 <= 8d+87) then
        tmp = (x_46re * ((x_46re * x_46re) - (x_46im * x_46im))) + ((x_46im * x_46im) * (x_46re * (-2.0d0)))
    else
        tmp = x_46im * (x_46re * (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 <= 8e+87) {
		tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + ((x_46_im * x_46_im) * (x_46_re * -2.0));
	} else {
		tmp = x_46_im * (x_46_re * (x_46_im * -3.0));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	tmp = 0
	if x_46_im <= 8e+87:
		tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + ((x_46_im * x_46_im) * (x_46_re * -2.0))
	else:
		tmp = x_46_im * (x_46_re * (x_46_im * -3.0))
	return tmp
function code(x_46_re, x_46_im)
	tmp = 0.0
	if (x_46_im <= 8e+87)
		tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))) + Float64(Float64(x_46_im * x_46_im) * Float64(x_46_re * -2.0)));
	else
		tmp = Float64(x_46_im * Float64(x_46_re * Float64(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 <= 8e+87)
		tmp = (x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) + ((x_46_im * x_46_im) * (x_46_re * -2.0));
	else
		tmp = x_46_im * (x_46_re * (x_46_im * -3.0));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := If[LessEqual[x$46$im, 8e+87], N[(N[(x$46$re * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(x$46$im * x$46$im), $MachinePrecision] * N[(x$46$re * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(x$46$re * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq 8 \cdot 10^{+87}:\\
\;\;\;\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.im \cdot x.im\right) \cdot \left(x.re \cdot -2\right)\\

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


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

    1. Initial program 87.8%

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, \left(-x.re\right) \cdot \left(-x.re\right) - x.im \cdot x.im, -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)} \]
      4. sqr-neg87.8%

        \[\leadsto \mathsf{fma}\left(x.re, \color{blue}{x.re \cdot x.re} - x.im \cdot x.im, -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right) \]
      5. +-commutative87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -\color{blue}{\left(x.im \cdot x.re + x.re \cdot x.im\right)} \cdot x.im\right) \]
      6. *-commutative87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -\color{blue}{x.im \cdot \left(x.im \cdot x.re + x.re \cdot x.im\right)}\right) \]
      7. *-commutative87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -x.im \cdot \left(x.im \cdot x.re + \color{blue}{x.im \cdot x.re}\right)\right) \]
      8. distribute-lft-out87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -x.im \cdot \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)}\right) \]
      9. associate-*r*87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, -\color{blue}{\left(x.im \cdot x.im\right) \cdot \left(x.re + x.re\right)}\right) \]
      10. distribute-rgt-neg-in87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \color{blue}{\left(x.im \cdot x.im\right) \cdot \left(-\left(x.re + x.re\right)\right)}\right) \]
      11. distribute-neg-out87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \color{blue}{\left(\left(-x.re\right) + \left(-x.re\right)\right)}\right) \]
      12. neg-mul-187.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \left(\color{blue}{-1 \cdot x.re} + \left(-x.re\right)\right)\right) \]
      13. neg-mul-187.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \left(-1 \cdot x.re + \color{blue}{-1 \cdot x.re}\right)\right) \]
      14. distribute-rgt-out87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \color{blue}{\left(x.re \cdot \left(-1 + -1\right)\right)}\right) \]
      15. metadata-eval87.8%

        \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \left(x.re \cdot \color{blue}{-2}\right)\right) \]
    3. Simplified87.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, \left(x.im \cdot x.im\right) \cdot \left(x.re \cdot -2\right)\right)} \]
    4. Step-by-step derivation
      1. fma-udef87.8%

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

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

    if 7.9999999999999997e87 < x.im

    1. Initial program 55.4%

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

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

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

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

        \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re - \left(-x.im\right)\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      5. sub-neg81.4%

        \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      6. remove-double-neg81.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
    4. Step-by-step derivation
      1. cancel-sign-sub-inv81.4%

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, \left(x.re + x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
      3. *-commutative81.6%

        \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{x.re \cdot \left(x.re + x.im\right)}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    5. Applied egg-rr81.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
    6. Taylor expanded in x.re around 0 64.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 91.8% accurate, 1.1× speedup?

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

\\
\left(x.re + x.im\right) \cdot \left(x.re \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)
\end{array}
Derivation
  1. Initial program 82.2%

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

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

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    6. remove-double-neg91.5%

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.re + \color{blue}{x.im \cdot x.re}\right) \]
    10. distribute-rgt-out91.5%

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

    \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
  4. Step-by-step derivation
    1. cancel-sign-sub-inv91.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, \left(x.re + x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
    3. *-commutative91.6%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{x.re \cdot \left(x.re + x.im\right)}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
  5. Applied egg-rr91.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
  6. Step-by-step derivation
    1. *-commutative91.6%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{\left(x.re + x.im\right) \cdot x.re}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    2. add-cube-cbrt91.1%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{\left(\sqrt[3]{\left(x.re + x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re + x.im\right) \cdot x.re}\right) \cdot \sqrt[3]{\left(x.re + x.im\right) \cdot x.re}}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    3. pow391.1%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{{\left(\sqrt[3]{\left(x.re + x.im\right) \cdot x.re}\right)}^{3}}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
    4. *-commutative91.1%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, {\left(\sqrt[3]{\color{blue}{x.re \cdot \left(x.re + x.im\right)}}\right)}^{3}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
  7. Applied egg-rr91.1%

    \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{{\left(\sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right)}^{3}}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
  8. Step-by-step derivation
    1. fma-udef91.1%

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

      \[\leadsto \left(x.re - x.im\right) \cdot \color{blue}{\left(\left(\sqrt[3]{x.re \cdot \left(x.re + x.im\right)} \cdot \sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right) \cdot \sqrt[3]{x.re \cdot \left(x.re + x.im\right)}\right)} + \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
    3. add-cube-cbrt91.5%

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

    \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(x.re \cdot \left(x.re + x.im\right)\right) + \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
  10. Step-by-step derivation
    1. distribute-lft-neg-out91.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\left(x.re + x.im\right) \cdot \left(x.re \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
  12. Final simplification91.5%

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

Alternative 6: 36.1% accurate, 2.7× speedup?

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

\\
-2 \cdot \left(x.im \cdot \left(x.re \cdot x.im\right)\right)
\end{array}
Derivation
  1. Initial program 82.2%

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

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

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    6. remove-double-neg91.5%

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.re + \color{blue}{x.im \cdot x.re}\right) \]
    10. distribute-rgt-out91.5%

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

    \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
  4. Step-by-step derivation
    1. cancel-sign-sub-inv91.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, \left(x.re + x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
    3. *-commutative91.6%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{x.re \cdot \left(x.re + x.im\right)}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
  5. Applied egg-rr91.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
  6. Step-by-step derivation
    1. distribute-lft-in91.6%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \color{blue}{\left(x.re \cdot x.im + x.re \cdot x.im\right)}\right) \]
    2. add-cube-cbrt91.4%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(\color{blue}{\left(\sqrt[3]{x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im}} + x.re \cdot x.im\right)\right) \]
    3. fma-def91.4%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \color{blue}{\mathsf{fma}\left(\sqrt[3]{x.re \cdot x.im} \cdot \sqrt[3]{x.re \cdot x.im}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)}\right) \]
    4. pow291.4%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \mathsf{fma}\left(\color{blue}{{\left(\sqrt[3]{x.re \cdot x.im}\right)}^{2}}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)\right) \]
  7. Applied egg-rr91.4%

    \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \color{blue}{\mathsf{fma}\left({\left(\sqrt[3]{x.re \cdot x.im}\right)}^{2}, \sqrt[3]{x.re \cdot x.im}, x.re \cdot x.im\right)}\right) \]
  8. Taylor expanded in x.re around 0 31.6%

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

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

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

    \[\leadsto \color{blue}{-2 \cdot \left(x.im \cdot \left(x.im \cdot x.re\right)\right)} \]
  11. Final simplification32.5%

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

Alternative 7: 56.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ x.im \cdot \left(\left(x.re \cdot x.im\right) \cdot -3\right) \end{array} \]
(FPCore (x.re x.im) :precision binary64 (* x.im (* (* x.re x.im) -3.0)))
double code(double x_46_re, double x_46_im) {
	return x_46_im * ((x_46_re * x_46_im) * -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_46im) * (-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_im) * -3.0);
}
def code(x_46_re, x_46_im):
	return x_46_im * ((x_46_re * x_46_im) * -3.0)
function code(x_46_re, x_46_im)
	return Float64(x_46_im * Float64(Float64(x_46_re * x_46_im) * -3.0))
end
function tmp = code(x_46_re, x_46_im)
	tmp = x_46_im * ((x_46_re * x_46_im) * -3.0);
end
code[x$46$re_, x$46$im_] := N[(x$46$im * N[(N[(x$46$re * x$46$im), $MachinePrecision] * -3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\color{blue}{\left(x.re + \left(-\left(-x.im\right)\right)\right)} \cdot x.re\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    6. remove-double-neg91.5%

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

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

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

      \[\leadsto \left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.im \cdot x.re + \color{blue}{x.im \cdot x.re}\right) \]
    10. distribute-rgt-out91.5%

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

    \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(\left(x.re + x.im\right) \cdot x.re\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)} \]
  4. Step-by-step derivation
    1. cancel-sign-sub-inv91.5%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, \left(x.re + x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
    3. *-commutative91.6%

      \[\leadsto \mathsf{fma}\left(x.re - x.im, \color{blue}{x.re \cdot \left(x.re + x.im\right)}, \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right) \]
  5. Applied egg-rr91.6%

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)} \]
  6. Taylor expanded in x.re around 0 47.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto x.im \cdot \color{blue}{\left(-3 \cdot \left(x.im \cdot x.re\right)\right)} \]
  13. Final simplification53.6%

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

Developer target: 87.5% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \left(x.re \cdot x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re \cdot x.im\right) \cdot \left(x.re - 3 \cdot x.im\right) \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+ (* (* x.re x.re) (- x.re x.im)) (* (* x.re x.im) (- x.re (* 3.0 x.im)))))
double code(double x_46_re, double x_46_im) {
	return ((x_46_re * x_46_re) * (x_46_re - x_46_im)) + ((x_46_re * x_46_im) * (x_46_re - (3.0 * 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_46re) * (x_46re - x_46im)) + ((x_46re * x_46im) * (x_46re - (3.0d0 * x_46im)))
end function
public static double code(double x_46_re, double x_46_im) {
	return ((x_46_re * x_46_re) * (x_46_re - x_46_im)) + ((x_46_re * x_46_im) * (x_46_re - (3.0 * x_46_im)));
}
def code(x_46_re, x_46_im):
	return ((x_46_re * x_46_re) * (x_46_re - x_46_im)) + ((x_46_re * x_46_im) * (x_46_re - (3.0 * x_46_im)))
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(x_46_re * x_46_re) * Float64(x_46_re - x_46_im)) + Float64(Float64(x_46_re * x_46_im) * Float64(x_46_re - Float64(3.0 * x_46_im))))
end
function tmp = code(x_46_re, x_46_im)
	tmp = ((x_46_re * x_46_re) * (x_46_re - x_46_im)) + ((x_46_re * x_46_im) * (x_46_re - (3.0 * x_46_im)));
end
code[x$46$re_, x$46$im_] := N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] * N[(x$46$re - x$46$im), $MachinePrecision]), $MachinePrecision] + N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$re - N[(3.0 * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Reproduce

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

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

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