Average Error: 10.8 → 2.2
Time: 4.6s
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 -2.580140784623766 \cdot 10^{+144} \lor \neg \left(x.re \leq 1.2725287036008839 \cdot 10^{+151}\right):\\ \;\;\;\;\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(3 \cdot \left(x.re \cdot x.re\right) - 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 -2.580140784623766 \cdot 10^{+144} \lor \neg \left(x.re \leq 1.2725287036008839 \cdot 10^{+151}\right):\\
\;\;\;\;\mathsf{fma}\left(x.re + x.im, x.im \cdot \left(x.re - x.im\right), x.re \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x.im \cdot \left(3 \cdot \left(x.re \cdot x.re\right) - 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 -2.580140784623766e+144)
         (not (<= x.re 1.2725287036008839e+151)))
   (fma
    (+ x.re x.im)
    (* x.im (- x.re x.im))
    (* x.re (+ (* x.re x.im) (* x.re x.im))))
   (* x.im (- (* 3.0 (* x.re x.re)) (* 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 <= -2.580140784623766e+144) || !(x_46_re <= 1.2725287036008839e+151)) {
		tmp = fma((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 * ((3.0 * (x_46_re * x_46_re)) - (x_46_im * x_46_im));
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original10.8
Target5.4
Herbie2.2
\[\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 < -2.58014078462376613e144 or 1.2725287036008839e151 < x.re

    1. Initial program 29.9

      \[\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.3

      \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    3. Applied associate-*l*_binary648.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 \]
    4. Applied fma-def_binary648.3

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

    if -2.58014078462376613e144 < x.re < 1.2725287036008839e151

    1. Initial program 4.3

      \[\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.2

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

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

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

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

Reproduce

herbie shell --seed 2022068 
(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)))