Average Error: 7.4 → 0.2
Time: 4.0s
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 x.im\right) \cdot \left(-x.im\right), {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 x.im\right) \cdot \left(-x.im\right), {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r247714 = x_re;
        double r247715 = r247714 * r247714;
        double r247716 = x_im;
        double r247717 = r247716 * r247716;
        double r247718 = r247715 - r247717;
        double r247719 = r247718 * r247714;
        double r247720 = r247714 * r247716;
        double r247721 = r247716 * r247714;
        double r247722 = r247720 + r247721;
        double r247723 = r247722 * r247716;
        double r247724 = r247719 - r247723;
        return r247724;
}

double f(double x_re, double x_im) {
        double r247725 = 3.0;
        double r247726 = x_re;
        double r247727 = x_im;
        double r247728 = r247726 * r247727;
        double r247729 = -r247727;
        double r247730 = r247728 * r247729;
        double r247731 = pow(r247726, r247725);
        double r247732 = fma(r247725, r247730, r247731);
        return r247732;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.4
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.4

    \[\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.4

    \[\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-rgt-neg-in7.4

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

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

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

Reproduce

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