Average Error: 11.1 → 1.9
Time: 3.7s
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} t_0 := \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\\ \mathbf{if}\;x.im \leq -5.179057929550085 \cdot 10^{+106}:\\ \;\;\;\;\begin{array}{l} t_1 := x.im \cdot t_0\\ \sqrt[3]{t_1 \cdot t_1} \cdot \sqrt[3]{t_1} \end{array}\\ \mathbf{elif}\;x.im \leq 3.841500425837586 \cdot 10^{+101}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt[3]{t_0}\\ t_2 \cdot \left(x.im \cdot \left(t_2 \cdot t_2\right)\right) \end{array}\\ \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}
t_0 := \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\\
\mathbf{if}\;x.im \leq -5.179057929550085 \cdot 10^{+106}:\\
\;\;\;\;\begin{array}{l}
t_1 := x.im \cdot t_0\\
\sqrt[3]{t_1 \cdot t_1} \cdot \sqrt[3]{t_1}
\end{array}\\

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

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt[3]{t_0}\\
t_2 \cdot \left(x.im \cdot \left(t_2 \cdot t_2\right)\right)
\end{array}\\


\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
 (let* ((t_0 (fma x.re (* x.re 3.0) (- (* x.im x.im)))))
   (if (<= x.im -5.179057929550085e+106)
     (let* ((t_1 (* x.im t_0))) (* (cbrt (* t_1 t_1)) (cbrt t_1)))
     (if (<= x.im 3.841500425837586e+101)
       (- (* 3.0 (* x.re (* x.im x.re))) (pow x.im 3.0))
       (let* ((t_2 (cbrt t_0))) (* t_2 (* x.im (* t_2 t_2))))))))
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 t_0 = fma(x_46_re, (x_46_re * 3.0), -(x_46_im * x_46_im));
	double tmp;
	if (x_46_im <= -5.179057929550085e+106) {
		double t_1_1 = x_46_im * t_0;
		tmp = cbrt(t_1_1 * t_1_1) * cbrt(t_1_1);
	} else if (x_46_im <= 3.841500425837586e+101) {
		tmp = (3.0 * (x_46_re * (x_46_im * x_46_re))) - pow(x_46_im, 3.0);
	} else {
		double t_2 = cbrt(t_0);
		tmp = t_2 * (x_46_im * (t_2 * t_2));
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original11.1
Target5.6
Herbie1.9
\[\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 3 regimes
  2. if x.im < -5.1790579295500851e106

    1. Initial program 22.8

      \[\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. Simplified5.6

      \[\leadsto \color{blue}{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \]
    3. Applied add-cube-cbrt_binary645.6

      \[\leadsto \color{blue}{\left(\sqrt[3]{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \cdot \sqrt[3]{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}\right) \cdot \sqrt[3]{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}} \]
    4. Applied cbrt-unprod_binary645.6

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

    if -5.1790579295500851e106 < x.im < 3.84150042583758608e101

    1. Initial program 5.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. Simplified5.9

      \[\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.im around 0 5.9

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

      \[\leadsto 3 \cdot \left(\color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im\right) - {x.im}^{3} \]
    5. Applied associate-*l*_binary640.3

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

    if 3.84150042583758608e101 < x.im

    1. Initial program 20.1

      \[\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. Simplified4.9

      \[\leadsto \color{blue}{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \]
    3. Applied add-cube-cbrt_binary644.9

      \[\leadsto x.im \cdot \color{blue}{\left(\left(\sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}\right) \cdot \sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}\right)} \]
    4. Applied associate-*r*_binary644.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.im \leq -5.179057929550085 \cdot 10^{+106}:\\ \;\;\;\;\sqrt[3]{\left(x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\right) \cdot \left(x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)\right)} \cdot \sqrt[3]{x.im \cdot \mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}\\ \mathbf{elif}\;x.im \leq 3.841500425837586 \cdot 10^{+101}:\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.im \cdot x.re\right)\right) - {x.im}^{3}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \cdot \left(x.im \cdot \left(\sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)} \cdot \sqrt[3]{\mathsf{fma}\left(x.re, x.re \cdot 3, -x.im \cdot x.im\right)}\right)\right)\\ \end{array} \]

Reproduce

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