Average Error: 7.5 → 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 r235978 = x_re;
        double r235979 = r235978 * r235978;
        double r235980 = x_im;
        double r235981 = r235980 * r235980;
        double r235982 = r235979 - r235981;
        double r235983 = r235982 * r235978;
        double r235984 = r235978 * r235980;
        double r235985 = r235980 * r235978;
        double r235986 = r235984 + r235985;
        double r235987 = r235986 * r235980;
        double r235988 = r235983 - r235987;
        return r235988;
}

double f(double x_re, double x_im) {
        double r235989 = 3.0;
        double r235990 = x_re;
        double r235991 = x_im;
        double r235992 = -r235991;
        double r235993 = r235990 * r235992;
        double r235994 = r235993 * r235991;
        double r235995 = pow(r235990, r235989);
        double r235996 = fma(r235989, r235994, r235995);
        return r235996;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

    \[\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 2020001 +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)))