Average Error: 6.8 → 0.2
Time: 15.3s
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, \left(-3 \cdot x.im\right) \cdot x.re, {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(x.im, \left(-3 \cdot x.im\right) \cdot x.re, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r94786 = x_re;
        double r94787 = r94786 * r94786;
        double r94788 = x_im;
        double r94789 = r94788 * r94788;
        double r94790 = r94787 - r94789;
        double r94791 = r94790 * r94786;
        double r94792 = r94786 * r94788;
        double r94793 = r94788 * r94786;
        double r94794 = r94792 + r94793;
        double r94795 = r94794 * r94788;
        double r94796 = r94791 - r94795;
        return r94796;
}

double f(double x_re, double x_im) {
        double r94797 = x_im;
        double r94798 = -3.0;
        double r94799 = r94798 * r94797;
        double r94800 = x_re;
        double r94801 = r94799 * r94800;
        double r94802 = 3.0;
        double r94803 = pow(r94800, r94802);
        double r94804 = fma(r94797, r94801, r94803);
        return r94804;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.8
Target0.3
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 6.8

    \[\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.re \cdot x.im, 3 \cdot x.im, {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied fma-udef0.2

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

    \[\leadsto \color{blue}{\left(x.im \cdot \left(x.re \cdot x.im\right)\right) \cdot -3} + {x.re}^{3}\]
  6. Using strategy rm
  7. Applied pow10.2

    \[\leadsto \left(x.im \cdot \left(x.re \cdot x.im\right)\right) \cdot \color{blue}{{-3}^{1}} + {x.re}^{3}\]
  8. Applied pow10.2

    \[\leadsto \left(x.im \cdot \left(x.re \cdot \color{blue}{{x.im}^{1}}\right)\right) \cdot {-3}^{1} + {x.re}^{3}\]
  9. Applied pow10.2

    \[\leadsto \left(x.im \cdot \left(\color{blue}{{x.re}^{1}} \cdot {x.im}^{1}\right)\right) \cdot {-3}^{1} + {x.re}^{3}\]
  10. Applied pow-prod-down0.2

    \[\leadsto \left(x.im \cdot \color{blue}{{\left(x.re \cdot x.im\right)}^{1}}\right) \cdot {-3}^{1} + {x.re}^{3}\]
  11. Applied pow10.2

    \[\leadsto \left(\color{blue}{{x.im}^{1}} \cdot {\left(x.re \cdot x.im\right)}^{1}\right) \cdot {-3}^{1} + {x.re}^{3}\]
  12. Applied pow-prod-down0.2

    \[\leadsto \color{blue}{{\left(x.im \cdot \left(x.re \cdot x.im\right)\right)}^{1}} \cdot {-3}^{1} + {x.re}^{3}\]
  13. Applied pow-prod-down0.2

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

    \[\leadsto {\color{blue}{\left(\left(\left(x.re \cdot x.im\right) \cdot -3\right) \cdot x.im\right)}}^{1} + {x.re}^{3}\]
  15. Using strategy rm
  16. Applied *-un-lft-identity0.2

    \[\leadsto {\left(\left(\left(x.re \cdot x.im\right) \cdot -3\right) \cdot x.im\right)}^{1} + \color{blue}{1 \cdot {x.re}^{3}}\]
  17. Applied *-un-lft-identity0.2

    \[\leadsto \color{blue}{1 \cdot {\left(\left(\left(x.re \cdot x.im\right) \cdot -3\right) \cdot x.im\right)}^{1}} + 1 \cdot {x.re}^{3}\]
  18. Applied distribute-lft-out0.2

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

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

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

Reproduce

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