Average Error: 7.2 → 0.2
Time: 25.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 r208327 = x_re;
        double r208328 = r208327 * r208327;
        double r208329 = x_im;
        double r208330 = r208329 * r208329;
        double r208331 = r208328 - r208330;
        double r208332 = r208331 * r208327;
        double r208333 = r208327 * r208329;
        double r208334 = r208329 * r208327;
        double r208335 = r208333 + r208334;
        double r208336 = r208335 * r208329;
        double r208337 = r208332 - r208336;
        return r208337;
}

double f(double x_re, double x_im) {
        double r208338 = x_im;
        double r208339 = -3.0;
        double r208340 = r208339 * r208338;
        double r208341 = x_re;
        double r208342 = r208340 * r208341;
        double r208343 = 3.0;
        double r208344 = pow(r208341, r208343);
        double r208345 = fma(r208338, r208342, r208344);
        return r208345;
}

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