Average Error: 7.2 → 0.2
Time: 17.1s
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(-x.im\right) \cdot \left(\left(x.re + x.re\right) \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, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r8345160 = x_re;
        double r8345161 = r8345160 * r8345160;
        double r8345162 = x_im;
        double r8345163 = r8345162 * r8345162;
        double r8345164 = r8345161 - r8345163;
        double r8345165 = r8345164 * r8345160;
        double r8345166 = r8345160 * r8345162;
        double r8345167 = r8345162 * r8345160;
        double r8345168 = r8345166 + r8345167;
        double r8345169 = r8345168 * r8345162;
        double r8345170 = r8345165 - r8345169;
        return r8345170;
}

double f(double x_re, double x_im) {
        double r8345171 = x_im;
        double r8345172 = x_re;
        double r8345173 = r8345171 + r8345172;
        double r8345174 = r8345172 - r8345171;
        double r8345175 = r8345174 * r8345172;
        double r8345176 = -r8345171;
        double r8345177 = r8345172 + r8345172;
        double r8345178 = r8345177 * r8345171;
        double r8345179 = r8345176 * r8345178;
        double r8345180 = fma(r8345173, r8345175, r8345179);
        return r8345180;
}

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 \cdot \left(x.re + x.re\right)\right) \cdot x.im}\right)\]
  8. Final simplification0.2

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

Reproduce

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