Average Error: 7.9 → 0.2
Time: 8.5s
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 r224341 = x_re;
        double r224342 = r224341 * r224341;
        double r224343 = x_im;
        double r224344 = r224343 * r224343;
        double r224345 = r224342 - r224344;
        double r224346 = r224345 * r224341;
        double r224347 = r224341 * r224343;
        double r224348 = r224343 * r224341;
        double r224349 = r224347 + r224348;
        double r224350 = r224349 * r224343;
        double r224351 = r224346 - r224350;
        return r224351;
}

double f(double x_re, double x_im) {
        double r224352 = x_im;
        double r224353 = -3.0;
        double r224354 = x_re;
        double r224355 = r224353 * r224354;
        double r224356 = r224355 * r224352;
        double r224357 = 3.0;
        double r224358 = pow(r224354, r224357);
        double r224359 = fma(r224352, r224356, r224358);
        return r224359;
}

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)))