Average Error: 7.1 → 0.2
Time: 26.6s
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 r158351 = x_re;
        double r158352 = r158351 * r158351;
        double r158353 = x_im;
        double r158354 = r158353 * r158353;
        double r158355 = r158352 - r158354;
        double r158356 = r158355 * r158353;
        double r158357 = r158351 * r158353;
        double r158358 = r158353 * r158351;
        double r158359 = r158357 + r158358;
        double r158360 = r158359 * r158351;
        double r158361 = r158356 + r158360;
        return r158361;
}

double f(double x_re, double x_im) {
        double r158362 = x_re;
        double r158363 = 3.0;
        double r158364 = x_im;
        double r158365 = r158363 * r158364;
        double r158366 = r158365 * r158362;
        double r158367 = pow(r158364, r158363);
        double r158368 = -r158367;
        double r158369 = fma(r158362, r158366, r158368);
        return r158369;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.1
Target0.2
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.1

    \[\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 2019325 +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)))