Average Error: 7.2 → 0.2
Time: 19.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(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {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.im\right) \cdot x.re, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r125424 = x_re;
        double r125425 = r125424 * r125424;
        double r125426 = x_im;
        double r125427 = r125426 * r125426;
        double r125428 = r125425 - r125427;
        double r125429 = r125428 * r125424;
        double r125430 = r125424 * r125426;
        double r125431 = r125426 * r125424;
        double r125432 = r125430 + r125431;
        double r125433 = r125432 * r125426;
        double r125434 = r125429 - r125433;
        return r125434;
}

double f(double x_re, double x_im) {
        double r125435 = x_im;
        double r125436 = -3.0;
        double r125437 = r125436 * r125435;
        double r125438 = x_re;
        double r125439 = r125437 * r125438;
        double r125440 = 3.0;
        double r125441 = pow(r125438, r125440);
        double r125442 = fma(r125435, r125439, r125441);
        return r125442;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

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

Reproduce

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