Average Error: 7.3 → 0.2
Time: 3.8s
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.re + x.im, \left(x.re - x.im\right) \cdot x.re, \left(-\mathsf{fma}\left(x.re, x.im, x.im \cdot x.re\right)\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.re + x.im, \left(x.re - x.im\right) \cdot x.re, \left(-\mathsf{fma}\left(x.re, x.im, x.im \cdot x.re\right)\right) \cdot x.im\right)
double f(double x_re, double x_im) {
        double r169216 = x_re;
        double r169217 = r169216 * r169216;
        double r169218 = x_im;
        double r169219 = r169218 * r169218;
        double r169220 = r169217 - r169219;
        double r169221 = r169220 * r169216;
        double r169222 = r169216 * r169218;
        double r169223 = r169218 * r169216;
        double r169224 = r169222 + r169223;
        double r169225 = r169224 * r169218;
        double r169226 = r169221 - r169225;
        return r169226;
}

double f(double x_re, double x_im) {
        double r169227 = x_re;
        double r169228 = x_im;
        double r169229 = r169227 + r169228;
        double r169230 = r169227 - r169228;
        double r169231 = r169230 * r169227;
        double r169232 = r169228 * r169227;
        double r169233 = fma(r169227, r169228, r169232);
        double r169234 = -r169233;
        double r169235 = r169234 * r169228;
        double r169236 = fma(r169229, r169231, r169235);
        return r169236;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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.3

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

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

Reproduce

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

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