Average Error: 7.3 → 0.2
Time: 28.2s
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.re, \left(3 \cdot x.im\right) \cdot 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(x.re, \left(3 \cdot x.im\right) \cdot x.re, -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r156503 = x_re;
        double r156504 = r156503 * r156503;
        double r156505 = x_im;
        double r156506 = r156505 * r156505;
        double r156507 = r156504 - r156506;
        double r156508 = r156507 * r156505;
        double r156509 = r156503 * r156505;
        double r156510 = r156505 * r156503;
        double r156511 = r156509 + r156510;
        double r156512 = r156511 * r156503;
        double r156513 = r156508 + r156512;
        return r156513;
}

double f(double x_re, double x_im) {
        double r156514 = x_re;
        double r156515 = 3.0;
        double r156516 = x_im;
        double r156517 = r156515 * r156516;
        double r156518 = r156517 * r156514;
        double r156519 = pow(r156516, r156515);
        double r156520 = -r156519;
        double r156521 = fma(r156514, r156518, r156520);
        return r156521;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.3
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.3

    \[\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(x.re, 3 \cdot \left(x.im \cdot x.re\right), -{x.im}^{3}\right)}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

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

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

Reproduce

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

  :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)))