math.cube on complex, real part

Percentage Accurate: 82.6% → 96.3%
Time: 6.6s
Alternatives: 6
Speedup: 0.5×

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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 82.6% 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.3% accurate, 0.1× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \begin{array}{l} \mathbf{if}\;x.re\_m \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;\mathsf{fma}\left(x.re\_m \cdot x.im, x.im \cdot -3, {x.re\_m}^{3}\right)\\ \mathbf{elif}\;x.re\_m \leq 9 \cdot 10^{+200}:\\ \;\;\;\;x.re\_m \cdot \left(\left(x.re\_m + x.im\right) \cdot \left(x.re\_m - x.im\right)\right) - x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re\_m}^{3}\\ \end{array} \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (*
  x.re_s
  (if (<= x.re_m 5.5e+102)
    (fma (* x.re_m x.im) (* x.im -3.0) (pow x.re_m 3.0))
    (if (<= x.re_m 9e+200)
      (-
       (* x.re_m (* (+ x.re_m x.im) (- x.re_m x.im)))
       (* x.im (+ (* x.re_m x.im) (* x.re_m x.im))))
      (pow x.re_m 3.0)))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_re_m <= 5.5e+102) {
		tmp = fma((x_46_re_m * x_46_im), (x_46_im * -3.0), pow(x_46_re_m, 3.0));
	} else if (x_46_re_m <= 9e+200) {
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)));
	} else {
		tmp = pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = 0.0
	if (x_46_re_m <= 5.5e+102)
		tmp = fma(Float64(x_46_re_m * x_46_im), Float64(x_46_im * -3.0), (x_46_re_m ^ 3.0));
	elseif (x_46_re_m <= 9e+200)
		tmp = Float64(Float64(x_46_re_m * Float64(Float64(x_46_re_m + x_46_im) * Float64(x_46_re_m - x_46_im))) - Float64(x_46_im * Float64(Float64(x_46_re_m * x_46_im) + Float64(x_46_re_m * x_46_im))));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	return Float64(x_46_re_s * tmp)
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := N[(x$46$re$95$s * If[LessEqual[x$46$re$95$m, 5.5e+102], N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision] + N[Power[x$46$re$95$m, 3.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re$95$m, 9e+200], N[(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] - N[(x$46$im * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] + N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$46$re$95$m, 3.0], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

\\
x.re\_s \cdot \begin{array}{l}
\mathbf{if}\;x.re\_m \leq 5.5 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(x.re\_m \cdot x.im, x.im \cdot -3, {x.re\_m}^{3}\right)\\

\mathbf{elif}\;x.re\_m \leq 9 \cdot 10^{+200}:\\
\;\;\;\;x.re\_m \cdot \left(\left(x.re\_m + x.im\right) \cdot \left(x.re\_m - x.im\right)\right) - x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.re < 5.49999999999999981e102

    1. Initial program 83.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. Simplified81.9%

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

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

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

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

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

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

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

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

    if 5.49999999999999981e102 < x.re < 8.99999999999999939e200

    1. Initial program 87.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares100.0%

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

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

    if 8.99999999999999939e200 < x.re

    1. Initial program 66.7%

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

        \[\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. *-commutative66.7%

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

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

        \[\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. *-commutative66.7%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x.re around inf 95.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right)\\ \mathbf{elif}\;x.re \leq 9 \cdot 10^{+200}:\\ \;\;\;\;x.re \cdot \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re}^{3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 96.6% accurate, 0.2× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \begin{array}{l} \mathbf{if}\;x.re\_m \cdot \left(x.re\_m \cdot x.re\_m - x.im \cdot x.im\right) - x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right) \leq -1 \cdot 10^{-320}:\\ \;\;\;\;\left(x.re\_m \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re\_m}^{3}\\ \end{array} \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (*
  x.re_s
  (if (<=
       (-
        (* x.re_m (- (* x.re_m x.re_m) (* x.im x.im)))
        (* x.im (+ (* x.re_m x.im) (* x.re_m x.im))))
       -1e-320)
    (* (* x.re_m x.im) (* x.im -3.0))
    (pow x.re_m 3.0))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double tmp;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)))) <= -1e-320) {
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	} else {
		tmp = pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.re\_m = abs(x_46re)
x.re\_s = copysign(1.0d0, x_46re)
real(8) function code(x_46re_s, x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if (((x_46re_m * ((x_46re_m * x_46re_m) - (x_46im * x_46im))) - (x_46im * ((x_46re_m * x_46im) + (x_46re_m * x_46im)))) <= (-1d-320)) then
        tmp = (x_46re_m * x_46im) * (x_46im * (-3.0d0))
    else
        tmp = x_46re_m ** 3.0d0
    end if
    code = x_46re_s * tmp
end function
x.re\_m = Math.abs(x_46_re);
x.re\_s = Math.copySign(1.0, x_46_re);
public static double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double tmp;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)))) <= -1e-320) {
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	} else {
		tmp = Math.pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.re\_m = math.fabs(x_46_re)
x.re\_s = math.copysign(1.0, x_46_re)
def code(x_46_re_s, x_46_re_m, x_46_im):
	tmp = 0
	if ((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)))) <= -1e-320:
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0)
	else:
		tmp = math.pow(x_46_re_m, 3.0)
	return x_46_re_s * tmp
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = 0.0
	if (Float64(Float64(x_46_re_m * Float64(Float64(x_46_re_m * x_46_re_m) - Float64(x_46_im * x_46_im))) - Float64(x_46_im * Float64(Float64(x_46_re_m * x_46_im) + Float64(x_46_re_m * x_46_im)))) <= -1e-320)
		tmp = Float64(Float64(x_46_re_m * x_46_im) * Float64(x_46_im * -3.0));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	return Float64(x_46_re_s * tmp)
end
x.re\_m = abs(x_46_re);
x.re\_s = sign(x_46_re) * abs(1.0);
function tmp_2 = code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = 0.0;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)))) <= -1e-320)
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	else
		tmp = x_46_re_m ^ 3.0;
	end
	tmp_2 = x_46_re_s * tmp;
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := N[(x$46$re$95$s * If[LessEqual[N[(N[(x$46$re$95$m * N[(N[(x$46$re$95$m * x$46$re$95$m), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] + N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1e-320], N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision], N[Power[x$46$re$95$m, 3.0], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

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

\mathbf{else}:\\
\;\;\;\;{x.re\_m}^{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)) < -9.99989e-321

    1. Initial program 91.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-neg91.6%

        \[\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. *-commutative91.6%

        \[\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-neg91.6%

        \[\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-neg91.6%

        \[\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. *-commutative91.6%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x.re around 0 38.2%

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

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

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

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

        \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)} \]
      4. add-exp-log25.1%

        \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)}} \cdot \left(x.im \cdot -3\right) \]
      5. add-exp-log0.4%

        \[\leadsto e^{\log \left(x.re \cdot x.im\right)} \cdot \color{blue}{e^{\log \left(x.im \cdot -3\right)}} \]
      6. prod-exp0.4%

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

      \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right) + \log \left(x.im \cdot -3\right)}} \]
    9. Step-by-step derivation
      1. exp-sum0.4%

        \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)} \cdot e^{\log \left(x.im \cdot -3\right)}} \]
      2. rem-exp-log19.0%

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

        \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot e^{\log \left(x.im \cdot -3\right)} \]
      4. rem-exp-log46.3%

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

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

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

    if -9.99989e-321 < (-.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 77.7%

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

        \[\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. *-commutative77.7%

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

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

        \[\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. *-commutative77.7%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x.re around inf 64.9%

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

    \[\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 -1 \cdot 10^{-320}:\\ \;\;\;\;\left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re}^{3}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 96.3% accurate, 0.2× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \begin{array}{l} \mathbf{if}\;x.re\_m \leq 5.5 \cdot 10^{+102}:\\ \;\;\;\;{x.re\_m}^{3} + x.im \cdot \left(-3 \cdot \left(x.re\_m \cdot x.im\right) + x.re\_m \cdot \left(x.re\_m - x.re\_m\right)\right)\\ \mathbf{elif}\;x.re\_m \leq 5.5 \cdot 10^{+200}:\\ \;\;\;\;x.re\_m \cdot \left(\left(x.re\_m + x.im\right) \cdot \left(x.re\_m - x.im\right)\right) - x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re\_m}^{3}\\ \end{array} \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (*
  x.re_s
  (if (<= x.re_m 5.5e+102)
    (+
     (pow x.re_m 3.0)
     (* x.im (+ (* -3.0 (* x.re_m x.im)) (* x.re_m (- x.re_m x.re_m)))))
    (if (<= x.re_m 5.5e+200)
      (-
       (* x.re_m (* (+ x.re_m x.im) (- x.re_m x.im)))
       (* x.im (+ (* x.re_m x.im) (* x.re_m x.im))))
      (pow x.re_m 3.0)))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_re_m <= 5.5e+102) {
		tmp = pow(x_46_re_m, 3.0) + (x_46_im * ((-3.0 * (x_46_re_m * x_46_im)) + (x_46_re_m * (x_46_re_m - x_46_re_m))));
	} else if (x_46_re_m <= 5.5e+200) {
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)));
	} else {
		tmp = pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.re\_m = abs(x_46re)
x.re\_s = copysign(1.0d0, x_46re)
real(8) function code(x_46re_s, x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if (x_46re_m <= 5.5d+102) then
        tmp = (x_46re_m ** 3.0d0) + (x_46im * (((-3.0d0) * (x_46re_m * x_46im)) + (x_46re_m * (x_46re_m - x_46re_m))))
    else if (x_46re_m <= 5.5d+200) then
        tmp = (x_46re_m * ((x_46re_m + x_46im) * (x_46re_m - x_46im))) - (x_46im * ((x_46re_m * x_46im) + (x_46re_m * x_46im)))
    else
        tmp = x_46re_m ** 3.0d0
    end if
    code = x_46re_s * tmp
end function
x.re\_m = Math.abs(x_46_re);
x.re\_s = Math.copySign(1.0, x_46_re);
public static double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double tmp;
	if (x_46_re_m <= 5.5e+102) {
		tmp = Math.pow(x_46_re_m, 3.0) + (x_46_im * ((-3.0 * (x_46_re_m * x_46_im)) + (x_46_re_m * (x_46_re_m - x_46_re_m))));
	} else if (x_46_re_m <= 5.5e+200) {
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)));
	} else {
		tmp = Math.pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.re\_m = math.fabs(x_46_re)
x.re\_s = math.copysign(1.0, x_46_re)
def code(x_46_re_s, x_46_re_m, x_46_im):
	tmp = 0
	if x_46_re_m <= 5.5e+102:
		tmp = math.pow(x_46_re_m, 3.0) + (x_46_im * ((-3.0 * (x_46_re_m * x_46_im)) + (x_46_re_m * (x_46_re_m - x_46_re_m))))
	elif x_46_re_m <= 5.5e+200:
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)))
	else:
		tmp = math.pow(x_46_re_m, 3.0)
	return x_46_re_s * tmp
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = 0.0
	if (x_46_re_m <= 5.5e+102)
		tmp = Float64((x_46_re_m ^ 3.0) + Float64(x_46_im * Float64(Float64(-3.0 * Float64(x_46_re_m * x_46_im)) + Float64(x_46_re_m * Float64(x_46_re_m - x_46_re_m)))));
	elseif (x_46_re_m <= 5.5e+200)
		tmp = Float64(Float64(x_46_re_m * Float64(Float64(x_46_re_m + x_46_im) * Float64(x_46_re_m - x_46_im))) - Float64(x_46_im * Float64(Float64(x_46_re_m * x_46_im) + Float64(x_46_re_m * x_46_im))));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	return Float64(x_46_re_s * tmp)
end
x.re\_m = abs(x_46_re);
x.re\_s = sign(x_46_re) * abs(1.0);
function tmp_2 = code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = 0.0;
	if (x_46_re_m <= 5.5e+102)
		tmp = (x_46_re_m ^ 3.0) + (x_46_im * ((-3.0 * (x_46_re_m * x_46_im)) + (x_46_re_m * (x_46_re_m - x_46_re_m))));
	elseif (x_46_re_m <= 5.5e+200)
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - (x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im)));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	tmp_2 = x_46_re_s * tmp;
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := N[(x$46$re$95$s * If[LessEqual[x$46$re$95$m, 5.5e+102], N[(N[Power[x$46$re$95$m, 3.0], $MachinePrecision] + N[(x$46$im * N[(N[(-3.0 * N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision] + N[(x$46$re$95$m * N[(x$46$re$95$m - x$46$re$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re$95$m, 5.5e+200], N[(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] - N[(x$46$im * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] + N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$46$re$95$m, 3.0], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

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

\mathbf{elif}\;x.re\_m \leq 5.5 \cdot 10^{+200}:\\
\;\;\;\;x.re\_m \cdot \left(\left(x.re\_m + x.im\right) \cdot \left(x.re\_m - x.im\right)\right) - x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x.re < 5.49999999999999981e102

    1. Initial program 83.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares85.2%

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

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

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

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

    if 5.49999999999999981e102 < x.re < 5.5e200

    1. Initial program 87.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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares100.0%

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

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

    if 5.5e200 < x.re

    1. Initial program 66.7%

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

        \[\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. *-commutative66.7%

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

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

        \[\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. *-commutative66.7%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x.re around inf 95.2%

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

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

Alternative 4: 91.0% accurate, 0.5× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ \begin{array}{l} t_0 := x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\ x.re\_s \cdot \begin{array}{l} \mathbf{if}\;x.re\_m \cdot \left(x.re\_m \cdot x.re\_m - x.im \cdot x.im\right) - t\_0 \leq -5 \cdot 10^{-106}:\\ \;\;\;\;\left(x.re\_m \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\\ \mathbf{else}:\\ \;\;\;\;x.re\_m \cdot \left(\left(x.re\_m + x.im\right) \cdot \left(x.re\_m - x.im\right)\right) - t\_0\\ \end{array} \end{array} \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (let* ((t_0 (* x.im (+ (* x.re_m x.im) (* x.re_m x.im)))))
   (*
    x.re_s
    (if (<= (- (* x.re_m (- (* x.re_m x.re_m) (* x.im x.im))) t_0) -5e-106)
      (* (* x.re_m x.im) (* x.im -3.0))
      (- (* x.re_m (* (+ x.re_m x.im) (- x.re_m x.im))) t_0)))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double t_0 = x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	double tmp;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - t_0) <= -5e-106) {
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	} else {
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - t_0;
	}
	return x_46_re_s * tmp;
}
x.re\_m = abs(x_46re)
x.re\_s = copysign(1.0d0, x_46re)
real(8) function code(x_46re_s, x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x_46im * ((x_46re_m * x_46im) + (x_46re_m * x_46im))
    if (((x_46re_m * ((x_46re_m * x_46re_m) - (x_46im * x_46im))) - t_0) <= (-5d-106)) then
        tmp = (x_46re_m * x_46im) * (x_46im * (-3.0d0))
    else
        tmp = (x_46re_m * ((x_46re_m + x_46im) * (x_46re_m - x_46im))) - t_0
    end if
    code = x_46re_s * tmp
end function
x.re\_m = Math.abs(x_46_re);
x.re\_s = Math.copySign(1.0, x_46_re);
public static double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	double t_0 = x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	double tmp;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - t_0) <= -5e-106) {
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	} else {
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - t_0;
	}
	return x_46_re_s * tmp;
}
x.re\_m = math.fabs(x_46_re)
x.re\_s = math.copysign(1.0, x_46_re)
def code(x_46_re_s, x_46_re_m, x_46_im):
	t_0 = x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im))
	tmp = 0
	if ((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - t_0) <= -5e-106:
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0)
	else:
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - t_0
	return x_46_re_s * tmp
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	t_0 = Float64(x_46_im * 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_re_m * Float64(Float64(x_46_re_m * x_46_re_m) - Float64(x_46_im * x_46_im))) - t_0) <= -5e-106)
		tmp = Float64(Float64(x_46_re_m * x_46_im) * Float64(x_46_im * -3.0));
	else
		tmp = Float64(Float64(x_46_re_m * Float64(Float64(x_46_re_m + x_46_im) * Float64(x_46_re_m - x_46_im))) - t_0);
	end
	return Float64(x_46_re_s * tmp)
end
x.re\_m = abs(x_46_re);
x.re\_s = sign(x_46_re) * abs(1.0);
function tmp_2 = code(x_46_re_s, x_46_re_m, x_46_im)
	t_0 = x_46_im * ((x_46_re_m * x_46_im) + (x_46_re_m * x_46_im));
	tmp = 0.0;
	if (((x_46_re_m * ((x_46_re_m * x_46_re_m) - (x_46_im * x_46_im))) - t_0) <= -5e-106)
		tmp = (x_46_re_m * x_46_im) * (x_46_im * -3.0);
	else
		tmp = (x_46_re_m * ((x_46_re_m + x_46_im) * (x_46_re_m - x_46_im))) - t_0;
	end
	tmp_2 = x_46_re_s * tmp;
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := Block[{t$95$0 = N[(x$46$im * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] + N[(x$46$re$95$m * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$46$re$95$s * If[LessEqual[N[(N[(x$46$re$95$m * 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], -5e-106], N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision], N[(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] - t$95$0), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

\\
\begin{array}{l}
t_0 := x.im \cdot \left(x.re\_m \cdot x.im + x.re\_m \cdot x.im\right)\\
x.re\_s \cdot \begin{array}{l}
\mathbf{if}\;x.re\_m \cdot \left(x.re\_m \cdot x.re\_m - x.im \cdot x.im\right) - t\_0 \leq -5 \cdot 10^{-106}:\\
\;\;\;\;\left(x.re\_m \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\\

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


\end{array}
\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)) < -4.99999999999999983e-106

    1. Initial program 90.3%

      \[\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-neg90.3%

        \[\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. *-commutative90.3%

        \[\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-neg90.3%

        \[\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-neg90.3%

        \[\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. *-commutative90.3%

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x.re around 0 35.2%

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)}} \cdot \left(x.im \cdot -3\right) \]
      5. add-exp-log0.3%

        \[\leadsto e^{\log \left(x.re \cdot x.im\right)} \cdot \color{blue}{e^{\log \left(x.im \cdot -3\right)}} \]
      6. prod-exp0.3%

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

      \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right) + \log \left(x.im \cdot -3\right)}} \]
    9. Step-by-step derivation
      1. exp-sum0.3%

        \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)} \cdot e^{\log \left(x.im \cdot -3\right)}} \]
      2. rem-exp-log18.4%

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

        \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot e^{\log \left(x.im \cdot -3\right)} \]
      4. rem-exp-log44.8%

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

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

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

    if -4.99999999999999983e-106 < (-.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 79.3%

      \[\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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares83.2%

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

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

    \[\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 -5 \cdot 10^{-106}:\\ \;\;\;\;\left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 56.0% accurate, 2.7× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \left(\left(x.re\_m \cdot x.im\right) \cdot \left(x.im \cdot -3\right)\right) \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (* x.re_s (* (* x.re_m x.im) (* x.im -3.0))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	return x_46_re_s * ((x_46_re_m * x_46_im) * (x_46_im * -3.0));
}
x.re\_m = abs(x_46re)
x.re\_s = copysign(1.0d0, x_46re)
real(8) function code(x_46re_s, x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    code = x_46re_s * ((x_46re_m * x_46im) * (x_46im * (-3.0d0)))
end function
x.re\_m = Math.abs(x_46_re);
x.re\_s = Math.copySign(1.0, x_46_re);
public static double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	return x_46_re_s * ((x_46_re_m * x_46_im) * (x_46_im * -3.0));
}
x.re\_m = math.fabs(x_46_re)
x.re\_s = math.copysign(1.0, x_46_re)
def code(x_46_re_s, x_46_re_m, x_46_im):
	return x_46_re_s * ((x_46_re_m * x_46_im) * (x_46_im * -3.0))
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	return Float64(x_46_re_s * Float64(Float64(x_46_re_m * x_46_im) * Float64(x_46_im * -3.0)))
end
x.re\_m = abs(x_46_re);
x.re\_s = sign(x_46_re) * abs(1.0);
function tmp = code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = x_46_re_s * ((x_46_re_m * x_46_im) * (x_46_im * -3.0));
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := N[(x$46$re$95$s * N[(N[(x$46$re$95$m * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

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

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

      \[\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. *-commutative82.7%

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

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

      \[\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. *-commutative82.7%

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x.re around 0 45.4%

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

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

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

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

      \[\leadsto \color{blue}{\left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)} \]
    4. add-exp-log27.5%

      \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)}} \cdot \left(x.im \cdot -3\right) \]
    5. add-exp-log12.5%

      \[\leadsto e^{\log \left(x.re \cdot x.im\right)} \cdot \color{blue}{e^{\log \left(x.im \cdot -3\right)}} \]
    6. prod-exp12.4%

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

    \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right) + \log \left(x.im \cdot -3\right)}} \]
  9. Step-by-step derivation
    1. exp-sum12.5%

      \[\leadsto \color{blue}{e^{\log \left(x.re \cdot x.im\right)} \cdot e^{\log \left(x.im \cdot -3\right)}} \]
    2. rem-exp-log21.0%

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

      \[\leadsto \color{blue}{\left(x.im \cdot x.re\right)} \cdot e^{\log \left(x.im \cdot -3\right)} \]
    4. rem-exp-log51.2%

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

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

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

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

Alternative 6: 50.3% accurate, 2.7× speedup?

\[\begin{array}{l} x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \left(x.re\_m \cdot \left(-3 \cdot \left(x.im \cdot x.im\right)\right)\right) \end{array} \]
x.re\_m = (fabs.f64 x.re)
x.re\_s = (copysign.f64 #s(literal 1 binary64) x.re)
(FPCore (x.re_s x.re_m x.im)
 :precision binary64
 (* x.re_s (* x.re_m (* -3.0 (* x.im x.im)))))
x.re\_m = fabs(x_46_re);
x.re\_s = copysign(1.0, x_46_re);
double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	return x_46_re_s * (x_46_re_m * (-3.0 * (x_46_im * x_46_im)));
}
x.re\_m = abs(x_46re)
x.re\_s = copysign(1.0d0, x_46re)
real(8) function code(x_46re_s, x_46re_m, x_46im)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im
    code = x_46re_s * (x_46re_m * ((-3.0d0) * (x_46im * x_46im)))
end function
x.re\_m = Math.abs(x_46_re);
x.re\_s = Math.copySign(1.0, x_46_re);
public static double code(double x_46_re_s, double x_46_re_m, double x_46_im) {
	return x_46_re_s * (x_46_re_m * (-3.0 * (x_46_im * x_46_im)));
}
x.re\_m = math.fabs(x_46_re)
x.re\_s = math.copysign(1.0, x_46_re)
def code(x_46_re_s, x_46_re_m, x_46_im):
	return x_46_re_s * (x_46_re_m * (-3.0 * (x_46_im * x_46_im)))
x.re\_m = abs(x_46_re)
x.re\_s = copysign(1.0, x_46_re)
function code(x_46_re_s, x_46_re_m, x_46_im)
	return Float64(x_46_re_s * Float64(x_46_re_m * Float64(-3.0 * Float64(x_46_im * x_46_im))))
end
x.re\_m = abs(x_46_re);
x.re\_s = sign(x_46_re) * abs(1.0);
function tmp = code(x_46_re_s, x_46_re_m, x_46_im)
	tmp = x_46_re_s * (x_46_re_m * (-3.0 * (x_46_im * x_46_im)));
end
x.re\_m = N[Abs[x$46$re], $MachinePrecision]
x.re\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$re$95$s_, x$46$re$95$m_, x$46$im_] := N[(x$46$re$95$s * N[(x$46$re$95$m * N[(-3.0 * N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

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

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

      \[\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. *-commutative82.7%

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

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

      \[\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. *-commutative82.7%

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.re \cdot x.re - x.im \cdot x.im, x.im \cdot \left(-2 \cdot \left(x.re \cdot x.im\right)\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x.re around 0 45.4%

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

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

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

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

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

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

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