Average Error: 6.8 → 0.1
Time: 11.4s
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\]
\[{x.re}^{3} - \mathsf{fma}\left(x.im, \left(x.im \cdot x.re\right), \left(\left(x.im \cdot x.re\right) \cdot \left(x.im + x.im\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
{x.re}^{3} - \mathsf{fma}\left(x.im, \left(x.im \cdot x.re\right), \left(\left(x.im \cdot x.re\right) \cdot \left(x.im + x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r5248912 = x_re;
        double r5248913 = r5248912 * r5248912;
        double r5248914 = x_im;
        double r5248915 = r5248914 * r5248914;
        double r5248916 = r5248913 - r5248915;
        double r5248917 = r5248916 * r5248912;
        double r5248918 = r5248912 * r5248914;
        double r5248919 = r5248914 * r5248912;
        double r5248920 = r5248918 + r5248919;
        double r5248921 = r5248920 * r5248914;
        double r5248922 = r5248917 - r5248921;
        return r5248922;
}

double f(double x_re, double x_im) {
        double r5248923 = x_re;
        double r5248924 = 3.0;
        double r5248925 = pow(r5248923, r5248924);
        double r5248926 = x_im;
        double r5248927 = r5248926 * r5248923;
        double r5248928 = r5248926 + r5248926;
        double r5248929 = r5248927 * r5248928;
        double r5248930 = fma(r5248926, r5248927, r5248929);
        double r5248931 = r5248925 - r5248930;
        return r5248931;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.8
Target0.2
Herbie0.1
\[\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}{x.re \cdot \left(x.re \cdot x.re\right) - \left(x.re \cdot x.im\right) \cdot \left(x.im + \left(x.im + x.im\right)\right)}\]
  3. Using strategy rm
  4. Applied pow10.2

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

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

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

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

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

    \[\leadsto {x.re}^{\color{blue}{3}} - \left(x.re \cdot x.im\right) \cdot \left(x.im + \left(x.im + x.im\right)\right)\]
  10. Using strategy rm
  11. Applied distribute-rgt-in0.2

    \[\leadsto {x.re}^{3} - \color{blue}{\left(x.im \cdot \left(x.re \cdot x.im\right) + \left(x.im + x.im\right) \cdot \left(x.re \cdot x.im\right)\right)}\]
  12. Using strategy rm
  13. Applied fma-def0.1

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

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

Reproduce

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