Average Error: 7.0 → 0.6
Time: 39.4s
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(\left(x.re - x.im\right) \cdot x.im, x.im + x.re, \sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re} \cdot \left(\sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re}\right)\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(\left(x.re - x.im\right) \cdot x.im, x.im + x.re, \sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re} \cdot \left(\sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re} \cdot \sqrt[3]{\left(x.re \cdot x.im + x.re \cdot x.im\right) \cdot x.re}\right)\right)
double f(double x_re, double x_im) {
        double r7627630 = x_re;
        double r7627631 = r7627630 * r7627630;
        double r7627632 = x_im;
        double r7627633 = r7627632 * r7627632;
        double r7627634 = r7627631 - r7627633;
        double r7627635 = r7627634 * r7627632;
        double r7627636 = r7627630 * r7627632;
        double r7627637 = r7627632 * r7627630;
        double r7627638 = r7627636 + r7627637;
        double r7627639 = r7627638 * r7627630;
        double r7627640 = r7627635 + r7627639;
        return r7627640;
}

double f(double x_re, double x_im) {
        double r7627641 = x_re;
        double r7627642 = x_im;
        double r7627643 = r7627641 - r7627642;
        double r7627644 = r7627643 * r7627642;
        double r7627645 = r7627642 + r7627641;
        double r7627646 = r7627641 * r7627642;
        double r7627647 = r7627646 + r7627646;
        double r7627648 = r7627647 * r7627641;
        double r7627649 = cbrt(r7627648);
        double r7627650 = r7627649 * r7627649;
        double r7627651 = r7627649 * r7627650;
        double r7627652 = fma(r7627644, r7627645, r7627651);
        return r7627652;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.0
Target0.2
Herbie0.6
\[\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. Taylor expanded around 0 7.0

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

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

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

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

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

Reproduce

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