math.cube on complex, real part

?

Percentage Accurate: 82.8% → 95.9%
Time: 10.5s
Precision: binary64
Cost: 7372

?

\[\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 \]
\[\begin{array}{l} t_0 := x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{if}\;x.re \leq -3.1 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.re \leq 6 \cdot 10^{-92}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.re\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 3.2 \cdot 10^{+170}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \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)))
(FPCore (x.re x.im)
 :precision binary64
 (let* ((t_0 (* x.re (fma x.re x.re (* x.im (* x.im -3.0))))))
   (if (<= x.re -3.1e-97)
     t_0
     (if (<= x.re 6e-92)
       (- (* x.im (* x.im (- x.re))) (* x.im (* x.re (+ x.im x.im))))
       (if (<= x.re 3.2e+170) t_0 (* x.re (* x.re x.re)))))))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
double code(double x_46_re, double x_46_im) {
	double t_0 = x_46_re * fma(x_46_re, x_46_re, (x_46_im * (x_46_im * -3.0)));
	double tmp;
	if (x_46_re <= -3.1e-97) {
		tmp = t_0;
	} else if (x_46_re <= 6e-92) {
		tmp = (x_46_im * (x_46_im * -x_46_re)) - (x_46_im * (x_46_re * (x_46_im + x_46_im)));
	} else if (x_46_re <= 3.2e+170) {
		tmp = t_0;
	} else {
		tmp = x_46_re * (x_46_re * x_46_re);
	}
	return tmp;
}
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 code(x_46_re, x_46_im)
	t_0 = Float64(x_46_re * fma(x_46_re, x_46_re, Float64(x_46_im * Float64(x_46_im * -3.0))))
	tmp = 0.0
	if (x_46_re <= -3.1e-97)
		tmp = t_0;
	elseif (x_46_re <= 6e-92)
		tmp = Float64(Float64(x_46_im * Float64(x_46_im * Float64(-x_46_re))) - Float64(x_46_im * Float64(x_46_re * Float64(x_46_im + x_46_im))));
	elseif (x_46_re <= 3.2e+170)
		tmp = t_0;
	else
		tmp = Float64(x_46_re * Float64(x_46_re * x_46_re));
	end
	return tmp
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]
code[x$46$re_, x$46$im_] := Block[{t$95$0 = N[(x$46$re * N[(x$46$re * x$46$re + N[(x$46$im * N[(x$46$im * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$46$re, -3.1e-97], t$95$0, If[LessEqual[x$46$re, 6e-92], N[(N[(x$46$im * N[(x$46$im * (-x$46$re)), $MachinePrecision]), $MachinePrecision] - N[(x$46$im * N[(x$46$re * N[(x$46$im + x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 3.2e+170], t$95$0, N[(x$46$re * N[(x$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]]]]]
\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
\begin{array}{l}
t_0 := x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\
\mathbf{if}\;x.re \leq -3.1 \cdot 10^{-97}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;x.re \leq 3.2 \cdot 10^{+170}:\\
\;\;\;\;t_0\\

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


\end{array}

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.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Target

Original82.8%
Target86.8%
Herbie95.9%
\[\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) \]

Derivation?

  1. Split input into 3 regimes
  2. if x.re < -3.10000000000000002e-97 or 6.00000000000000027e-92 < x.re < 3.19999999999999979e170

    1. Initial program 92.6%

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

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

      [Start]92.6%

      \[ \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]

      *-commutative [<=]92.6%

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

      distribute-lft-out [=>]92.6%

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

      associate-*l* [=>]92.6%

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

      *-commutative [=>]92.6%

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

      distribute-rgt-out-- [=>]94.6%

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

      associate--l- [=>]94.6%

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

      associate--l- [<=]94.6%

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

      sub-neg [=>]94.6%

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

      associate--l+ [=>]94.6%

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

      fma-udef [<=]98.5%

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

      neg-mul-1 [=>]98.5%

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

      count-2 [=>]98.5%

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

      associate-*l* [=>]98.5%

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

      distribute-rgt-out-- [=>]98.5%

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

      associate-*r* [<=]98.5%

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

      metadata-eval [=>]98.5%

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

    if -3.10000000000000002e-97 < x.re < 6.00000000000000027e-92

    1. Initial program 83.1%

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

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

      [Start]83.1%

      \[ \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 \]

      *-commutative [=>]83.1%

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

      *-commutative [=>]83.1%

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

      *-commutative [<=]83.1%

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

      distribute-lft-out [=>]83.1%

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

      \[\leadsto x.re \cdot \color{blue}{\left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(\mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right) + \mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right)\right)\right)} - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
      Step-by-step derivation

      [Start]83.1%

      \[ x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]

      prod-diff [=>]66.0%

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

      fma-neg [<=]66.0%

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

      prod-diff [=>]66.0%

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

      fma-neg [<=]66.0%

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

      associate-+l+ [=>]66.0%

      \[ x.re \cdot \color{blue}{\left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(\mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right) + \mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right)\right)\right)} - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
    4. Simplified66.0%

      \[\leadsto x.re \cdot \color{blue}{\left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + 2 \cdot \mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right)\right)} - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]
      Step-by-step derivation

      [Start]66.0%

      \[ x.re \cdot \left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(\mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right) + \mathsf{fma}\left(-x.im, x.im, x.im \cdot x.im\right)\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]

      count-2 [=>]66.0%

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

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

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

      [Start]66.0%

      \[ x.re \cdot \left(2 \cdot \left({x.im}^{2} + -1 \cdot {x.im}^{2}\right) - {x.im}^{2}\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]

      fma-neg [=>]66.0%

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

      distribute-rgt1-in [=>]66.0%

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

      metadata-eval [=>]66.0%

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

      mul0-lft [=>]83.1%

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

      fma-udef [=>]83.1%

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

      metadata-eval [=>]83.1%

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

      distribute-lft-in [=>]83.1%

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

      mul0-rgt [=>]83.1%

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

      distribute-rgt-neg-in [<=]83.1%

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

      sub-neg [<=]83.1%

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

      neg-sub0 [<=]83.1%

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

      *-commutative [=>]83.1%

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

      distribute-rgt-neg-in [=>]83.1%

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

      unpow2 [=>]83.1%

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

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

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

      [Start]83.1%

      \[ -1 \cdot \left(x.re \cdot {x.im}^{2}\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right) \]

      mul-1-neg [=>]83.1%

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

      *-commutative [<=]83.1%

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

      unpow2 [=>]83.1%

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

      associate-*r* [<=]99.6%

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

      distribute-rgt-neg-in [=>]99.6%

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

      *-commutative [=>]99.6%

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

      distribute-rgt-neg-in [=>]99.6%

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

    if 3.19999999999999979e170 < x.re

    1. Initial program 54.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. Simplified75.0%

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

      [Start]54.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 \]

      *-commutative [<=]54.2%

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

      distribute-lft-out [=>]54.2%

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

      associate-*l* [=>]54.2%

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

      *-commutative [=>]54.2%

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

      distribute-rgt-out-- [=>]70.8%

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

      associate--l- [=>]70.8%

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

      associate--l- [<=]70.8%

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

      sub-neg [=>]70.8%

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

      associate--l+ [=>]70.8%

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

      fma-udef [<=]75.0%

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

      neg-mul-1 [=>]75.0%

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

      count-2 [=>]75.0%

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

      associate-*l* [=>]75.0%

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

      distribute-rgt-out-- [=>]75.0%

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

      associate-*r* [<=]75.0%

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

      metadata-eval [=>]75.0%

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

      \[\leadsto x.re \cdot \color{blue}{{x.re}^{2}} \]
    4. Simplified95.8%

      \[\leadsto x.re \cdot \color{blue}{\left(x.re \cdot x.re\right)} \]
      Step-by-step derivation

      [Start]95.8%

      \[ x.re \cdot {x.re}^{2} \]

      unpow2 [=>]95.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \leq -3.1 \cdot 10^{-97}:\\ \;\;\;\;x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{elif}\;x.re \leq 6 \cdot 10^{-92}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.re\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 3.2 \cdot 10^{+170}:\\ \;\;\;\;x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy95.9%
Cost7372
\[\begin{array}{l} t_0 := x.re \cdot \mathsf{fma}\left(x.re, x.re, x.im \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{if}\;x.re \leq -3.1 \cdot 10^{-97}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.re \leq 6 \cdot 10^{-92}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.re\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\ \mathbf{elif}\;x.re \leq 3.2 \cdot 10^{+170}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]
Alternative 2
Accuracy94.6%
Cost1161
\[\begin{array}{l} \mathbf{if}\;x.im \leq -8 \cdot 10^{+153} \lor \neg \left(x.im \leq 6.4 \cdot 10^{+89}\right):\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.re\right)\right) - x.im \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot \left(x.im \cdot -3\right) + x.re \cdot x.re\right)\\ \end{array} \]
Alternative 3
Accuracy75.7%
Cost978
\[\begin{array}{l} \mathbf{if}\;x.im \leq -3.2 \cdot 10^{+102} \lor \neg \left(x.im \leq -4.5 \cdot 10^{+72} \lor \neg \left(x.im \leq -7.5 \cdot 10^{-26}\right) \land x.im \leq 3.1 \cdot 10^{+66}\right):\\ \;\;\;\;-3 \cdot \left(x.re \cdot \left(x.im \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]
Alternative 4
Accuracy75.6%
Cost976
\[\begin{array}{l} t_0 := -3 \cdot \left(x.re \cdot \left(x.im \cdot x.im\right)\right)\\ t_1 := x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{if}\;x.im \leq -1.1 \cdot 10^{+102}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq -4.4 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x.im \leq -5 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq 5.5 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(-3 \cdot \left(x.im \cdot x.im\right)\right)\\ \end{array} \]
Alternative 5
Accuracy75.6%
Cost976
\[\begin{array}{l} t_0 := x.re \cdot \left(x.re \cdot x.re\right)\\ \mathbf{if}\;x.im \leq -9.2 \cdot 10^{+101}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot \left(x.im \cdot -3\right)\right)\\ \mathbf{elif}\;x.im \leq -2.4 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x.im \leq -9.5 \cdot 10^{-23}:\\ \;\;\;\;-3 \cdot \left(x.re \cdot \left(x.im \cdot x.im\right)\right)\\ \mathbf{elif}\;x.im \leq 8.2 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(-3 \cdot \left(x.im \cdot x.im\right)\right)\\ \end{array} \]
Alternative 6
Accuracy89.8%
Cost836
\[\begin{array}{l} \mathbf{if}\;x.re \leq 1.7 \cdot 10^{+151}:\\ \;\;\;\;x.re \cdot \left(x.im \cdot \left(x.im \cdot -3\right) + x.re \cdot x.re\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]
Alternative 7
Accuracy70.9%
Cost649
\[\begin{array}{l} \mathbf{if}\;x.im \leq -1.1 \cdot 10^{+104} \lor \neg \left(x.im \leq 4.6 \cdot 10^{+89}\right):\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.re\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]
Alternative 8
Accuracy58.8%
Cost320
\[x.re \cdot \left(x.re \cdot x.re\right) \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"
  :precision binary64

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