math.cube on complex, real part

Percentage Accurate: 82.1% → 87.8%
Time: 7.2s
Alternatives: 5
Speedup: 1.0×

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 5 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.1% 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: 87.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right) \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (fma (* x.re x.im) (* x.im -3.0) (pow x.re 3.0)))
double code(double x_46_re, double x_46_im) {
	return fma((x_46_re * x_46_im), (x_46_im * -3.0), pow(x_46_re, 3.0));
}
function code(x_46_re, x_46_im)
	return fma(Float64(x_46_re * x_46_im), Float64(x_46_im * -3.0), (x_46_re ^ 3.0))
end
code[x$46$re_, x$46$im_] := N[(N[(x$46$re * x$46$im), $MachinePrecision] * N[(x$46$im * -3.0), $MachinePrecision] + N[Power[x$46$re, 3.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x.re \cdot x.im, x.im \cdot -3, {x.re}^{3}\right)
\end{array}
Derivation
  1. Initial program 83.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. Simplified83.0%

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 0.2× speedup?

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

\\
{x.re}^{3} + \left(x.re \cdot x.im\right) \cdot \left(x.im \cdot -3\right)
\end{array}
Derivation
  1. Initial program 83.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. Simplified83.0%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 85.1% accurate, 1.0× speedup?

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

\\
x.re \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)
\end{array}
Derivation
  1. Initial program 83.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. Step-by-step derivation
    1. difference-of-squares80.1%

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

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

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

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

Alternative 4: 62.8% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := x.re \cdot \left(x.re - x.im\right)\\
x.re \cdot t\_0 + x.im \cdot t\_0
\end{array}
\end{array}
Derivation
  1. Initial program 83.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. Step-by-step derivation
    1. *-commutative83.7%

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

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

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \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}} \]
    4. +-inverses0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \]
    5. metadata-eval0.0%

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

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\log 1}{\color{blue}{0}} \]
    7. metadata-eval0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\log 1}{\color{blue}{\log 1}} \]
    8. associate-*r/0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{\frac{x.im \cdot \log 1}{\log 1}} \]
    9. metadata-eval0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \frac{x.im \cdot \color{blue}{0}}{\log 1} \]
    10. metadata-eval0.0%

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

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

    \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{0} \]
  6. Step-by-step derivation
    1. difference-of-squares80.1%

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

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

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

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

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

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

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

    \[\leadsto \left(\left(x.re \cdot \left(x.re - x.im\right)\right) \cdot x.re + \color{blue}{x.im \cdot \left(-1 \cdot \left(x.im \cdot x.re\right) + {x.re}^{2}\right)}\right) - 0 \]
  11. Step-by-step derivation
    1. neg-mul-161.1%

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

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

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

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

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

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

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

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

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

Alternative 5: 78.1% accurate, 2.1× speedup?

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

\\
x.re \cdot \left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)
\end{array}
Derivation
  1. Initial program 83.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. Step-by-step derivation
    1. *-commutative83.7%

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

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

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \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}} \]
    4. +-inverses0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\color{blue}{0}}{x.re \cdot x.im - x.re \cdot x.im} \]
    5. metadata-eval0.0%

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

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\log 1}{\color{blue}{0}} \]
    7. metadata-eval0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - x.im \cdot \frac{\log 1}{\color{blue}{\log 1}} \]
    8. associate-*r/0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{\frac{x.im \cdot \log 1}{\log 1}} \]
    9. metadata-eval0.0%

      \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \frac{x.im \cdot \color{blue}{0}}{\log 1} \]
    10. metadata-eval0.0%

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

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

    \[\leadsto \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \color{blue}{0} \]
  6. Step-by-step derivation
    1. difference-of-squares80.1%

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

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

    \[\leadsto \color{blue}{\left(\left(x.re - x.im\right) \cdot \left(x.re + x.im\right)\right)} \cdot x.re - 0 \]
  8. Final simplification80.1%

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

Developer target: 87.3% 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 2024066 
(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)))