Average Error: 7.2 → 0.2
Time: 15.7s
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(\left(x.im \cdot x.re\right) \cdot 3, 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(\left(x.im \cdot x.re\right) \cdot 3, x.re, -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r142145 = x_re;
        double r142146 = r142145 * r142145;
        double r142147 = x_im;
        double r142148 = r142147 * r142147;
        double r142149 = r142146 - r142148;
        double r142150 = r142149 * r142147;
        double r142151 = r142145 * r142147;
        double r142152 = r142147 * r142145;
        double r142153 = r142151 + r142152;
        double r142154 = r142153 * r142145;
        double r142155 = r142150 + r142154;
        return r142155;
}

double f(double x_re, double x_im) {
        double r142156 = x_im;
        double r142157 = x_re;
        double r142158 = r142156 * r142157;
        double r142159 = 3.0;
        double r142160 = r142158 * r142159;
        double r142161 = pow(r142156, r142159);
        double r142162 = -r142161;
        double r142163 = fma(r142160, r142157, r142162);
        return r142163;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

Reproduce

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

  :herbie-target
  (+ (* (* x.re x.im) (* 2.0 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)))