Average Error: 6.9 → 0.5
Time: 55.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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(\left(\sqrt[3]{x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)} \cdot \sqrt[3]{x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}\right) \cdot \left(-\sqrt[3]{x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)\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(\left(x.im + x.re\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(\left(\left(\sqrt[3]{x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)} \cdot \sqrt[3]{x.im}\right) \cdot \sqrt[3]{x.re \cdot x.im + x.re \cdot x.im}\right) \cdot \left(-\sqrt[3]{x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)}\right)\right)\right)
double f(double x_re, double x_im) {
        double r27591389 = x_re;
        double r27591390 = r27591389 * r27591389;
        double r27591391 = x_im;
        double r27591392 = r27591391 * r27591391;
        double r27591393 = r27591390 - r27591392;
        double r27591394 = r27591393 * r27591389;
        double r27591395 = r27591389 * r27591391;
        double r27591396 = r27591391 * r27591389;
        double r27591397 = r27591395 + r27591396;
        double r27591398 = r27591397 * r27591391;
        double r27591399 = r27591394 - r27591398;
        return r27591399;
}

double f(double x_re, double x_im) {
        double r27591400 = x_im;
        double r27591401 = x_re;
        double r27591402 = r27591400 + r27591401;
        double r27591403 = r27591401 - r27591400;
        double r27591404 = r27591403 * r27591401;
        double r27591405 = r27591401 * r27591400;
        double r27591406 = r27591405 + r27591405;
        double r27591407 = r27591400 * r27591406;
        double r27591408 = cbrt(r27591407);
        double r27591409 = cbrt(r27591400);
        double r27591410 = r27591408 * r27591409;
        double r27591411 = cbrt(r27591406);
        double r27591412 = r27591410 * r27591411;
        double r27591413 = -r27591408;
        double r27591414 = r27591412 * r27591413;
        double r27591415 = fma(r27591402, r27591404, r27591414);
        return r27591415;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.9
Target0.2
Herbie0.5
\[\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.9

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

    \[\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(\left(x.re + x.im\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(-\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)\right)}\]
  7. Using strategy rm
  8. Applied add-cube-cbrt0.6

    \[\leadsto \mathsf{fma}\left(\left(x.re + x.im\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(-\color{blue}{\left(\sqrt[3]{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im} \cdot \sqrt[3]{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im}\right) \cdot \sqrt[3]{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im}}\right)\right)\]
  9. Using strategy rm
  10. Applied cbrt-prod0.5

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

    \[\leadsto \mathsf{fma}\left(\left(x.re + x.im\right), \left(\left(x.re - x.im\right) \cdot x.re\right), \left(-\color{blue}{\left(\sqrt[3]{x.re \cdot x.im + x.im \cdot x.re} \cdot \left(\sqrt[3]{x.im} \cdot \sqrt[3]{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im}\right)\right)} \cdot \sqrt[3]{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im}\right)\right)\]
  12. Final simplification0.5

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

Reproduce

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