Average Error: 7.6 → 0.2
Time: 16.6s
Precision: 64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[\mathsf{fma}\left(x.re, \left(x.im \cdot 3\right) \cdot x.re, -{x.im}^{3}\right)\]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\mathsf{fma}\left(x.re, \left(x.im \cdot 3\right) \cdot x.re, -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r174775 = x_re;
        double r174776 = r174775 * r174775;
        double r174777 = x_im;
        double r174778 = r174777 * r174777;
        double r174779 = r174776 - r174778;
        double r174780 = r174779 * r174777;
        double r174781 = r174775 * r174777;
        double r174782 = r174777 * r174775;
        double r174783 = r174781 + r174782;
        double r174784 = r174783 * r174775;
        double r174785 = r174780 + r174784;
        return r174785;
}

double f(double x_re, double x_im) {
        double r174786 = x_re;
        double r174787 = x_im;
        double r174788 = 3.0;
        double r174789 = r174787 * r174788;
        double r174790 = r174789 * r174786;
        double r174791 = pow(r174787, r174788);
        double r174792 = -r174791;
        double r174793 = fma(r174786, r174790, r174792);
        return r174793;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.6
Target0.3
Herbie0.2
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)\]

Derivation

  1. Initial program 7.6

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Simplified0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re, x.im \cdot \left(3 \cdot x.re\right), -{x.im}^{3}\right)}\]
  3. Using strategy rm
  4. Applied *-un-lft-identity0.2

    \[\leadsto \mathsf{fma}\left(x.re, \color{blue}{\left(1 \cdot x.im\right)} \cdot \left(3 \cdot x.re\right), -{x.im}^{3}\right)\]
  5. Applied associate-*l*0.2

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

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

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

Reproduce

herbie shell --seed 2019212 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, imaginary part"
  :precision binary64

  :herbie-target
  (+ (* (* x.re x.im) (* 2 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

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