Average Error: 7.0 → 0.2
Time: 4.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 \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 r235525 = x_re;
        double r235526 = r235525 * r235525;
        double r235527 = x_im;
        double r235528 = r235527 * r235527;
        double r235529 = r235526 - r235528;
        double r235530 = r235529 * r235525;
        double r235531 = r235525 * r235527;
        double r235532 = r235527 * r235525;
        double r235533 = r235531 + r235532;
        double r235534 = r235533 * r235527;
        double r235535 = r235530 - r235534;
        return r235535;
}

double f(double x_re, double x_im) {
        double r235536 = 3.0;
        double r235537 = x_re;
        double r235538 = x_im;
        double r235539 = r235537 * r235538;
        double r235540 = -r235538;
        double r235541 = r235539 * r235540;
        double r235542 = pow(r235537, r235536);
        double r235543 = fma(r235536, r235541, r235542);
        return r235543;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Simplified6.9

    \[\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-in6.9

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