Average Error: 7.6 → 0.2
Time: 4.2s
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(3, \left(x.re \cdot \left(-x.im\right)\right) \cdot x.im, {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(3, \left(x.re \cdot \left(-x.im\right)\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r216549 = x_re;
        double r216550 = r216549 * r216549;
        double r216551 = x_im;
        double r216552 = r216551 * r216551;
        double r216553 = r216550 - r216552;
        double r216554 = r216553 * r216549;
        double r216555 = r216549 * r216551;
        double r216556 = r216551 * r216549;
        double r216557 = r216555 + r216556;
        double r216558 = r216557 * r216551;
        double r216559 = r216554 - r216558;
        return r216559;
}

double f(double x_re, double x_im) {
        double r216560 = 3.0;
        double r216561 = x_re;
        double r216562 = x_im;
        double r216563 = -r216562;
        double r216564 = r216561 * r216563;
        double r216565 = r216564 * r216562;
        double r216566 = pow(r216561, r216560);
        double r216567 = fma(r216560, r216565, r216566);
        return r216567;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.6
Target0.2
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.6

    \[\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. Simplified7.6

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x.re \cdot \left(-x.im \cdot x.im\right), {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied distribute-lft-neg-in7.6

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

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

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

Reproduce

herbie shell --seed 2019362 +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)))