Average Error: 7.1 → 0.2
Time: 25.3s
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 r166690 = x_re;
        double r166691 = r166690 * r166690;
        double r166692 = x_im;
        double r166693 = r166692 * r166692;
        double r166694 = r166691 - r166693;
        double r166695 = r166694 * r166692;
        double r166696 = r166690 * r166692;
        double r166697 = r166692 * r166690;
        double r166698 = r166696 + r166697;
        double r166699 = r166698 * r166690;
        double r166700 = r166695 + r166699;
        return r166700;
}

double f(double x_re, double x_im) {
        double r166701 = x_re;
        double r166702 = 3.0;
        double r166703 = x_im;
        double r166704 = r166702 * r166703;
        double r166705 = r166704 * r166701;
        double r166706 = pow(r166703, r166702);
        double r166707 = -r166706;
        double r166708 = fma(r166701, r166705, r166707);
        return r166708;
}

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