Average Error: 7.0 → 0.2
Time: 20.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, x.re \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\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 \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r6884312 = x_re;
        double r6884313 = r6884312 * r6884312;
        double r6884314 = x_im;
        double r6884315 = r6884314 * r6884314;
        double r6884316 = r6884313 - r6884315;
        double r6884317 = r6884316 * r6884312;
        double r6884318 = r6884312 * r6884314;
        double r6884319 = r6884314 * r6884312;
        double r6884320 = r6884318 + r6884319;
        double r6884321 = r6884320 * r6884314;
        double r6884322 = r6884317 - r6884321;
        return r6884322;
}

double f(double x_re, double x_im) {
        double r6884323 = x_im;
        double r6884324 = -r6884323;
        double r6884325 = x_re;
        double r6884326 = r6884325 * r6884323;
        double r6884327 = r6884326 + r6884326;
        double r6884328 = r6884323 * r6884327;
        double r6884329 = fma(r6884324, r6884327, r6884328);
        double r6884330 = r6884323 + r6884325;
        double r6884331 = r6884325 - r6884323;
        double r6884332 = r6884331 * r6884325;
        double r6884333 = r6884324 * r6884327;
        double r6884334 = fma(r6884330, r6884332, r6884333);
        double r6884335 = r6884329 + r6884334;
        return r6884335;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.0
Target0.3
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. Using strategy rm
  3. Applied difference-of-squares7.0

    \[\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 prod-diff0.2

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

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

Reproduce

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