Average Error: 6.9 → 0.2
Time: 31.7s
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 \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\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(-x.im, x.re \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r5776180 = x_re;
        double r5776181 = r5776180 * r5776180;
        double r5776182 = x_im;
        double r5776183 = r5776182 * r5776182;
        double r5776184 = r5776181 - r5776183;
        double r5776185 = r5776184 * r5776180;
        double r5776186 = r5776180 * r5776182;
        double r5776187 = r5776182 * r5776180;
        double r5776188 = r5776186 + r5776187;
        double r5776189 = r5776188 * r5776182;
        double r5776190 = r5776185 - r5776189;
        return r5776190;
}

double f(double x_re, double x_im) {
        double r5776191 = x_im;
        double r5776192 = -r5776191;
        double r5776193 = x_re;
        double r5776194 = r5776193 * r5776191;
        double r5776195 = r5776194 + r5776194;
        double r5776196 = r5776191 * r5776195;
        double r5776197 = fma(r5776192, r5776195, r5776196);
        double r5776198 = r5776191 + r5776193;
        double r5776199 = r5776193 - r5776191;
        double r5776200 = r5776199 * r5776193;
        double r5776201 = r5776192 * r5776195;
        double r5776202 = fma(r5776198, r5776200, r5776201);
        double r5776203 = r5776197 + r5776202;
        return r5776203;
}

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 prod-diff0.2

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

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

Reproduce

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