Average Error: 7.4 → 0.2
Time: 15.4s
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.re \cdot \left(-x.im\right), x.im \cdot 3, {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.re \cdot \left(-x.im\right), x.im \cdot 3, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r198365 = x_re;
        double r198366 = r198365 * r198365;
        double r198367 = x_im;
        double r198368 = r198367 * r198367;
        double r198369 = r198366 - r198368;
        double r198370 = r198369 * r198365;
        double r198371 = r198365 * r198367;
        double r198372 = r198367 * r198365;
        double r198373 = r198371 + r198372;
        double r198374 = r198373 * r198367;
        double r198375 = r198370 - r198374;
        return r198375;
}

double f(double x_re, double x_im) {
        double r198376 = x_re;
        double r198377 = x_im;
        double r198378 = -r198377;
        double r198379 = r198376 * r198378;
        double r198380 = 3.0;
        double r198381 = r198377 * r198380;
        double r198382 = pow(r198376, r198380);
        double r198383 = fma(r198379, r198381, r198382);
        return r198383;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.4
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 7.4

    \[\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.re \cdot x.im, 3 \cdot x.im, {x.re}^{3}\right)}\]
  3. Final simplification0.2

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

Reproduce

herbie shell --seed 2019179 +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.0 x.im))))

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