Average Error: 7.2 → 0.2
Time: 24.8s
Precision: 64
\[\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\]
\[\mathsf{fma}\left(x.im + x.re, x.re \cdot x.re - x.re \cdot x.im, \left(x.re \cdot x.im\right) \cdot \left(-\left(x.im + x.im\right)\right)\right)\]
\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
\mathsf{fma}\left(x.im + x.re, x.re \cdot x.re - x.re \cdot x.im, \left(x.re \cdot x.im\right) \cdot \left(-\left(x.im + x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r9204998 = x_re;
        double r9204999 = r9204998 * r9204998;
        double r9205000 = x_im;
        double r9205001 = r9205000 * r9205000;
        double r9205002 = r9204999 - r9205001;
        double r9205003 = r9205002 * r9204998;
        double r9205004 = r9204998 * r9205000;
        double r9205005 = r9205000 * r9204998;
        double r9205006 = r9205004 + r9205005;
        double r9205007 = r9205006 * r9205000;
        double r9205008 = r9205003 - r9205007;
        return r9205008;
}

double f(double x_re, double x_im) {
        double r9205009 = x_im;
        double r9205010 = x_re;
        double r9205011 = r9205009 + r9205010;
        double r9205012 = r9205010 * r9205010;
        double r9205013 = r9205010 * r9205009;
        double r9205014 = r9205012 - r9205013;
        double r9205015 = r9205009 + r9205009;
        double r9205016 = -r9205015;
        double r9205017 = r9205013 * r9205016;
        double r9205018 = fma(r9205011, r9205014, r9205017);
        return r9205018;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.2
Target0.3
Herbie0.2
\[\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. Initial program 7.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. Using strategy rm
  3. Applied difference-of-squares7.2

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

    \[\leadsto \color{blue}{\left(x.re + x.im\right) \cdot \left(\left(x.re - x.im\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  5. Using strategy rm
  6. Applied fma-neg0.2

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

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

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

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

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

Reproduce

herbie shell --seed 2019168 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"

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

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