Average Error: 7.5 → 0.2
Time: 18.4s
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 r351071 = x_re;
        double r351072 = r351071 * r351071;
        double r351073 = x_im;
        double r351074 = r351073 * r351073;
        double r351075 = r351072 - r351074;
        double r351076 = r351075 * r351073;
        double r351077 = r351071 * r351073;
        double r351078 = r351073 * r351071;
        double r351079 = r351077 + r351078;
        double r351080 = r351079 * r351071;
        double r351081 = r351076 + r351080;
        return r351081;
}

double f(double x_re, double x_im) {
        double r351082 = x_re;
        double r351083 = 3.0;
        double r351084 = x_im;
        double r351085 = r351083 * r351084;
        double r351086 = r351085 * r351082;
        double r351087 = pow(r351084, r351083);
        double r351088 = -r351087;
        double r351089 = fma(r351082, r351086, r351088);
        return r351089;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.5
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.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(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 2019350 +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)))