Average Error: 6.7 → 0.2
Time: 17.3s
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, x.im \cdot \left(x.re \cdot \left(-x.im\right) + x.re \cdot \left(-x.im\right)\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, \left(x.re - x.im\right) \cdot x.re, x.im \cdot \left(x.re \cdot \left(-x.im\right) + x.re \cdot \left(-x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r2864180 = x_re;
        double r2864181 = r2864180 * r2864180;
        double r2864182 = x_im;
        double r2864183 = r2864182 * r2864182;
        double r2864184 = r2864181 - r2864183;
        double r2864185 = r2864184 * r2864180;
        double r2864186 = r2864180 * r2864182;
        double r2864187 = r2864182 * r2864180;
        double r2864188 = r2864186 + r2864187;
        double r2864189 = r2864188 * r2864182;
        double r2864190 = r2864185 - r2864189;
        return r2864190;
}

double f(double x_re, double x_im) {
        double r2864191 = x_im;
        double r2864192 = x_re;
        double r2864193 = r2864191 + r2864192;
        double r2864194 = r2864192 - r2864191;
        double r2864195 = r2864194 * r2864192;
        double r2864196 = -r2864191;
        double r2864197 = r2864192 * r2864196;
        double r2864198 = r2864197 + r2864197;
        double r2864199 = r2864191 * r2864198;
        double r2864200 = fma(r2864193, r2864195, r2864199);
        return r2864200;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

    \[\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}{-x.im \cdot \left(x.re \cdot x.im + x.re \cdot 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, x.im \cdot \left(x.re \cdot \left(-x.im\right) + x.re \cdot \left(-x.im\right)\right)\right)\]

Reproduce

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