Average Error: 7.6 → 0.2
Time: 26.1s
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, 3 \cdot \left(x.im \cdot x.re\right), -{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, 3 \cdot \left(x.im \cdot x.re\right), -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r156851 = x_re;
        double r156852 = r156851 * r156851;
        double r156853 = x_im;
        double r156854 = r156853 * r156853;
        double r156855 = r156852 - r156854;
        double r156856 = r156855 * r156853;
        double r156857 = r156851 * r156853;
        double r156858 = r156853 * r156851;
        double r156859 = r156857 + r156858;
        double r156860 = r156859 * r156851;
        double r156861 = r156856 + r156860;
        return r156861;
}

double f(double x_re, double x_im) {
        double r156862 = x_re;
        double r156863 = 3.0;
        double r156864 = x_im;
        double r156865 = r156864 * r156862;
        double r156866 = r156863 * r156865;
        double r156867 = pow(r156864, r156863);
        double r156868 = -r156867;
        double r156869 = fma(r156862, r156866, r156868);
        return r156869;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.6
Target0.2
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, 3 \cdot \left(x.im \cdot x.re\right), -{x.im}^{3}\right)}\]
  3. Final simplification0.2

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

Reproduce

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