Average Error: 7.5 → 0.2
Time: 13.8s
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 \cdot x.im\right) \cdot 3, x.re, -{x.im}^{3}\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 \cdot x.im\right) \cdot 3, x.re, -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r363638 = x_re;
        double r363639 = r363638 * r363638;
        double r363640 = x_im;
        double r363641 = r363640 * r363640;
        double r363642 = r363639 - r363641;
        double r363643 = r363642 * r363640;
        double r363644 = r363638 * r363640;
        double r363645 = r363640 * r363638;
        double r363646 = r363644 + r363645;
        double r363647 = r363646 * r363638;
        double r363648 = r363643 + r363647;
        return r363648;
}

double f(double x_re, double x_im) {
        double r363649 = x_re;
        double r363650 = x_im;
        double r363651 = r363649 * r363650;
        double r363652 = 3.0;
        double r363653 = r363651 * r363652;
        double r363654 = pow(r363650, r363652);
        double r363655 = -r363654;
        double r363656 = fma(r363653, r363649, r363655);
        return r363656;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.5
Target0.3
Herbie0.2
\[\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.5

    \[\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. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(3 \cdot \left(x.re \cdot x.im\right), x.re, -{x.im}^{3}\right)}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

    \[\leadsto \mathsf{fma}\left(\color{blue}{\left(3 \cdot x.re\right) \cdot x.im}, x.re, -{x.im}^{3}\right)\]
  5. Using strategy rm
  6. Applied associate-*l*0.2

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

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

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

Reproduce

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

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 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)))