Average Error: 7.0 → 0.2
Time: 12.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 \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\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(-x.im, x.re \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r3151842 = x_re;
        double r3151843 = r3151842 * r3151842;
        double r3151844 = x_im;
        double r3151845 = r3151844 * r3151844;
        double r3151846 = r3151843 - r3151845;
        double r3151847 = r3151846 * r3151842;
        double r3151848 = r3151842 * r3151844;
        double r3151849 = r3151844 * r3151842;
        double r3151850 = r3151848 + r3151849;
        double r3151851 = r3151850 * r3151844;
        double r3151852 = r3151847 - r3151851;
        return r3151852;
}

double f(double x_re, double x_im) {
        double r3151853 = x_im;
        double r3151854 = -r3151853;
        double r3151855 = x_re;
        double r3151856 = r3151855 * r3151853;
        double r3151857 = r3151856 + r3151856;
        double r3151858 = r3151853 * r3151857;
        double r3151859 = fma(r3151854, r3151857, r3151858);
        double r3151860 = r3151853 + r3151855;
        double r3151861 = r3151855 - r3151853;
        double r3151862 = r3151861 * r3151855;
        double r3151863 = r3151854 * r3151857;
        double r3151864 = fma(r3151860, r3151862, r3151863);
        double r3151865 = r3151859 + r3151864;
        return r3151865;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.0
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.0

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

    \[\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 prod-diff0.2

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

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

Reproduce

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