Average Error: 7.9 → 0.2
Time: 8.2s
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, \left(-3 \cdot x.re\right) \cdot x.im, {x.re}^{3}\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, \left(-3 \cdot x.re\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r248357 = x_re;
        double r248358 = r248357 * r248357;
        double r248359 = x_im;
        double r248360 = r248359 * r248359;
        double r248361 = r248358 - r248360;
        double r248362 = r248361 * r248357;
        double r248363 = r248357 * r248359;
        double r248364 = r248359 * r248357;
        double r248365 = r248363 + r248364;
        double r248366 = r248365 * r248359;
        double r248367 = r248362 - r248366;
        return r248367;
}

double f(double x_re, double x_im) {
        double r248368 = x_im;
        double r248369 = -3.0;
        double r248370 = x_re;
        double r248371 = r248369 * r248370;
        double r248372 = r248371 * r248368;
        double r248373 = 3.0;
        double r248374 = pow(r248370, r248373);
        double r248375 = fma(r248368, r248372, r248374);
        return r248375;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.9
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.9

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

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

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

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

Reproduce

herbie shell --seed 2020046 +o rules:numerics
(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 x.im))))

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