Average Error: 6.7 → 0.5
Time: 25.0s
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(\left(x.re + x.re\right) \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(\left(x.re + x.re\right) \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 r7477109 = x_re;
        double r7477110 = r7477109 * r7477109;
        double r7477111 = x_im;
        double r7477112 = r7477111 * r7477111;
        double r7477113 = r7477110 - r7477112;
        double r7477114 = r7477113 * r7477111;
        double r7477115 = r7477109 * r7477111;
        double r7477116 = r7477111 * r7477109;
        double r7477117 = r7477115 + r7477116;
        double r7477118 = r7477117 * r7477109;
        double r7477119 = r7477114 + r7477118;
        return r7477119;
}

double f(double x_re, double x_im) {
        double r7477120 = x_im;
        double r7477121 = x_re;
        double r7477122 = r7477120 + r7477121;
        double r7477123 = r7477121 - r7477120;
        double r7477124 = r7477123 * r7477120;
        double r7477125 = r7477121 + r7477121;
        double r7477126 = r7477125 * r7477120;
        double r7477127 = cbrt(r7477121);
        double r7477128 = r7477126 * r7477127;
        double r7477129 = r7477128 * r7477127;
        double r7477130 = r7477129 * r7477127;
        double r7477131 = fma(r7477122, r7477124, r7477130);
        return r7477131;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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