Average Error: 7.0 → 0.6
Time: 20.8s
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, \left(x.re - x.im\right) \cdot x.re, \sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right)} \cdot \left(\sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right)} \cdot \sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\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, \left(x.re - x.im\right) \cdot x.re, \sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right)} \cdot \left(\sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right)} \cdot \sqrt[3]{x.im \cdot \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right)}\right)\right)
double f(double x_re, double x_im) {
        double r7551633 = x_re;
        double r7551634 = r7551633 * r7551633;
        double r7551635 = x_im;
        double r7551636 = r7551635 * r7551635;
        double r7551637 = r7551634 - r7551636;
        double r7551638 = r7551637 * r7551633;
        double r7551639 = r7551633 * r7551635;
        double r7551640 = r7551635 * r7551633;
        double r7551641 = r7551639 + r7551640;
        double r7551642 = r7551641 * r7551635;
        double r7551643 = r7551638 - r7551642;
        return r7551643;
}

double f(double x_re, double x_im) {
        double r7551644 = x_im;
        double r7551645 = x_re;
        double r7551646 = r7551644 + r7551645;
        double r7551647 = r7551645 - r7551644;
        double r7551648 = r7551647 * r7551645;
        double r7551649 = -r7551644;
        double r7551650 = r7551649 * r7551645;
        double r7551651 = r7551650 + r7551650;
        double r7551652 = r7551644 * r7551651;
        double r7551653 = cbrt(r7551652);
        double r7551654 = r7551653 * r7551653;
        double r7551655 = r7551653 * r7551654;
        double r7551656 = fma(r7551646, r7551648, r7551655);
        return r7551656;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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-squares7.0

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

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

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

Reproduce

herbie shell --seed 2019170 +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.0 x.im))))

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