Average Error: 7.3 → 0.2
Time: 24.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(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {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(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r111651 = x_re;
        double r111652 = r111651 * r111651;
        double r111653 = x_im;
        double r111654 = r111653 * r111653;
        double r111655 = r111652 - r111654;
        double r111656 = r111655 * r111651;
        double r111657 = r111651 * r111653;
        double r111658 = r111653 * r111651;
        double r111659 = r111657 + r111658;
        double r111660 = r111659 * r111653;
        double r111661 = r111656 - r111660;
        return r111661;
}

double f(double x_re, double x_im) {
        double r111662 = x_im;
        double r111663 = -3.0;
        double r111664 = r111663 * r111662;
        double r111665 = x_re;
        double r111666 = r111664 * r111665;
        double r111667 = 3.0;
        double r111668 = pow(r111665, r111667);
        double r111669 = fma(r111662, r111666, r111668);
        return r111669;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Simplified0.2

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

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

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

Reproduce

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