Average Error: 7.6 → 0.2
Time: 23.2s
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(-3, \left(x.im \cdot x.re\right) \cdot x.im, {x.re}^{3}\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(-3, \left(x.im \cdot x.re\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r109282 = x_re;
        double r109283 = r109282 * r109282;
        double r109284 = x_im;
        double r109285 = r109284 * r109284;
        double r109286 = r109283 - r109285;
        double r109287 = r109286 * r109282;
        double r109288 = r109282 * r109284;
        double r109289 = r109284 * r109282;
        double r109290 = r109288 + r109289;
        double r109291 = r109290 * r109284;
        double r109292 = r109287 - r109291;
        return r109292;
}

double f(double x_re, double x_im) {
        double r109293 = -3.0;
        double r109294 = x_im;
        double r109295 = x_re;
        double r109296 = r109294 * r109295;
        double r109297 = r109296 * r109294;
        double r109298 = 3.0;
        double r109299 = pow(r109295, r109298);
        double r109300 = fma(r109293, r109297, r109299);
        return r109300;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.6
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.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. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.im, -3 \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied add-cube-cbrt0.2

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{\left(\left(\sqrt[3]{-3} \cdot \sqrt[3]{-3}\right) \cdot \sqrt[3]{-3}\right)} \cdot \left(x.im \cdot x.re\right), {x.re}^{3}\right)\]
  5. Applied associate-*l*0.2

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{\left(\sqrt[3]{-3} \cdot \sqrt[3]{-3}\right) \cdot \left(\sqrt[3]{-3} \cdot \left(x.im \cdot x.re\right)\right)}, {x.re}^{3}\right)\]
  6. Taylor expanded around 0 7.5

    \[\leadsto \color{blue}{{x.re}^{3} - 3 \cdot \left({x.im}^{2} \cdot x.re\right)}\]
  7. Simplified0.2

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

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

Reproduce

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