Average Error: 7.3 → 0.2
Time: 10.3s
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.re\right) \cdot x.im, {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.re\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r252920 = x_re;
        double r252921 = r252920 * r252920;
        double r252922 = x_im;
        double r252923 = r252922 * r252922;
        double r252924 = r252921 - r252923;
        double r252925 = r252924 * r252920;
        double r252926 = r252920 * r252922;
        double r252927 = r252922 * r252920;
        double r252928 = r252926 + r252927;
        double r252929 = r252928 * r252922;
        double r252930 = r252925 - r252929;
        return r252930;
}

double f(double x_re, double x_im) {
        double r252931 = x_im;
        double r252932 = -3.0;
        double r252933 = x_re;
        double r252934 = r252932 * r252933;
        double r252935 = r252934 * r252931;
        double r252936 = 3.0;
        double r252937 = pow(r252933, r252936);
        double r252938 = fma(r252931, r252935, r252937);
        return r252938;
}

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

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

Reproduce

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