Average Error: 6.9 → 0.2
Time: 18.1s
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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot 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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r1983428 = x_re;
        double r1983429 = r1983428 * r1983428;
        double r1983430 = x_im;
        double r1983431 = r1983430 * r1983430;
        double r1983432 = r1983429 - r1983431;
        double r1983433 = r1983432 * r1983428;
        double r1983434 = r1983428 * r1983430;
        double r1983435 = r1983430 * r1983428;
        double r1983436 = r1983434 + r1983435;
        double r1983437 = r1983436 * r1983430;
        double r1983438 = r1983433 - r1983437;
        return r1983438;
}

double f(double x_re, double x_im) {
        double r1983439 = x_im;
        double r1983440 = x_re;
        double r1983441 = r1983439 + r1983440;
        double r1983442 = r1983440 - r1983439;
        double r1983443 = r1983442 * r1983440;
        double r1983444 = -r1983439;
        double r1983445 = r1983440 * r1983439;
        double r1983446 = r1983445 + r1983445;
        double r1983447 = r1983444 * r1983446;
        double r1983448 = fma(r1983441, r1983443, r1983447);
        return r1983448;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.9
Target0.2
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 6.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. Using strategy rm
  3. Applied difference-of-squares6.9

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

    \[\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(\left(x.re + x.im\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right)}\]
  7. Simplified0.2

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

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

Reproduce

herbie shell --seed 2019133 +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)))