Average Error: 7.2 → 0.2
Time: 19.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, \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 r6766369 = x_re;
        double r6766370 = r6766369 * r6766369;
        double r6766371 = x_im;
        double r6766372 = r6766371 * r6766371;
        double r6766373 = r6766370 - r6766372;
        double r6766374 = r6766373 * r6766369;
        double r6766375 = r6766369 * r6766371;
        double r6766376 = r6766371 * r6766369;
        double r6766377 = r6766375 + r6766376;
        double r6766378 = r6766377 * r6766371;
        double r6766379 = r6766374 - r6766378;
        return r6766379;
}

double f(double x_re, double x_im) {
        double r6766380 = x_im;
        double r6766381 = x_re;
        double r6766382 = r6766380 + r6766381;
        double r6766383 = r6766381 - r6766380;
        double r6766384 = r6766383 * r6766381;
        double r6766385 = -r6766380;
        double r6766386 = r6766385 * r6766381;
        double r6766387 = r6766386 + r6766386;
        double r6766388 = r6766387 * r6766380;
        double r6766389 = fma(r6766382, r6766384, r6766388);
        return r6766389;
}

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.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot 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)))