Average Error: 7.2 → 0.2
Time: 20.9s
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 + x.re, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right) \cdot x.im\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 + x.re, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot x.re + \left(-x.im\right) \cdot x.re\right) \cdot x.im\right)
double f(double x_re, double x_im) {
        double r6887911 = x_re;
        double r6887912 = r6887911 * r6887911;
        double r6887913 = x_im;
        double r6887914 = r6887913 * r6887913;
        double r6887915 = r6887912 - r6887914;
        double r6887916 = r6887915 * r6887911;
        double r6887917 = r6887911 * r6887913;
        double r6887918 = r6887913 * r6887911;
        double r6887919 = r6887917 + r6887918;
        double r6887920 = r6887919 * r6887913;
        double r6887921 = r6887916 - r6887920;
        return r6887921;
}

double f(double x_re, double x_im) {
        double r6887922 = x_im;
        double r6887923 = x_re;
        double r6887924 = r6887922 + r6887923;
        double r6887925 = r6887923 - r6887922;
        double r6887926 = r6887925 * r6887923;
        double r6887927 = -r6887922;
        double r6887928 = r6887927 * r6887923;
        double r6887929 = r6887928 + r6887928;
        double r6887930 = r6887929 * r6887922;
        double r6887931 = fma(r6887924, r6887926, r6887930);
        return r6887931;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Using strategy rm
  3. Applied difference-of-squares7.2

    \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  4. Applied associate-*l*0.2

    \[\leadsto \color{blue}{\left(x.re + x.im\right) \cdot \left(\left(x.re - x.im\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  5. Using strategy rm
  6. Applied fma-neg0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re + x.im, \left(x.re - x.im\right) \cdot x.re, -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}\]
  7. Simplified0.2

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

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

Reproduce

herbie shell --seed 2019163 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"

  :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)))