Average Error: 7.2 → 6.4
Time: 2.8s
Precision: binary64
\[\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.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - t_0 \leq -\infty:\\ \;\;\;\;{x.re}^{3} - t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x.re, x.im \cdot \left(x.im \cdot -3\right), {x.re}^{3}\right)\\ \end{array} \]
\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.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\
\mathbf{if}\;x.re \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) - t_0 \leq -\infty:\\
\;\;\;\;{x.re}^{3} - t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x.re, x.im \cdot \left(x.im \cdot -3\right), {x.re}^{3}\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.im (+ (* x.re x.im) (* x.re x.im)))))
   (if (<= (- (* x.re (- (* x.re x.re) (* x.im x.im))) t_0) (- INFINITY))
     (- (pow x.re 3.0) t_0)
     (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 (((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_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im));
	double tmp;
	if (((x_46_re * ((x_46_re * x_46_re) - (x_46_im * x_46_im))) - t_0) <= -((double) INFINITY)) {
		tmp = pow(x_46_re, 3.0) - t_0;
	} else {
		tmp = fma(x_46_re, (x_46_im * (x_46_im * -3.0)), pow(x_46_re, 3.0));
	}
	return tmp;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.2
Target0.2
Herbie6.4
\[\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 2 regimes
  2. if (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im)) < -inf.0

    1. Initial program 64.0

      \[\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. Taylor expanded around inf 51.2

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

    if -inf.0 < (-.f64 (*.f64 (-.f64 (*.f64 x.re x.re) (*.f64 x.im x.im)) x.re) (*.f64 (+.f64 (*.f64 x.re x.im) (*.f64 x.im x.re)) x.im))

    1. Initial program 3.8

      \[\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. Simplified3.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, \left(x.im \cdot x.im\right) \cdot -3, {x.re}^{3}\right)} \]
    3. Using strategy rm
    4. Applied associate-*l*_binary643.8

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

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

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

Reproduce

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