Average Error: 6.6 → 0.2
Time: 22.0s
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 r6765803 = x_re;
        double r6765804 = r6765803 * r6765803;
        double r6765805 = x_im;
        double r6765806 = r6765805 * r6765805;
        double r6765807 = r6765804 - r6765806;
        double r6765808 = r6765807 * r6765803;
        double r6765809 = r6765803 * r6765805;
        double r6765810 = r6765805 * r6765803;
        double r6765811 = r6765809 + r6765810;
        double r6765812 = r6765811 * r6765805;
        double r6765813 = r6765808 - r6765812;
        return r6765813;
}

double f(double x_re, double x_im) {
        double r6765814 = x_im;
        double r6765815 = x_re;
        double r6765816 = r6765814 + r6765815;
        double r6765817 = r6765815 - r6765814;
        double r6765818 = r6765817 * r6765815;
        double r6765819 = -r6765814;
        double r6765820 = r6765819 * r6765815;
        double r6765821 = r6765820 + r6765820;
        double r6765822 = r6765821 * r6765814;
        double r6765823 = fma(r6765816, r6765818, r6765822);
        return r6765823;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.6
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 6.6

    \[\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-squares6.6

    \[\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 2019162 +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)))