math.cube on complex, real part

Percentage Accurate: 81.8% → 97.3%
Time: 6.2s
Alternatives: 7
Speedup: 0.8×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 81.8% accurate, 1.0× speedup?

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

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

Alternative 1: 97.3% accurate, 0.0× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ \begin{array}{l} t_0 := x.im\_m \cdot \sqrt{x.re\_m \cdot 3}\\ x.re\_s \cdot \begin{array}{l} \mathbf{if}\;x.im\_m \leq 2.6 \cdot 10^{+188}:\\ \;\;\;\;\left({x.re\_m}^{1.5} + t\_0\right) \cdot \left({x.re\_m}^{1.5} - t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \end{array} \end{array} \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (let* ((t_0 (* x.im_m (sqrt (* x.re_m 3.0)))))
   (*
    x.re_s
    (if (<= x.im_m 2.6e+188)
      (* (+ (pow x.re_m 1.5) t_0) (- (pow x.re_m 1.5) t_0))
      (* x.im_m (* x.im_m (* x.re_m -3.0)))))))
x.im_m = fabs(x_46_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_m) {
	double t_0 = x_46_im_m * sqrt((x_46_re_m * 3.0));
	double tmp;
	if (x_46_im_m <= 2.6e+188) {
		tmp = (pow(x_46_re_m, 1.5) + t_0) * (pow(x_46_re_m, 1.5) - t_0);
	} else {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	}
	return x_46_re_s * tmp;
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = x_46im_m * sqrt((x_46re_m * 3.0d0))
    if (x_46im_m <= 2.6d+188) then
        tmp = ((x_46re_m ** 1.5d0) + t_0) * ((x_46re_m ** 1.5d0) - t_0)
    else
        tmp = x_46im_m * (x_46im_m * (x_46re_m * (-3.0d0)))
    end if
    code = x_46re_s * tmp
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	double t_0 = x_46_im_m * Math.sqrt((x_46_re_m * 3.0));
	double tmp;
	if (x_46_im_m <= 2.6e+188) {
		tmp = (Math.pow(x_46_re_m, 1.5) + t_0) * (Math.pow(x_46_re_m, 1.5) - t_0);
	} else {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	}
	return x_46_re_s * tmp;
}
x.im_m = math.fabs(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_m):
	t_0 = x_46_im_m * math.sqrt((x_46_re_m * 3.0))
	tmp = 0
	if x_46_im_m <= 2.6e+188:
		tmp = (math.pow(x_46_re_m, 1.5) + t_0) * (math.pow(x_46_re_m, 1.5) - t_0)
	else:
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0))
	return x_46_re_s * tmp
x.im_m = abs(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_m)
	t_0 = Float64(x_46_im_m * sqrt(Float64(x_46_re_m * 3.0)))
	tmp = 0.0
	if (x_46_im_m <= 2.6e+188)
		tmp = Float64(Float64((x_46_re_m ^ 1.5) + t_0) * Float64((x_46_re_m ^ 1.5) - t_0));
	else
		tmp = Float64(x_46_im_m * Float64(x_46_im_m * Float64(x_46_re_m * -3.0)));
	end
	return Float64(x_46_re_s * tmp)
end
x.im_m = abs(x_46_im);
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_m)
	t_0 = x_46_im_m * sqrt((x_46_re_m * 3.0));
	tmp = 0.0;
	if (x_46_im_m <= 2.6e+188)
		tmp = ((x_46_re_m ^ 1.5) + t_0) * ((x_46_re_m ^ 1.5) - t_0);
	else
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	end
	tmp_2 = x_46_re_s * tmp;
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := Block[{t$95$0 = N[(x$46$im$95$m * N[Sqrt[N[(x$46$re$95$m * 3.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(x$46$re$95$s * If[LessEqual[x$46$im$95$m, 2.6e+188], N[(N[(N[Power[x$46$re$95$m, 1.5], $MachinePrecision] + t$95$0), $MachinePrecision] * N[(N[Power[x$46$re$95$m, 1.5], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision], N[(x$46$im$95$m * N[(x$46$im$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

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

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


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

    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. Simplified85.1%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({x.re}^{1.5} + \sqrt{x.re \cdot 3} \cdot x.im\right) \cdot \left({x.re}^{1.5} - \sqrt{\color{blue}{\left(x.re \cdot 3\right) \cdot \left(x.im \cdot x.im\right)}}\right) \]
      11. sqrt-prod38.7%

        \[\leadsto \left({x.re}^{1.5} + \sqrt{x.re \cdot 3} \cdot x.im\right) \cdot \left({x.re}^{1.5} - \color{blue}{\sqrt{x.re \cdot 3} \cdot \sqrt{x.im \cdot x.im}}\right) \]
      12. sqrt-prod25.7%

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

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

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

    if 2.59999999999999987e188 < x.im

    1. Initial program 45.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. Add Preprocessing
    3. Taylor expanded in x.re around 0 45.7%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 94.9% accurate, 0.2× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ 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 2.35 \cdot 10^{+246}:\\ \;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.re\_m \cdot \left(x.re\_m - x.im\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\ \mathbf{else}:\\ \;\;\;\;{x.re\_m}^{3}\\ \end{array} \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (*
  x.re_s
  (if (<= x.re_m 2.35e+246)
    (-
     (* (+ x.im_m x.re_m) (* x.re_m (- x.re_m x.im_m)))
     (* x.im_m (+ (* x.im_m x.re_m) (* x.im_m x.re_m))))
    (pow x.re_m 3.0))))
x.im_m = fabs(x_46_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_m) {
	double tmp;
	if (x_46_re_m <= 2.35e+246) {
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	} else {
		tmp = pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46re_m <= 2.35d+246) then
        tmp = ((x_46im_m + x_46re_m) * (x_46re_m * (x_46re_m - x_46im_m))) - (x_46im_m * ((x_46im_m * x_46re_m) + (x_46im_m * x_46re_m)))
    else
        tmp = x_46re_m ** 3.0d0
    end if
    code = x_46re_s * tmp
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	double tmp;
	if (x_46_re_m <= 2.35e+246) {
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	} else {
		tmp = Math.pow(x_46_re_m, 3.0);
	}
	return x_46_re_s * tmp;
}
x.im_m = math.fabs(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_m):
	tmp = 0
	if x_46_re_m <= 2.35e+246:
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)))
	else:
		tmp = math.pow(x_46_re_m, 3.0)
	return x_46_re_s * tmp
x.im_m = abs(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_m)
	tmp = 0.0
	if (x_46_re_m <= 2.35e+246)
		tmp = Float64(Float64(Float64(x_46_im_m + x_46_re_m) * Float64(x_46_re_m * Float64(x_46_re_m - x_46_im_m))) - Float64(x_46_im_m * Float64(Float64(x_46_im_m * x_46_re_m) + Float64(x_46_im_m * x_46_re_m))));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	return Float64(x_46_re_s * tmp)
end
x.im_m = abs(x_46_im);
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_m)
	tmp = 0.0;
	if (x_46_re_m <= 2.35e+246)
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	else
		tmp = x_46_re_m ^ 3.0;
	end
	tmp_2 = x_46_re_s * tmp;
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * If[LessEqual[x$46$re$95$m, 2.35e+246], N[(N[(N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision] * N[(x$46$re$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im$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[Power[x$46$re$95$m, 3.0], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
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 2.35 \cdot 10^{+246}:\\
\;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.re\_m \cdot \left(x.re\_m - x.im\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.re < 2.34999999999999988e246

    1. Initial program 85.4%

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

        \[\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 \]
      2. associate-*l*96.8%

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

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

    if 2.34999999999999988e246 < x.re

    1. Initial program 53.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-squares61.5%

        \[\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 \]
      2. associate-*l*61.5%

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

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

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

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

Alternative 3: 94.0% accurate, 0.8× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ 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.2 \cdot 10^{+247}:\\ \;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.re\_m \cdot \left(x.re\_m - x.im\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.im\_m \cdot x.re\_m\right)\\ \end{array} \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (*
  x.re_s
  (if (<= x.re_m 5.2e+247)
    (-
     (* (+ x.im_m x.re_m) (* x.re_m (- x.re_m x.im_m)))
     (* x.im_m (+ (* x.im_m x.re_m) (* x.im_m x.re_m))))
    (* (+ x.im_m x.re_m) (* x.im_m x.re_m)))))
x.im_m = fabs(x_46_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_m) {
	double tmp;
	if (x_46_re_m <= 5.2e+247) {
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	} else {
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	}
	return x_46_re_s * tmp;
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46re_m <= 5.2d+247) then
        tmp = ((x_46im_m + x_46re_m) * (x_46re_m * (x_46re_m - x_46im_m))) - (x_46im_m * ((x_46im_m * x_46re_m) + (x_46im_m * x_46re_m)))
    else
        tmp = (x_46im_m + x_46re_m) * (x_46im_m * x_46re_m)
    end if
    code = x_46re_s * tmp
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	double tmp;
	if (x_46_re_m <= 5.2e+247) {
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	} else {
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	}
	return x_46_re_s * tmp;
}
x.im_m = math.fabs(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_m):
	tmp = 0
	if x_46_re_m <= 5.2e+247:
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)))
	else:
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m)
	return x_46_re_s * tmp
x.im_m = abs(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_m)
	tmp = 0.0
	if (x_46_re_m <= 5.2e+247)
		tmp = Float64(Float64(Float64(x_46_im_m + x_46_re_m) * Float64(x_46_re_m * Float64(x_46_re_m - x_46_im_m))) - Float64(x_46_im_m * Float64(Float64(x_46_im_m * x_46_re_m) + Float64(x_46_im_m * x_46_re_m))));
	else
		tmp = Float64(Float64(x_46_im_m + x_46_re_m) * Float64(x_46_im_m * x_46_re_m));
	end
	return Float64(x_46_re_s * tmp)
end
x.im_m = abs(x_46_im);
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_m)
	tmp = 0.0;
	if (x_46_re_m <= 5.2e+247)
		tmp = ((x_46_im_m + x_46_re_m) * (x_46_re_m * (x_46_re_m - x_46_im_m))) - (x_46_im_m * ((x_46_im_m * x_46_re_m) + (x_46_im_m * x_46_re_m)));
	else
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	end
	tmp_2 = x_46_re_s * tmp;
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * If[LessEqual[x$46$re$95$m, 5.2e+247], N[(N[(N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision] * N[(x$46$re$95$m * N[(x$46$re$95$m - x$46$im$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im$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[(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]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
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.2 \cdot 10^{+247}:\\
\;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.re\_m \cdot \left(x.re\_m - x.im\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.re < 5.19999999999999981e247

    1. Initial program 85.4%

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

        \[\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 \]
      2. associate-*l*96.8%

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

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

    if 5.19999999999999981e247 < x.re

    1. Initial program 50.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-squares58.3%

        \[\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 \]
      2. associate-*l*58.3%

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

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

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

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

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

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

      \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re \cdot \left(-x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    8. Step-by-step derivation
      1. add-sqr-sqrt41.7%

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

        \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\sqrt{\left(x.re \cdot \left(-x.im\right)\right) \cdot \left(x.re \cdot \left(-x.im\right)\right)}} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      3. distribute-rgt-neg-out58.3%

        \[\leadsto \left(x.re + x.im\right) \cdot \sqrt{\color{blue}{\left(-x.re \cdot x.im\right)} \cdot \left(x.re \cdot \left(-x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      4. distribute-rgt-neg-out58.3%

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

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

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

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

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

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{\color{blue}{x.im \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}}\right) \]
      10. fma-define0.0%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{x.im \cdot \color{blue}{\mathsf{fma}\left(x.re, x.im, x.im \cdot x.re\right)}}\right) \]
      11. *-commutative0.0%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{x.im \cdot \mathsf{fma}\left(x.re, x.im, \color{blue}{x.re \cdot x.im}\right)}\right) \]
      12. exp-prod16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \color{blue}{\left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, x.re \cdot x.im\right)\right)}\right)} \]
      13. add-sqr-sqrt16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \color{blue}{\sqrt{x.re \cdot x.im} \cdot \sqrt{x.re \cdot x.im}}\right)\right)}\right) \]
      14. sqrt-unprod16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \color{blue}{\sqrt{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}}\right)\right)}\right) \]
      15. sqr-neg16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\color{blue}{\left(-x.re \cdot x.im\right) \cdot \left(-x.re \cdot x.im\right)}}\right)\right)}\right) \]
      16. distribute-rgt-neg-out16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\color{blue}{\left(x.re \cdot \left(-x.im\right)\right)} \cdot \left(-x.re \cdot x.im\right)}\right)\right)}\right) \]
      17. distribute-rgt-neg-out16.7%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\left(x.re \cdot \left(-x.im\right)\right) \cdot \color{blue}{\left(x.re \cdot \left(-x.im\right)\right)}}\right)\right)}\right) \]
    9. Applied egg-rr50.0%

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

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

Alternative 4: 65.8% accurate, 0.9× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ 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.im\_m \leq 90000:\\ \;\;\;\;x.im\_m \cdot \left(x.re\_m \cdot \left(x.im\_m + x.re\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\ \mathbf{else}:\\ \;\;\;\;x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \end{array} \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (*
  x.re_s
  (if (<= x.im_m 90000.0)
    (-
     (* x.im_m (* x.re_m (+ x.im_m x.re_m)))
     (* x.im_m (+ (* x.im_m x.re_m) (* x.im_m x.re_m))))
    (* x.im_m (* x.im_m (* x.re_m -3.0))))))
x.im_m = fabs(x_46_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_m) {
	double tmp;
	if (x_46_im_m <= 90000.0) {
		tmp = (x_46_im_m * (x_46_re_m * (x_46_im_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)));
	} else {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	}
	return x_46_re_s * tmp;
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46im_m <= 90000.0d0) then
        tmp = (x_46im_m * (x_46re_m * (x_46im_m + x_46re_m))) - (x_46im_m * ((x_46im_m * x_46re_m) + (x_46im_m * x_46re_m)))
    else
        tmp = x_46im_m * (x_46im_m * (x_46re_m * (-3.0d0)))
    end if
    code = x_46re_s * tmp
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	double tmp;
	if (x_46_im_m <= 90000.0) {
		tmp = (x_46_im_m * (x_46_re_m * (x_46_im_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)));
	} else {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	}
	return x_46_re_s * tmp;
}
x.im_m = math.fabs(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_m):
	tmp = 0
	if x_46_im_m <= 90000.0:
		tmp = (x_46_im_m * (x_46_re_m * (x_46_im_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)))
	else:
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0))
	return x_46_re_s * tmp
x.im_m = abs(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_m)
	tmp = 0.0
	if (x_46_im_m <= 90000.0)
		tmp = Float64(Float64(x_46_im_m * Float64(x_46_re_m * Float64(x_46_im_m + x_46_re_m))) - Float64(x_46_im_m * Float64(Float64(x_46_im_m * x_46_re_m) + Float64(x_46_im_m * x_46_re_m))));
	else
		tmp = Float64(x_46_im_m * Float64(x_46_im_m * Float64(x_46_re_m * -3.0)));
	end
	return Float64(x_46_re_s * tmp)
end
x.im_m = abs(x_46_im);
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_m)
	tmp = 0.0;
	if (x_46_im_m <= 90000.0)
		tmp = (x_46_im_m * (x_46_re_m * (x_46_im_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)));
	else
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	end
	tmp_2 = x_46_re_s * tmp;
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * If[LessEqual[x$46$im$95$m, 90000.0], N[(N[(x$46$im$95$m * N[(x$46$re$95$m * N[(x$46$im$95$m + x$46$re$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(x$46$im$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$m * N[(x$46$im$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
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.im\_m \leq 90000:\\
\;\;\;\;x.im\_m \cdot \left(x.re\_m \cdot \left(x.im\_m + x.re\_m\right)\right) - x.im\_m \cdot \left(x.im\_m \cdot x.re\_m + x.im\_m \cdot x.re\_m\right)\\

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


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

    1. Initial program 88.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-squares91.3%

        \[\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 \]
      2. associate-*l*97.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(x.re \cdot \left(x.re + x.im\right)\right) \cdot \color{blue}{\left(\sqrt{x.im} \cdot \sqrt{x.im}\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      7. add-sqr-sqrt26.0%

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

      \[\leadsto \color{blue}{\left(x.re \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.im \]

    if 9e4 < x.im

    1. Initial program 68.2%

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    2. Add Preprocessing
    3. Taylor expanded in x.re around 0 73.1%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 68.6% accurate, 1.6× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ 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 2.7 \cdot 10^{+183}:\\ \;\;\;\;x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.im\_m + x.re\_m\right) \cdot \left(x.im\_m \cdot x.re\_m\right)\\ \end{array} \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (*
  x.re_s
  (if (<= x.re_m 2.7e+183)
    (* x.im_m (* x.im_m (* x.re_m -3.0)))
    (* (+ x.im_m x.re_m) (* x.im_m x.re_m)))))
x.im_m = fabs(x_46_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_m) {
	double tmp;
	if (x_46_re_m <= 2.7e+183) {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	} else {
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	}
	return x_46_re_s * tmp;
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    real(8) :: tmp
    if (x_46re_m <= 2.7d+183) then
        tmp = x_46im_m * (x_46im_m * (x_46re_m * (-3.0d0)))
    else
        tmp = (x_46im_m + x_46re_m) * (x_46im_m * x_46re_m)
    end if
    code = x_46re_s * tmp
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	double tmp;
	if (x_46_re_m <= 2.7e+183) {
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	} else {
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	}
	return x_46_re_s * tmp;
}
x.im_m = math.fabs(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_m):
	tmp = 0
	if x_46_re_m <= 2.7e+183:
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0))
	else:
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m)
	return x_46_re_s * tmp
x.im_m = abs(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_m)
	tmp = 0.0
	if (x_46_re_m <= 2.7e+183)
		tmp = Float64(x_46_im_m * Float64(x_46_im_m * Float64(x_46_re_m * -3.0)));
	else
		tmp = Float64(Float64(x_46_im_m + x_46_re_m) * Float64(x_46_im_m * x_46_re_m));
	end
	return Float64(x_46_re_s * tmp)
end
x.im_m = abs(x_46_im);
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_m)
	tmp = 0.0;
	if (x_46_re_m <= 2.7e+183)
		tmp = x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0));
	else
		tmp = (x_46_im_m + x_46_re_m) * (x_46_im_m * x_46_re_m);
	end
	tmp_2 = x_46_re_s * tmp;
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * If[LessEqual[x$46$re$95$m, 2.7e+183], N[(x$46$im$95$m * N[(x$46$im$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
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 2.7 \cdot 10^{+183}:\\
\;\;\;\;x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x.re < 2.69999999999999982e183

    1. Initial program 86.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. Taylor expanded in x.re around 0 88.1%

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

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

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

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

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

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

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

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

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

    if 2.69999999999999982e183 < x.re

    1. Initial program 56.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-squares80.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 \]
      2. associate-*l*80.0%

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

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

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

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

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

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

      \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re \cdot \left(-x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    8. Step-by-step derivation
      1. add-sqr-sqrt48.2%

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

        \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\sqrt{\left(x.re \cdot \left(-x.im\right)\right) \cdot \left(x.re \cdot \left(-x.im\right)\right)}} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      3. distribute-rgt-neg-out60.8%

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

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

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

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

        \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re \cdot x.im\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
      8. add-log-exp0.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \color{blue}{\log \left(e^{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im}\right)} \]
      9. *-commutative0.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{\color{blue}{x.im \cdot \left(x.re \cdot x.im + x.im \cdot x.re\right)}}\right) \]
      10. fma-define0.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{x.im \cdot \color{blue}{\mathsf{fma}\left(x.re, x.im, x.im \cdot x.re\right)}}\right) \]
      11. *-commutative0.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left(e^{x.im \cdot \mathsf{fma}\left(x.re, x.im, \color{blue}{x.re \cdot x.im}\right)}\right) \]
      12. exp-prod8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \color{blue}{\left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, x.re \cdot x.im\right)\right)}\right)} \]
      13. add-sqr-sqrt8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \color{blue}{\sqrt{x.re \cdot x.im} \cdot \sqrt{x.re \cdot x.im}}\right)\right)}\right) \]
      14. sqrt-unprod8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \color{blue}{\sqrt{\left(x.re \cdot x.im\right) \cdot \left(x.re \cdot x.im\right)}}\right)\right)}\right) \]
      15. sqr-neg8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\color{blue}{\left(-x.re \cdot x.im\right) \cdot \left(-x.re \cdot x.im\right)}}\right)\right)}\right) \]
      16. distribute-rgt-neg-out8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\color{blue}{\left(x.re \cdot \left(-x.im\right)\right)} \cdot \left(-x.re \cdot x.im\right)}\right)\right)}\right) \]
      17. distribute-rgt-neg-out8.6%

        \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot x.im\right) - \log \left({\left(e^{x.im}\right)}^{\left(\mathsf{fma}\left(x.re, x.im, \sqrt{\left(x.re \cdot \left(-x.im\right)\right) \cdot \color{blue}{\left(x.re \cdot \left(-x.im\right)\right)}}\right)\right)}\right) \]
    9. Applied egg-rr28.6%

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

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

Alternative 6: 56.4% accurate, 2.7× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ x.re\_m = \left|x.re\right| \\ x.re\_s = \mathsf{copysign}\left(1, x.re\right) \\ x.re\_s \cdot \left(x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\right) \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (* x.re_s (* x.im_m (* x.im_m (* x.re_m -3.0)))))
x.im_m = fabs(x_46_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_m) {
	return x_46_re_s * (x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0)));
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    code = x_46re_s * (x_46im_m * (x_46im_m * (x_46re_m * (-3.0d0))))
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	return x_46_re_s * (x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0)));
}
x.im_m = math.fabs(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_m):
	return x_46_re_s * (x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0)))
x.im_m = abs(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_m)
	return Float64(x_46_re_s * Float64(x_46_im_m * Float64(x_46_im_m * Float64(x_46_re_m * -3.0))))
end
x.im_m = abs(x_46_im);
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_m)
	tmp = x_46_re_s * (x_46_im_m * (x_46_im_m * (x_46_re_m * -3.0)));
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * N[(x$46$im$95$m * N[(x$46$im$95$m * N[(x$46$re$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
x.re\_m = \left|x.re\right|
\\
x.re\_s = \mathsf{copysign}\left(1, x.re\right)

\\
x.re\_s \cdot \left(x.im\_m \cdot \left(x.im\_m \cdot \left(x.re\_m \cdot -3\right)\right)\right)
\end{array}
Derivation
  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. Taylor expanded in x.re around 0 86.1%

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

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

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

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

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

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

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

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

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

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

Alternative 7: 50.4% accurate, 2.7× speedup?

\[\begin{array}{l} x.im_m = \left|x.im\right| \\ 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(x.im\_m \cdot \left(x.im\_m \cdot -3\right)\right)\right) \end{array} \]
x.im_m = (fabs.f64 x.im)
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_m)
 :precision binary64
 (* x.re_s (* x.re_m (* x.im_m (* x.im_m -3.0)))))
x.im_m = fabs(x_46_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_m) {
	return x_46_re_s * (x_46_re_m * (x_46_im_m * (x_46_im_m * -3.0)));
}
x.im_m = abs(x_46im)
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_m)
    real(8), intent (in) :: x_46re_s
    real(8), intent (in) :: x_46re_m
    real(8), intent (in) :: x_46im_m
    code = x_46re_s * (x_46re_m * (x_46im_m * (x_46im_m * (-3.0d0))))
end function
x.im_m = Math.abs(x_46_im);
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_m) {
	return x_46_re_s * (x_46_re_m * (x_46_im_m * (x_46_im_m * -3.0)));
}
x.im_m = math.fabs(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_m):
	return x_46_re_s * (x_46_re_m * (x_46_im_m * (x_46_im_m * -3.0)))
x.im_m = abs(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_m)
	return Float64(x_46_re_s * Float64(x_46_re_m * Float64(x_46_im_m * Float64(x_46_im_m * -3.0))))
end
x.im_m = abs(x_46_im);
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_m)
	tmp = x_46_re_s * (x_46_re_m * (x_46_im_m * (x_46_im_m * -3.0)));
end
x.im_m = N[Abs[x$46$im], $MachinePrecision]
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$95$m_] := N[(x$46$re$95$s * N[(x$46$re$95$m * N[(x$46$im$95$m * N[(x$46$im$95$m * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x.im_m = \left|x.im\right|
\\
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(x.im\_m \cdot \left(x.im\_m \cdot -3\right)\right)\right)
\end{array}
Derivation
  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. Taylor expanded in x.re around 0 86.1%

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

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

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

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

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

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

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

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

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

Developer target: 99.8% 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 2024096 
(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)))