Average Error: 7.0 → 0.5
Time: 19.5s
Precision: 64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[\mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.im, \left(\left(\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot \sqrt[3]{x.re}\right) \cdot \sqrt[3]{x.re}\right) \cdot \sqrt[3]{x.re}\right)\]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.im, \left(\left(\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot \sqrt[3]{x.re}\right) \cdot \sqrt[3]{x.re}\right) \cdot \sqrt[3]{x.re}\right)
double f(double x_re, double x_im) {
        double r3648932 = x_re;
        double r3648933 = r3648932 * r3648932;
        double r3648934 = x_im;
        double r3648935 = r3648934 * r3648934;
        double r3648936 = r3648933 - r3648935;
        double r3648937 = r3648936 * r3648934;
        double r3648938 = r3648932 * r3648934;
        double r3648939 = r3648934 * r3648932;
        double r3648940 = r3648938 + r3648939;
        double r3648941 = r3648940 * r3648932;
        double r3648942 = r3648937 + r3648941;
        return r3648942;
}

double f(double x_re, double x_im) {
        double r3648943 = x_im;
        double r3648944 = x_re;
        double r3648945 = r3648943 + r3648944;
        double r3648946 = r3648944 - r3648943;
        double r3648947 = r3648946 * r3648943;
        double r3648948 = r3648944 * r3648943;
        double r3648949 = r3648948 + r3648948;
        double r3648950 = cbrt(r3648944);
        double r3648951 = r3648949 * r3648950;
        double r3648952 = r3648951 * r3648950;
        double r3648953 = r3648952 * r3648950;
        double r3648954 = fma(r3648945, r3648947, r3648953);
        return r3648954;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.0
Target0.2
Herbie0.5
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)\]

Derivation

  1. Initial program 7.0

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Using strategy rm
  3. Applied difference-of-squares7.0

    \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  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.im\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  5. Using strategy rm
  6. Applied fma-def0.2

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

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

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

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

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

Reproduce

herbie shell --seed 2019135 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"

  :herbie-target
  (+ (* (* x.re x.im) (* 2 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))