Average Error: 11.5 → 2.1
Time: 3.1s
Precision: binary64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
\[\begin{array}{l} \mathbf{if}\;x.re \leq -3.273291574359745 \cdot 10^{+164} \lor \neg \left(x.re \leq 8.978711195291429 \cdot 10^{+151}\right):\\ \;\;\;\;\left(x.re + x.im\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right) + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\\ \end{array} \]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\begin{array}{l}
\mathbf{if}\;x.re \leq -3.273291574359745 \cdot 10^{+164} \lor \neg \left(x.re \leq 8.978711195291429 \cdot 10^{+151}\right):\\
\;\;\;\;\left(x.re + x.im\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right) + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\

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


\end{array}
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.re -3.273291574359745e+164)
         (not (<= x.re 8.978711195291429e+151)))
   (+
    (* (+ x.re x.im) (* x.im (- x.re x.im)))
    (* x.re (+ (* x.re x.im) (* x.re x.im))))
   (* x.im (fma x.re (* x.re 3.0) (- (* x.im 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_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_re <= -3.273291574359745e+164) || !(x_46_re <= 8.978711195291429e+151)) {
		tmp = ((x_46_re + x_46_im) * (x_46_im * (x_46_re - x_46_im))) + (x_46_re * ((x_46_re * x_46_im) + (x_46_re * x_46_im)));
	} else {
		tmp = x_46_im * fma(x_46_re, (x_46_re * 3.0), -(x_46_im * x_46_im));
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original11.5
Target5.5
Herbie2.1
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right) \]

Derivation

  1. Split input into 2 regimes
  2. if x.re < -3.27329157435974482e164 or 8.97871119529142927e151 < x.re

    1. Initial program 31.5

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Applied difference-of-squares_binary6422.6

      \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied associate-*l*_binary647.4

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

    if -3.27329157435974482e164 < x.re < 8.97871119529142927e151

    1. Initial program 5.0

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

      \[\leadsto \color{blue}{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \]
    3. Applied *-un-lft-identity_binary640.4

      \[\leadsto x.im \cdot \color{blue}{\left(1 \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification2.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \leq -3.273291574359745 \cdot 10^{+164} \lor \neg \left(x.re \leq 8.978711195291429 \cdot 10^{+151}\right):\\ \;\;\;\;\left(x.re + x.im\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right) + x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\\ \end{array} \]

Reproduce

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

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))