Average Error: 7.5 → 0.2
Time: 3.3s
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 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 x.im\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r329094 = x_re;
        double r329095 = r329094 * r329094;
        double r329096 = x_im;
        double r329097 = r329096 * r329096;
        double r329098 = r329095 - r329097;
        double r329099 = r329098 * r329094;
        double r329100 = r329094 * r329096;
        double r329101 = r329096 * r329094;
        double r329102 = r329100 + r329101;
        double r329103 = r329102 * r329096;
        double r329104 = r329099 - r329103;
        return r329104;
}

double f(double x_re, double x_im) {
        double r329105 = -3.0;
        double r329106 = x_re;
        double r329107 = x_im;
        double r329108 = r329106 * r329107;
        double r329109 = r329108 * r329107;
        double r329110 = 3.0;
        double r329111 = pow(r329106, r329110);
        double r329112 = fma(r329105, r329109, r329111);
        return r329112;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.5
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.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-rgt-neg-in7.5

    \[\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. Taylor expanded around 0 7.5

    \[\leadsto \color{blue}{{x.re}^{3} - 3 \cdot \left({x.im}^{2} \cdot x.re\right)}\]
  7. Simplified0.2

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

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

Reproduce

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