Average Error: 6.7 → 0.7
Time: 15.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, \sqrt[3]{\left(x.re - x.im\right) \cdot x.re} \cdot \left(\sqrt[3]{\left(x.re - x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re - x.im\right) \cdot x.re}\right), 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, \sqrt[3]{\left(x.re - x.im\right) \cdot x.re} \cdot \left(\sqrt[3]{\left(x.re - x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re - x.im\right) \cdot x.re}\right), 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 r3255980 = x_re;
        double r3255981 = r3255980 * r3255980;
        double r3255982 = x_im;
        double r3255983 = r3255982 * r3255982;
        double r3255984 = r3255981 - r3255983;
        double r3255985 = r3255984 * r3255980;
        double r3255986 = r3255980 * r3255982;
        double r3255987 = r3255982 * r3255980;
        double r3255988 = r3255986 + r3255987;
        double r3255989 = r3255988 * r3255982;
        double r3255990 = r3255985 - r3255989;
        return r3255990;
}

double f(double x_re, double x_im) {
        double r3255991 = x_im;
        double r3255992 = x_re;
        double r3255993 = r3255991 + r3255992;
        double r3255994 = r3255992 - r3255991;
        double r3255995 = r3255994 * r3255992;
        double r3255996 = cbrt(r3255995);
        double r3255997 = r3255996 * r3255996;
        double r3255998 = r3255996 * r3255997;
        double r3255999 = -r3255991;
        double r3256000 = r3255992 * r3255999;
        double r3256001 = r3256000 + r3256000;
        double r3256002 = r3255991 * r3256001;
        double r3256003 = fma(r3255993, r3255998, r3256002);
        return r3256003;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.7
Target0.3
Herbie0.7
\[\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}{\left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)\]
  8. Using strategy rm
  9. Applied add-cube-cbrt0.7

    \[\leadsto \mathsf{fma}\left(x.re + x.im, \color{blue}{\left(\sqrt[3]{\left(x.re - x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re - x.im\right) \cdot x.re}\right) \cdot \sqrt[3]{\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)\]
  10. Final simplification0.7

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

Reproduce

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