Average Error: 7.2 → 0.2
Time: 24.9s
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(-3, \left(x.im \cdot x.re\right) \cdot x.im, {x.re}^{3}\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(-3, \left(x.im \cdot x.re\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r119145 = x_re;
        double r119146 = r119145 * r119145;
        double r119147 = x_im;
        double r119148 = r119147 * r119147;
        double r119149 = r119146 - r119148;
        double r119150 = r119149 * r119145;
        double r119151 = r119145 * r119147;
        double r119152 = r119147 * r119145;
        double r119153 = r119151 + r119152;
        double r119154 = r119153 * r119147;
        double r119155 = r119150 - r119154;
        return r119155;
}

double f(double x_re, double x_im) {
        double r119156 = -3.0;
        double r119157 = x_im;
        double r119158 = x_re;
        double r119159 = r119157 * r119158;
        double r119160 = r119159 * r119157;
        double r119161 = 3.0;
        double r119162 = pow(r119158, r119161);
        double r119163 = fma(r119156, r119160, r119162);
        return r119163;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

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

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{\left(\sqrt[3]{-3} \cdot \sqrt[3]{-3}\right) \cdot \left(\sqrt[3]{-3} \cdot \left(x.im \cdot x.re\right)\right)}, {x.re}^{3}\right)\]
  6. Taylor expanded around 0 7.1

    \[\leadsto \color{blue}{{x.re}^{3} - 3 \cdot \left({x.im}^{2} \cdot x.re\right)}\]
  7. Simplified0.2

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

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

Reproduce

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

  :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)))