Average Error: 7.0 → 0.2
Time: 15.1s
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 r341088 = x_re;
        double r341089 = r341088 * r341088;
        double r341090 = x_im;
        double r341091 = r341090 * r341090;
        double r341092 = r341089 - r341091;
        double r341093 = r341092 * r341088;
        double r341094 = r341088 * r341090;
        double r341095 = r341090 * r341088;
        double r341096 = r341094 + r341095;
        double r341097 = r341096 * r341090;
        double r341098 = r341093 - r341097;
        return r341098;
}

double f(double x_re, double x_im) {
        double r341099 = x_im;
        double r341100 = -3.0;
        double r341101 = r341100 * r341099;
        double r341102 = x_re;
        double r341103 = r341101 * r341102;
        double r341104 = 3.0;
        double r341105 = pow(r341102, r341104);
        double r341106 = fma(r341099, r341103, r341105);
        return r341106;
}

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. 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 2019350 +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)))