Average Error: 7.1 → 0.2
Time: 3.5s
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 r210590 = x_re;
        double r210591 = r210590 * r210590;
        double r210592 = x_im;
        double r210593 = r210592 * r210592;
        double r210594 = r210591 - r210593;
        double r210595 = r210594 * r210590;
        double r210596 = r210590 * r210592;
        double r210597 = r210592 * r210590;
        double r210598 = r210596 + r210597;
        double r210599 = r210598 * r210592;
        double r210600 = r210595 - r210599;
        return r210600;
}

double f(double x_re, double x_im) {
        double r210601 = 3.0;
        double r210602 = x_re;
        double r210603 = x_im;
        double r210604 = r210602 * r210603;
        double r210605 = -r210603;
        double r210606 = r210604 * r210605;
        double r210607 = pow(r210602, r210601);
        double r210608 = fma(r210601, r210606, r210607);
        return r210608;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

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