Average Error: 7.4 → 0.2
Time: 18.3s
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, x.im \cdot \left(3 \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, x.im \cdot \left(3 \cdot x.re\right), -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r111055 = x_re;
        double r111056 = r111055 * r111055;
        double r111057 = x_im;
        double r111058 = r111057 * r111057;
        double r111059 = r111056 - r111058;
        double r111060 = r111059 * r111057;
        double r111061 = r111055 * r111057;
        double r111062 = r111057 * r111055;
        double r111063 = r111061 + r111062;
        double r111064 = r111063 * r111055;
        double r111065 = r111060 + r111064;
        return r111065;
}

double f(double x_re, double x_im) {
        double r111066 = x_re;
        double r111067 = x_im;
        double r111068 = 3.0;
        double r111069 = r111068 * r111066;
        double r111070 = r111067 * r111069;
        double r111071 = pow(r111067, r111068);
        double r111072 = -r111071;
        double r111073 = fma(r111066, r111070, r111072);
        return r111073;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Final simplification0.2

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

Reproduce

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