math.cube on complex, imaginary part

Percentage Accurate: 82.2% → 99.7%
Time: 7.5s
Alternatives: 8
Speedup: 0.8×

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 8 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ \begin{array}{l} t_0 := x.im\_m \cdot \left(x.re\_m - x.im\_m\right)\\ t_1 := x.re\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\ t_2 := x.im\_m \cdot \left(x.re\_m \cdot x.re\_m - x.im\_m \cdot x.im\_m\right) + t\_1\\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;t\_2 \leq 5 \cdot 10^{+182}:\\ \;\;\;\;t\_1 + x.im\_m \cdot \left(t\_0 + x.re\_m \cdot \left(x.re\_m - x.im\_m\right)\right)\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(x.im\_m + x.re\_m\right)\\ \end{array} \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re_m x.im_m)
 :precision binary64
 (let* ((t_0 (* x.im_m (- x.re_m x.im_m)))
        (t_1 (* x.re_m (+ (* x.im_m x.re_m) (* x.im_m x.re_m))))
        (t_2 (+ (* x.im_m (- (* x.re_m x.re_m) (* x.im_m x.im_m))) t_1)))
   (*
    x.im_s
    (if (<= t_2 5e+182)
      (+ t_1 (* x.im_m (+ t_0 (* x.re_m (- x.re_m x.im_m)))))
      (if (<= t_2 INFINITY)
        (* x.re_m (* x.re_m (* x.im_m 3.0)))
        (* t_0 (+ x.im_m x.re_m)))))))
x.re_m = fabs(x_46_re);
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double t_0 = x_46_im_m * (x_46_re_m - x_46_im_m);
	double t_1 = x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m));
	double t_2 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + t_1;
	double tmp;
	if (t_2 <= 5e+182) {
		tmp = t_1 + (x_46_im_m * (t_0 + (x_46_re_m * (x_46_re_m - x_46_im_m))));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = t_0 * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = Math.abs(x_46_re);
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double t_0 = x_46_im_m * (x_46_re_m - x_46_im_m);
	double t_1 = x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m));
	double t_2 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + t_1;
	double tmp;
	if (t_2 <= 5e+182) {
		tmp = t_1 + (x_46_im_m * (t_0 + (x_46_re_m * (x_46_re_m - x_46_im_m))));
	} else if (t_2 <= Double.POSITIVE_INFINITY) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = t_0 * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = math.fabs(x_46_re)
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re_m, x_46_im_m):
	t_0 = x_46_im_m * (x_46_re_m - x_46_im_m)
	t_1 = x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m))
	t_2 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + t_1
	tmp = 0
	if t_2 <= 5e+182:
		tmp = t_1 + (x_46_im_m * (t_0 + (x_46_re_m * (x_46_re_m - x_46_im_m))))
	elif t_2 <= math.inf:
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0))
	else:
		tmp = t_0 * (x_46_im_m + x_46_re_m)
	return x_46_im_s * tmp
x.re_m = abs(x_46_re)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re_m, x_46_im_m)
	t_0 = Float64(x_46_im_m * Float64(x_46_re_m - x_46_im_m))
	t_1 = Float64(x_46_re_m * Float64(Float64(x_46_im_m * x_46_re_m) + Float64(x_46_im_m * x_46_re_m)))
	t_2 = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re_m * x_46_re_m) - Float64(x_46_im_m * x_46_im_m))) + t_1)
	tmp = 0.0
	if (t_2 <= 5e+182)
		tmp = Float64(t_1 + Float64(x_46_im_m * Float64(t_0 + Float64(x_46_re_m * Float64(x_46_re_m - x_46_im_m)))));
	elseif (t_2 <= Inf)
		tmp = Float64(x_46_re_m * Float64(x_46_re_m * Float64(x_46_im_m * 3.0)));
	else
		tmp = Float64(t_0 * Float64(x_46_im_m + x_46_re_m));
	end
	return Float64(x_46_im_s * tmp)
end
x.re_m = abs(x_46_re);
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re_m, x_46_im_m)
	t_0 = x_46_im_m * (x_46_re_m - x_46_im_m);
	t_1 = x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m));
	t_2 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + t_1;
	tmp = 0.0;
	if (t_2 <= 5e+182)
		tmp = t_1 + (x_46_im_m * (t_0 + (x_46_re_m * (x_46_re_m - x_46_im_m))));
	elseif (t_2 <= Inf)
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	else
		tmp = t_0 * (x_46_im_m + x_46_re_m);
	end
	tmp_2 = x_46_im_s * tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re$95$m_, x$46$im$95$m_] := Block[{t$95$0 = N[(x$46$im$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x$46$re$95$m * N[(N[(x$46$im$95$m * x$46$re$95$m), $MachinePrecision] + N[(x$46$im$95$m * x$46$re$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x$46$im$95$m * N[(N[(x$46$re$95$m * x$46$re$95$m), $MachinePrecision] - N[(x$46$im$95$m * x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]}, N[(x$46$im$95$s * If[LessEqual[t$95$2, 5e+182], N[(t$95$1 + N[(x$46$im$95$m * N[(t$95$0 + N[(x$46$re$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(x$46$re$95$m * N[(x$46$re$95$m * N[(x$46$im$95$m * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]]
\begin{array}{l}
x.re_m = \left|x.re\right|
\\
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

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

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 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)) < 4.99999999999999973e182

    1. Initial program 96.1%

      \[\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. difference-of-squares96.1%

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in94.9%

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

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

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

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

    if 4.99999999999999973e182 < (+.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 86.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares23.3%

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in16.7%

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 87.2%

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

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

    if 9.9999999999999998e100 < x.im

    1. Initial program 64.7%

      \[\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. difference-of-squares72.5%

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in70.6%

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

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

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

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

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

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

Alternative 3: 99.8% accurate, 0.2× speedup?

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

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

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


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

    1. Initial program 87.2%

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

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

    if 5.00000000000000008e99 < x.im

    1. Initial program 64.7%

      \[\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. difference-of-squares72.5%

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in70.6%

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

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

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

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

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

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

Alternative 4: 99.7% accurate, 0.3× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ \begin{array}{l} t_0 := x.im\_m \cdot \left(x.re\_m \cdot x.re\_m - x.im\_m \cdot x.im\_m\right) + x.re\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 5 \cdot 10^{+182}:\\ \;\;\;\;x.im\_m \cdot \left(\left(x.re\_m - x.im\_m\right) \cdot \left(x.im\_m + x.re\_m\right)\right) + x.re\_m \cdot \left(\left(x.im\_m \cdot x.re\_m\right) \cdot 2\right)\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im\_m \cdot \left(x.re\_m - x.im\_m\right)\right) \cdot \left(x.im\_m + x.re\_m\right)\\ \end{array} \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re_m x.im_m)
 :precision binary64
 (let* ((t_0
         (+
          (* x.im_m (- (* x.re_m x.re_m) (* x.im_m x.im_m)))
          (* x.re_m (+ (* x.im_m x.re_m) (* x.im_m x.re_m))))))
   (*
    x.im_s
    (if (<= t_0 5e+182)
      (+
       (* x.im_m (* (- x.re_m x.im_m) (+ x.im_m x.re_m)))
       (* x.re_m (* (* x.im_m x.re_m) 2.0)))
      (if (<= t_0 INFINITY)
        (* x.re_m (* x.re_m (* x.im_m 3.0)))
        (* (* x.im_m (- x.re_m x.im_m)) (+ x.im_m x.re_m)))))))
x.re_m = fabs(x_46_re);
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double t_0 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	double tmp;
	if (t_0 <= 5e+182) {
		tmp = (x_46_im_m * ((x_46_re_m - x_46_im_m) * (x_46_im_m + x_46_re_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) * 2.0));
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = Math.abs(x_46_re);
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double t_0 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	double tmp;
	if (t_0 <= 5e+182) {
		tmp = (x_46_im_m * ((x_46_re_m - x_46_im_m) * (x_46_im_m + x_46_re_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) * 2.0));
	} else if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = math.fabs(x_46_re)
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re_m, x_46_im_m):
	t_0 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)))
	tmp = 0
	if t_0 <= 5e+182:
		tmp = (x_46_im_m * ((x_46_re_m - x_46_im_m) * (x_46_im_m + x_46_re_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) * 2.0))
	elif t_0 <= math.inf:
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0))
	else:
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m)
	return x_46_im_s * tmp
x.re_m = abs(x_46_re)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re_m, x_46_im_m)
	t_0 = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re_m * x_46_re_m) - Float64(x_46_im_m * x_46_im_m))) + Float64(x_46_re_m * Float64(Float64(x_46_im_m * x_46_re_m) + Float64(x_46_im_m * x_46_re_m))))
	tmp = 0.0
	if (t_0 <= 5e+182)
		tmp = Float64(Float64(x_46_im_m * Float64(Float64(x_46_re_m - x_46_im_m) * Float64(x_46_im_m + x_46_re_m))) + Float64(x_46_re_m * Float64(Float64(x_46_im_m * x_46_re_m) * 2.0)));
	elseif (t_0 <= Inf)
		tmp = Float64(x_46_re_m * Float64(x_46_re_m * Float64(x_46_im_m * 3.0)));
	else
		tmp = Float64(Float64(x_46_im_m * Float64(x_46_re_m - x_46_im_m)) * Float64(x_46_im_m + x_46_re_m));
	end
	return Float64(x_46_im_s * tmp)
end
x.re_m = abs(x_46_re);
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re_m, x_46_im_m)
	t_0 = (x_46_im_m * ((x_46_re_m * x_46_re_m) - (x_46_im_m * x_46_im_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	tmp = 0.0;
	if (t_0 <= 5e+182)
		tmp = (x_46_im_m * ((x_46_re_m - x_46_im_m) * (x_46_im_m + x_46_re_m))) + (x_46_re_m * ((x_46_im_m * x_46_re_m) * 2.0));
	elseif (t_0 <= Inf)
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	else
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	end
	tmp_2 = x_46_im_s * tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re$95$m_, x$46$im$95$m_] := Block[{t$95$0 = N[(N[(x$46$im$95$m * N[(N[(x$46$re$95$m * x$46$re$95$m), $MachinePrecision] - N[(x$46$im$95$m * x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x$46$re$95$m * N[(N[(x$46$im$95$m * x$46$re$95$m), $MachinePrecision] + N[(x$46$im$95$m * x$46$re$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$46$im$95$s * If[LessEqual[t$95$0, 5e+182], N[(N[(x$46$im$95$m * N[(N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision] * N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x$46$re$95$m * N[(N[(x$46$im$95$m * x$46$re$95$m), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(x$46$re$95$m * N[(x$46$re$95$m * N[(x$46$im$95$m * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision] * N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
x.re_m = \left|x.re\right|
\\
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

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

\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 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)) < 4.99999999999999973e182

    1. Initial program 96.1%

      \[\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. difference-of-squares96.1%

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

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

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

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

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

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

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

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

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

    if 4.99999999999999973e182 < (+.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 86.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\left(x.im \cdot 3\right) \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. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares23.3%

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in16.7%

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

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

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

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

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

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

Alternative 5: 92.3% accurate, 0.8× speedup?

\[\begin{array}{l} x.re_m = \left|x.re\right| \\ x.im\_m = \left|x.im\right| \\ x.im\_s = \mathsf{copysign}\left(1, x.im\right) \\ x.im\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 7.8 \cdot 10^{-111} \lor \neg \left(x.im\_m \leq 2.3 \cdot 10^{-77}\right) \land x.im\_m \leq 5.1 \cdot 10^{-52}:\\ \;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im\_m \cdot \left(x.re\_m - x.im\_m\right)\right) \cdot \left(x.im\_m + x.re\_m\right)\\ \end{array} \end{array} \]
x.re_m = (fabs.f64 x.re)
x.im\_m = (fabs.f64 x.im)
x.im\_s = (copysign.f64 #s(literal 1 binary64) x.im)
(FPCore (x.im_s x.re_m x.im_m)
 :precision binary64
 (*
  x.im_s
  (if (or (<= x.im_m 7.8e-111)
          (and (not (<= x.im_m 2.3e-77)) (<= x.im_m 5.1e-52)))
    (* x.re_m (* x.re_m (* x.im_m 3.0)))
    (* (* x.im_m (- x.re_m x.im_m)) (+ x.im_m x.re_m)))))
x.re_m = fabs(x_46_re);
x.im\_m = fabs(x_46_im);
x.im\_s = copysign(1.0, x_46_im);
double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double tmp;
	if ((x_46_im_m <= 7.8e-111) || (!(x_46_im_m <= 2.3e-77) && (x_46_im_m <= 5.1e-52))) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = abs(x_46re)
x.im\_m = abs(x_46im)
x.im\_s = copysign(1.0d0, x_46im)
real(8) function code(x_46im_s, x_46re_m, x_46im_m)
    real(8), intent (in) :: x_46im_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if ((x_46im_m <= 7.8d-111) .or. (.not. (x_46im_m <= 2.3d-77)) .and. (x_46im_m <= 5.1d-52)) then
        tmp = x_46re_m * (x_46re_m * (x_46im_m * 3.0d0))
    else
        tmp = (x_46im_m * (x_46re_m - x_46im_m)) * (x_46im_m + x_46re_m)
    end if
    code = x_46im_s * tmp
end function
x.re_m = Math.abs(x_46_re);
x.im\_m = Math.abs(x_46_im);
x.im\_s = Math.copySign(1.0, x_46_im);
public static double code(double x_46_im_s, double x_46_re_m, double x_46_im_m) {
	double tmp;
	if ((x_46_im_m <= 7.8e-111) || (!(x_46_im_m <= 2.3e-77) && (x_46_im_m <= 5.1e-52))) {
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	} else {
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	}
	return x_46_im_s * tmp;
}
x.re_m = math.fabs(x_46_re)
x.im\_m = math.fabs(x_46_im)
x.im\_s = math.copysign(1.0, x_46_im)
def code(x_46_im_s, x_46_re_m, x_46_im_m):
	tmp = 0
	if (x_46_im_m <= 7.8e-111) or (not (x_46_im_m <= 2.3e-77) and (x_46_im_m <= 5.1e-52)):
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0))
	else:
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m)
	return x_46_im_s * tmp
x.re_m = abs(x_46_re)
x.im\_m = abs(x_46_im)
x.im\_s = copysign(1.0, x_46_im)
function code(x_46_im_s, x_46_re_m, x_46_im_m)
	tmp = 0.0
	if ((x_46_im_m <= 7.8e-111) || (!(x_46_im_m <= 2.3e-77) && (x_46_im_m <= 5.1e-52)))
		tmp = Float64(x_46_re_m * Float64(x_46_re_m * Float64(x_46_im_m * 3.0)));
	else
		tmp = Float64(Float64(x_46_im_m * Float64(x_46_re_m - x_46_im_m)) * Float64(x_46_im_m + x_46_re_m));
	end
	return Float64(x_46_im_s * tmp)
end
x.re_m = abs(x_46_re);
x.im\_m = abs(x_46_im);
x.im\_s = sign(x_46_im) * abs(1.0);
function tmp_2 = code(x_46_im_s, x_46_re_m, x_46_im_m)
	tmp = 0.0;
	if ((x_46_im_m <= 7.8e-111) || (~((x_46_im_m <= 2.3e-77)) && (x_46_im_m <= 5.1e-52)))
		tmp = x_46_re_m * (x_46_re_m * (x_46_im_m * 3.0));
	else
		tmp = (x_46_im_m * (x_46_re_m - x_46_im_m)) * (x_46_im_m + x_46_re_m);
	end
	tmp_2 = x_46_im_s * tmp;
end
x.re_m = N[Abs[x$46$re], $MachinePrecision]
x.im\_m = N[Abs[x$46$im], $MachinePrecision]
x.im\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x$46$im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$46$im$95$s_, x$46$re$95$m_, x$46$im$95$m_] := N[(x$46$im$95$s * If[Or[LessEqual[x$46$im$95$m, 7.8e-111], And[N[Not[LessEqual[x$46$im$95$m, 2.3e-77]], $MachinePrecision], LessEqual[x$46$im$95$m, 5.1e-52]]], N[(x$46$re$95$m * N[(x$46$re$95$m * N[(x$46$im$95$m * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision] * N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.re_m = \left|x.re\right|
\\
x.im\_m = \left|x.im\right|
\\
x.im\_s = \mathsf{copysign}\left(1, x.im\right)

\\
x.im\_s \cdot \begin{array}{l}
\mathbf{if}\;x.im\_m \leq 7.8 \cdot 10^{-111} \lor \neg \left(x.im\_m \leq 2.3 \cdot 10^{-77}\right) \land x.im\_m \leq 5.1 \cdot 10^{-52}:\\
\;\;\;\;x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.im < 7.8000000000000006e-111 or 2.29999999999999999e-77 < x.im < 5.09999999999999989e-52

    1. Initial program 84.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. Simplified88.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.8000000000000006e-111 < x.im < 2.29999999999999999e-77 or 5.09999999999999989e-52 < x.im

    1. Initial program 79.1%

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

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

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

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

        \[\leadsto \color{blue}{x.im \cdot \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 \]
      2. distribute-rgt-in80.3%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq 7.8 \cdot 10^{-111} \lor \neg \left(x.im \leq 2.3 \cdot 10^{-77}\right) \land x.im \leq 5.1 \cdot 10^{-52}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.im + x.re\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 55.6% accurate, 2.7× speedup?

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

\\
x.im\_s \cdot \left(x.re\_m \cdot \left(x.re\_m \cdot \left(x.im\_m \cdot 3\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.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
  2. Simplified85.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 2.8% accurate, 9.5× speedup?

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

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

    \[\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. difference-of-squares85.5%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1 \cdot x.re} \]
  9. Step-by-step derivation
    1. mul-1-neg3.4%

      \[\leadsto \color{blue}{-x.re} \]
  10. Simplified3.4%

    \[\leadsto \color{blue}{-x.re} \]
  11. Final simplification3.4%

    \[\leadsto -x.re \]
  12. Add Preprocessing

Alternative 8: 2.7% accurate, 19.0× speedup?

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

\\
x.im\_s \cdot -3
\end{array}
Derivation
  1. Initial program 82.7%

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot \color{blue}{\left(x.im \cdot 2\right)}, \left(\left(-x.re\right) \cdot \left(-x.re\right) - x.im \cdot x.im\right) \cdot x.im\right) \]
    9. *-commutative85.5%

      \[\leadsto \mathsf{fma}\left(x.re, x.re \cdot \left(x.im \cdot 2\right), \color{blue}{x.im \cdot \left(\left(-x.re\right) \cdot \left(-x.re\right) - x.im \cdot x.im\right)}\right) \]
    10. sqr-neg85.5%

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

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

    \[\leadsto \color{blue}{-1 \cdot {x.im}^{3}} \]
  6. Simplified2.9%

    \[\leadsto \color{blue}{-3} \]
  7. Final simplification2.9%

    \[\leadsto -3 \]
  8. Add Preprocessing

Developer target: 91.3% 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 2024069 
(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)))