Average Error: 7.3 → 0.2
Time: 11.7s
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 r162844 = x_re;
        double r162845 = r162844 * r162844;
        double r162846 = x_im;
        double r162847 = r162846 * r162846;
        double r162848 = r162845 - r162847;
        double r162849 = r162848 * r162844;
        double r162850 = r162844 * r162846;
        double r162851 = r162846 * r162844;
        double r162852 = r162850 + r162851;
        double r162853 = r162852 * r162846;
        double r162854 = r162849 - r162853;
        return r162854;
}

double f(double x_re, double x_im) {
        double r162855 = x_im;
        double r162856 = x_re;
        double r162857 = r162855 * r162856;
        double r162858 = -3.0;
        double r162859 = r162857 * r162858;
        double r162860 = 3.0;
        double r162861 = pow(r162856, r162860);
        double r162862 = fma(r162855, r162859, r162861);
        return r162862;
}

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(\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 2019235 +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)))