Average Error: 7.8 → 0.2
Time: 16.8s
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(x.im \cdot x.re\right) \cdot -3, {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(x.im \cdot x.re\right) \cdot -3, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r115751 = x_re;
        double r115752 = r115751 * r115751;
        double r115753 = x_im;
        double r115754 = r115753 * r115753;
        double r115755 = r115752 - r115754;
        double r115756 = r115755 * r115751;
        double r115757 = r115751 * r115753;
        double r115758 = r115753 * r115751;
        double r115759 = r115757 + r115758;
        double r115760 = r115759 * r115753;
        double r115761 = r115756 - r115760;
        return r115761;
}

double f(double x_re, double x_im) {
        double r115762 = x_im;
        double r115763 = x_re;
        double r115764 = r115762 * r115763;
        double r115765 = -3.0;
        double r115766 = r115764 * r115765;
        double r115767 = 3.0;
        double r115768 = pow(r115763, r115767);
        double r115769 = fma(r115762, r115766, r115768);
        return r115769;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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(\left(-x.im\right) \cdot x.re\right), {x.re}^{3}\right)}\]
  3. Final simplification0.2

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

Reproduce

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