Average Error: 6.9 → 0.5
Time: 29.0s
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.re - x.im, \left(x.im + x.re\right) \cdot x.re, \left(\left(-2 \cdot x.im\right) \cdot \left(\sqrt[3]{x.im} \cdot x.re\right)\right) \cdot \left(\sqrt[3]{x.im} \cdot \sqrt[3]{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.re - x.im, \left(x.im + x.re\right) \cdot x.re, \left(\left(-2 \cdot x.im\right) \cdot \left(\sqrt[3]{x.im} \cdot x.re\right)\right) \cdot \left(\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right)\right)
double f(double x_re, double x_im) {
        double r6020970 = x_re;
        double r6020971 = r6020970 * r6020970;
        double r6020972 = x_im;
        double r6020973 = r6020972 * r6020972;
        double r6020974 = r6020971 - r6020973;
        double r6020975 = r6020974 * r6020970;
        double r6020976 = r6020970 * r6020972;
        double r6020977 = r6020972 * r6020970;
        double r6020978 = r6020976 + r6020977;
        double r6020979 = r6020978 * r6020972;
        double r6020980 = r6020975 - r6020979;
        return r6020980;
}

double f(double x_re, double x_im) {
        double r6020981 = x_re;
        double r6020982 = x_im;
        double r6020983 = r6020981 - r6020982;
        double r6020984 = r6020982 + r6020981;
        double r6020985 = r6020984 * r6020981;
        double r6020986 = -2.0;
        double r6020987 = r6020986 * r6020982;
        double r6020988 = cbrt(r6020982);
        double r6020989 = r6020988 * r6020981;
        double r6020990 = r6020987 * r6020989;
        double r6020991 = r6020988 * r6020988;
        double r6020992 = r6020990 * r6020991;
        double r6020993 = fma(r6020983, r6020985, r6020992);
        return r6020993;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.9
Target0.2
Herbie0.5
\[\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. Taylor expanded around -inf 6.8

    \[\leadsto \color{blue}{\left({x.re}^{3} - {x.im}^{2} \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  3. Simplified0.2

    \[\leadsto \color{blue}{\left(x.re - x.im\right) \cdot \left(x.re \cdot \left(x.re + x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  4. Using strategy rm
  5. Applied fma-neg0.2

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

    \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \color{blue}{\left(-x.im\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)}\right)\]
  7. Using strategy rm
  8. Applied add-cube-cbrt0.5

    \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \left(-\color{blue}{\left(\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right) \cdot \sqrt[3]{x.im}}\right) \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)\]
  9. Applied distribute-rgt-neg-in0.5

    \[\leadsto \mathsf{fma}\left(x.re - x.im, x.re \cdot \left(x.re + x.im\right), \color{blue}{\left(\left(\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right) \cdot \left(-\sqrt[3]{x.im}\right)\right)} \cdot \left(x.re \cdot \left(x.im + x.im\right)\right)\right)\]
  10. Applied associate-*l*0.5

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

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

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

Reproduce

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