Average Error: 7.4 → 0.5
Time: 18.5s
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(\left(x.re + x.re\right) \cdot x.im\right) \cdot \left(-\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right)\right) \cdot \sqrt[3]{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(\left(x.re + x.re\right) \cdot x.im\right) \cdot \left(-\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right)\right) \cdot \sqrt[3]{x.im}\right)
double f(double x_re, double x_im) {
        double r7621395 = x_re;
        double r7621396 = r7621395 * r7621395;
        double r7621397 = x_im;
        double r7621398 = r7621397 * r7621397;
        double r7621399 = r7621396 - r7621398;
        double r7621400 = r7621399 * r7621395;
        double r7621401 = r7621395 * r7621397;
        double r7621402 = r7621397 * r7621395;
        double r7621403 = r7621401 + r7621402;
        double r7621404 = r7621403 * r7621397;
        double r7621405 = r7621400 - r7621404;
        return r7621405;
}

double f(double x_re, double x_im) {
        double r7621406 = x_im;
        double r7621407 = x_re;
        double r7621408 = r7621406 + r7621407;
        double r7621409 = r7621407 - r7621406;
        double r7621410 = r7621409 * r7621407;
        double r7621411 = r7621407 + r7621407;
        double r7621412 = r7621411 * r7621406;
        double r7621413 = cbrt(r7621406);
        double r7621414 = r7621413 * r7621413;
        double r7621415 = -r7621414;
        double r7621416 = r7621412 * r7621415;
        double r7621417 = r7621416 * r7621413;
        double r7621418 = fma(r7621408, r7621410, r7621417);
        return r7621418;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.4
Target0.3
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 7.4

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

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

    \[\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 \left(-x.im\right)}\right)\]
  8. Using strategy rm
  9. Applied add-cube-cbrt0.5

    \[\leadsto \mathsf{fma}\left(x.re + x.im, \left(x.re - x.im\right) \cdot x.re, \left(x.im \cdot \left(x.re + x.re\right)\right) \cdot \left(-\color{blue}{\left(\sqrt[3]{x.im} \cdot \sqrt[3]{x.im}\right) \cdot \sqrt[3]{x.im}}\right)\right)\]
  10. Applied distribute-rgt-neg-in0.5

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

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

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

Reproduce

herbie shell --seed 2019174 +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.0 x.im))))

  (- (* (- (* x.re x.re) (* x.im x.im)) x.re) (* (+ (* x.re x.im) (* x.im x.re)) x.im)))