math.cube on complex, imaginary part

Percentage Accurate: 82.4% → 96.4%
Time: 6.1s
Alternatives: 4
Speedup: 0.5×

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 4 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.4% 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: 96.4% accurate, 0.5× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ \begin{array}{l} t_0 := x.re\_m \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\ \mathbf{if}\;x.im \cdot \left(x.re\_m \cdot x.re\_m - x.im \cdot x.im\right) + t\_0 \leq \infty:\\ \;\;\;\;t\_0 + \left(x.im \cdot \left(x.re\_m + x.im\right)\right) \cdot \left(x.re\_m - x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
(FPCore (x.re_m x.im)
 :precision binary64
 (let* ((t_0 (* x.re_m (+ (* x.re_m x.im) (* x.re_m x.im)))))
   (if (<= (+ (* x.im (- (* x.re_m x.re_m) (* x.im x.im))) t_0) INFINITY)
     (+ t_0 (* (* x.im (+ x.re_m x.im)) (- x.re_m x.im)))
     (* x.im (* x.re_m (* x.re_m -3.0))))))
x.re_m = fabs(x_46_re);
double code(double x_46_re_m, double x_46_im) {
	double t_0 = x_46_re_m * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	double tmp;
	if (((x_46_im * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) + t_0) <= ((double) INFINITY)) {
		tmp = t_0 + ((x_46_im * (x_46_re_m + x_46_im)) * (x_46_re_m - x_46_im));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = Math.abs(x_46_re);
public static double code(double x_46_re_m, double x_46_im) {
	double t_0 = x_46_re_m * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	double tmp;
	if (((x_46_im * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) + t_0) <= Double.POSITIVE_INFINITY) {
		tmp = t_0 + ((x_46_im * (x_46_re_m + x_46_im)) * (x_46_re_m - x_46_im));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = math.fabs(x_46_re)
def code(x_46_re_m, x_46_im):
	t_0 = x_46_re_m * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im))
	tmp = 0
	if ((x_46_im * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) + t_0) <= math.inf:
		tmp = t_0 + ((x_46_im * (x_46_re_m + x_46_im)) * (x_46_re_m - x_46_im))
	else:
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0))
	return tmp
x.re_m = abs(x_46_re)
function code(x_46_re_m, x_46_im)
	t_0 = Float64(x_46_re_m * Float64(Float64(x_46_re_m * x_46_im) + Float64(x_46_re_m * x_46_im)))
	tmp = 0.0
	if (Float64(Float64(x_46_im * Float64(Float64(x_46_re_m * x_46_re_m) - Float64(x_46_im * x_46_im))) + t_0) <= Inf)
		tmp = Float64(t_0 + Float64(Float64(x_46_im * Float64(x_46_re_m + x_46_im)) * Float64(x_46_re_m - x_46_im)));
	else
		tmp = Float64(x_46_im * Float64(x_46_re_m * Float64(x_46_re_m * -3.0)));
	end
	return tmp
end
x.re_m = abs(x_46_re);
function tmp_2 = code(x_46_re_m, x_46_im)
	t_0 = x_46_re_m * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	tmp = 0.0;
	if (((x_46_im * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) + t_0) <= Inf)
		tmp = t_0 + ((x_46_im * (x_46_re_m + x_46_im)) * (x_46_re_m - x_46_im));
	else
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	end
	tmp_2 = tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
code[x$46$re$95$m_, x$46$im_] := Block[{t$95$0 = N[(x$46$re$95$m * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] + N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(x$46$im * N[(N[(x$46$re$95$m * x$46$re$95$m), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], Infinity], N[(t$95$0 + N[(N[(x$46$im * N[(x$46$re$95$m + x$46$im), $MachinePrecision]), $MachinePrecision] * N[(x$46$re$95$m - x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(x$46$re$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x.re_m = \left|x.re\right|

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

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


\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.im) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.re)) < +inf.0

    1. Initial program 94.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. Add Preprocessing
    3. Step-by-step derivation
      1. *-commutative94.8%

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

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

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

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

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

    1. Initial program 0.0%

      \[\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. Simplified0.0%

      \[\leadsto \color{blue}{x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. *-commutative0.0%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x.im \cdot \color{blue}{\left(-3 \cdot \left(-1 \cdot {x.re}^{2}\right)\right)} \]
      3. neg-mul-118.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x.im \cdot \left(\left(-3 \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.re} \cdot \sqrt{x.re}\right)}\right) \]
      21. add-sqr-sqrt81.8%

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

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

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

Alternative 2: 57.8% accurate, 1.6× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ \begin{array}{l} \mathbf{if}\;x.im \leq 3.3 \cdot 10^{+126}:\\ \;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
(FPCore (x.re_m x.im)
 :precision binary64
 (if (<= x.im 3.3e+126)
   (* x.re_m (* x.re_m (* x.im 3.0)))
   (* x.im (* x.re_m (* x.re_m -3.0)))))
x.re_m = fabs(x_46_re);
double code(double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_im <= 3.3e+126) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im * 3.0));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = abs(x_46re)
real(8) function code(x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if (x_46im <= 3.3d+126) then
        tmp = x_46re_m * (x_46re_m * (x_46im * 3.0d0))
    else
        tmp = x_46im * (x_46re_m * (x_46re_m * (-3.0d0)))
    end if
    code = tmp
end function
x.re_m = Math.abs(x_46_re);
public static double code(double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_im <= 3.3e+126) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im * 3.0));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = math.fabs(x_46_re)
def code(x_46_re_m, x_46_im):
	tmp = 0
	if x_46_im <= 3.3e+126:
		tmp = x_46_re_m * (x_46_re_m * (x_46_im * 3.0))
	else:
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0))
	return tmp
x.re_m = abs(x_46_re)
function code(x_46_re_m, x_46_im)
	tmp = 0.0
	if (x_46_im <= 3.3e+126)
		tmp = Float64(x_46_re_m * Float64(x_46_re_m * Float64(x_46_im * 3.0)));
	else
		tmp = Float64(x_46_im * Float64(x_46_re_m * Float64(x_46_re_m * -3.0)));
	end
	return tmp
end
x.re_m = abs(x_46_re);
function tmp_2 = code(x_46_re_m, x_46_im)
	tmp = 0.0;
	if (x_46_im <= 3.3e+126)
		tmp = x_46_re_m * (x_46_re_m * (x_46_im * 3.0));
	else
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	end
	tmp_2 = tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
code[x$46$re$95$m_, x$46$im_] := If[LessEqual[x$46$im, 3.3e+126], N[(x$46$re$95$m * N[(x$46$re$95$m * N[(x$46$im * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(x$46$re$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x.re_m = \left|x.re\right|

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq 3.3 \cdot 10^{+126}:\\
\;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im \cdot 3\right)\right)\\

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


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

    1. Initial program 87.0%

      \[\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. Simplified91.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \cdot x.re\right) \cdot x.re} \]
    10. Applied egg-rr60.0%

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

    if 3.30000000000000013e126 < x.im

    1. Initial program 56.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. Simplified56.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x.im \cdot \color{blue}{\left(-3 \cdot \left(-1 \cdot {x.re}^{2}\right)\right)} \]
      3. neg-mul-111.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 52.1% accurate, 1.6× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ \begin{array}{l} \mathbf{if}\;x.im \leq 3 \cdot 10^{+126}:\\ \;\;\;\;x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
(FPCore (x.re_m x.im)
 :precision binary64
 (if (<= x.im 3e+126)
   (* x.im (* x.re_m (* x.re_m 3.0)))
   (* x.im (* x.re_m (* x.re_m -3.0)))))
x.re_m = fabs(x_46_re);
double code(double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_im <= 3e+126) {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * 3.0));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = abs(x_46re)
real(8) function code(x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if (x_46im <= 3d+126) then
        tmp = x_46im * (x_46re_m * (x_46re_m * 3.0d0))
    else
        tmp = x_46im * (x_46re_m * (x_46re_m * (-3.0d0)))
    end if
    code = tmp
end function
x.re_m = Math.abs(x_46_re);
public static double code(double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_im <= 3e+126) {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * 3.0));
	} else {
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	}
	return tmp;
}
x.re_m = math.fabs(x_46_re)
def code(x_46_re_m, x_46_im):
	tmp = 0
	if x_46_im <= 3e+126:
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * 3.0))
	else:
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0))
	return tmp
x.re_m = abs(x_46_re)
function code(x_46_re_m, x_46_im)
	tmp = 0.0
	if (x_46_im <= 3e+126)
		tmp = Float64(x_46_im * Float64(x_46_re_m * Float64(x_46_re_m * 3.0)));
	else
		tmp = Float64(x_46_im * Float64(x_46_re_m * Float64(x_46_re_m * -3.0)));
	end
	return tmp
end
x.re_m = abs(x_46_re);
function tmp_2 = code(x_46_re_m, x_46_im)
	tmp = 0.0;
	if (x_46_im <= 3e+126)
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * 3.0));
	else
		tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
	end
	tmp_2 = tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
code[x$46$re$95$m_, x$46$im_] := If[LessEqual[x$46$im, 3e+126], N[(x$46$im * N[(x$46$re$95$m * N[(x$46$re$95$m * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im * N[(x$46$re$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x.re_m = \left|x.re\right|

\\
\begin{array}{l}
\mathbf{if}\;x.im \leq 3 \cdot 10^{+126}:\\
\;\;\;\;x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot 3\right)\right)\\

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


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

    1. Initial program 87.0%

      \[\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. Simplified91.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.0000000000000002e126 < x.im

    1. Initial program 56.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. Simplified56.8%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto x.im \cdot \color{blue}{\left(-3 \cdot \left(-1 \cdot {x.re}^{2}\right)\right)} \]
      3. neg-mul-111.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 24.3% accurate, 2.7× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot -3\right)\right) \end{array} \]
x.re_m = (fabs.f64 x.re)
(FPCore (x.re_m x.im) :precision binary64 (* x.im (* x.re_m (* x.re_m -3.0))))
x.re_m = fabs(x_46_re);
double code(double x_46_re_m, double x_46_im) {
	return x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
}
x.re_m = abs(x_46re)
real(8) function code(x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    code = x_46im * (x_46re_m * (x_46re_m * (-3.0d0)))
end function
x.re_m = Math.abs(x_46_re);
public static double code(double x_46_re_m, double x_46_im) {
	return x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
}
x.re_m = math.fabs(x_46_re)
def code(x_46_re_m, x_46_im):
	return x_46_im * (x_46_re_m * (x_46_re_m * -3.0))
x.re_m = abs(x_46_re)
function code(x_46_re_m, x_46_im)
	return Float64(x_46_im * Float64(x_46_re_m * Float64(x_46_re_m * -3.0)))
end
x.re_m = abs(x_46_re);
function tmp = code(x_46_re_m, x_46_im)
	tmp = x_46_im * (x_46_re_m * (x_46_re_m * -3.0));
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
code[x$46$re$95$m_, x$46$im_] := N[(x$46$im * N[(x$46$re$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.re_m = \left|x.re\right|

\\
x.im \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot -3\right)\right)
\end{array}
Derivation
  1. Initial program 82.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. Simplified86.2%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x.im \cdot \color{blue}{\left(-3 \cdot \left(-1 \cdot {x.re}^{2}\right)\right)} \]
    3. neg-mul-148.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x.im \cdot \left(\left(-3 \cdot x.re\right) \cdot \color{blue}{\left(\sqrt{x.re} \cdot \sqrt{x.re}\right)}\right) \]
    21. add-sqr-sqrt25.0%

      \[\leadsto x.im \cdot \left(\left(-3 \cdot x.re\right) \cdot \color{blue}{x.re}\right) \]
  10. Applied egg-rr25.0%

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

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

Developer target: 91.4% 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 2024096 
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"
  :precision binary64

  :alt
  (+ (* (* 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)))