Average Error: 7.2 → 0.2
Time: 26.6s
Precision: 64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
\[\mathsf{fma}\left(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {x.re}^{3}\right)\]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im
\mathsf{fma}\left(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r215257 = x_re;
        double r215258 = r215257 * r215257;
        double r215259 = x_im;
        double r215260 = r215259 * r215259;
        double r215261 = r215258 - r215260;
        double r215262 = r215261 * r215257;
        double r215263 = r215257 * r215259;
        double r215264 = r215259 * r215257;
        double r215265 = r215263 + r215264;
        double r215266 = r215265 * r215259;
        double r215267 = r215262 - r215266;
        return r215267;
}

double f(double x_re, double x_im) {
        double r215268 = x_im;
        double r215269 = -3.0;
        double r215270 = r215269 * r215268;
        double r215271 = x_re;
        double r215272 = r215270 * r215271;
        double r215273 = 3.0;
        double r215274 = pow(r215271, r215273);
        double r215275 = fma(r215268, r215272, r215274);
        return r215275;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.2
Target0.3
Herbie0.2
\[\left(x.re \cdot x.re\right) \cdot \left(x.re - x.im\right) + \left(x.re \cdot x.im\right) \cdot \left(x.re - 3 \cdot x.im\right)\]

Derivation

  1. Initial program 7.2

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  2. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.im, -3 \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

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

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

Reproduce

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

  :herbie-target
  (+ (* (* x.re x.re) (- x.re x.im)) (* (* x.re x.im) (- x.re (* 3 x.im))))

  (- (* (- (* x.re x.re) (* x.im x.im)) x.re) (* (+ (* x.re x.im) (* x.im x.re)) x.im)))