Average Error: 7.1 → 0.2
Time: 26.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 r164236 = x_re;
        double r164237 = r164236 * r164236;
        double r164238 = x_im;
        double r164239 = r164238 * r164238;
        double r164240 = r164237 - r164239;
        double r164241 = r164240 * r164238;
        double r164242 = r164236 * r164238;
        double r164243 = r164238 * r164236;
        double r164244 = r164242 + r164243;
        double r164245 = r164244 * r164236;
        double r164246 = r164241 + r164245;
        return r164246;
}

double f(double x_re, double x_im) {
        double r164247 = x_re;
        double r164248 = 3.0;
        double r164249 = x_im;
        double r164250 = r164248 * r164249;
        double r164251 = r164250 * r164247;
        double r164252 = pow(r164249, r164248);
        double r164253 = -r164252;
        double r164254 = fma(r164247, r164251, r164253);
        return r164254;
}

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