Average Error: 6.6 → 0.2
Time: 23.9s
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, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right) \cdot x.im\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, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right) \cdot x.im\right)
double f(double x_re, double x_im) {
        double r6153339 = x_re;
        double r6153340 = r6153339 * r6153339;
        double r6153341 = x_im;
        double r6153342 = r6153341 * r6153341;
        double r6153343 = r6153340 - r6153342;
        double r6153344 = r6153343 * r6153339;
        double r6153345 = r6153339 * r6153341;
        double r6153346 = r6153341 * r6153339;
        double r6153347 = r6153345 + r6153346;
        double r6153348 = r6153347 * r6153341;
        double r6153349 = r6153344 - r6153348;
        return r6153349;
}

double f(double x_re, double x_im) {
        double r6153350 = x_im;
        double r6153351 = x_re;
        double r6153352 = r6153350 + r6153351;
        double r6153353 = r6153351 - r6153350;
        double r6153354 = r6153353 * r6153351;
        double r6153355 = -r6153350;
        double r6153356 = r6153355 * r6153351;
        double r6153357 = r6153356 + r6153356;
        double r6153358 = r6153357 * r6153350;
        double r6153359 = fma(r6153352, r6153354, r6153358);
        return r6153359;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.6
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 6.6

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

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

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

Reproduce

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