Average Error: 6.8 → 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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot 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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r2115200 = x_re;
        double r2115201 = r2115200 * r2115200;
        double r2115202 = x_im;
        double r2115203 = r2115202 * r2115202;
        double r2115204 = r2115201 - r2115203;
        double r2115205 = r2115204 * r2115200;
        double r2115206 = r2115200 * r2115202;
        double r2115207 = r2115202 * r2115200;
        double r2115208 = r2115206 + r2115207;
        double r2115209 = r2115208 * r2115202;
        double r2115210 = r2115205 - r2115209;
        return r2115210;
}

double f(double x_re, double x_im) {
        double r2115211 = x_im;
        double r2115212 = x_re;
        double r2115213 = r2115211 + r2115212;
        double r2115214 = r2115212 - r2115211;
        double r2115215 = r2115214 * r2115212;
        double r2115216 = -r2115211;
        double r2115217 = r2115212 * r2115211;
        double r2115218 = r2115217 + r2115217;
        double r2115219 = r2115216 * r2115218;
        double r2115220 = fma(r2115213, r2115215, r2115219);
        return r2115220;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

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

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

Reproduce

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