Average Error: 7.4 → 0.2
Time: 27.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, x.im \cdot \left(x.re \cdot 3\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(x.re \cdot 3\right), -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r132335 = x_re;
        double r132336 = r132335 * r132335;
        double r132337 = x_im;
        double r132338 = r132337 * r132337;
        double r132339 = r132336 - r132338;
        double r132340 = r132339 * r132337;
        double r132341 = r132335 * r132337;
        double r132342 = r132337 * r132335;
        double r132343 = r132341 + r132342;
        double r132344 = r132343 * r132335;
        double r132345 = r132340 + r132344;
        return r132345;
}

double f(double x_re, double x_im) {
        double r132346 = x_re;
        double r132347 = x_im;
        double r132348 = 3.0;
        double r132349 = r132346 * r132348;
        double r132350 = r132347 * r132349;
        double r132351 = pow(r132347, r132348);
        double r132352 = -r132351;
        double r132353 = fma(r132346, r132350, r132352);
        return r132353;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.4
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.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, 3 \cdot \left(x.im \cdot x.re\right), -{x.im}^{3}\right)}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt0.4

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

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

    \[\leadsto \mathsf{fma}\left(x.re, \sqrt{\color{blue}{1 \cdot 3}} \cdot \left(\sqrt{3} \cdot \left(x.im \cdot x.re\right)\right), -{x.im}^{3}\right)\]
  8. Applied sqrt-prod0.3

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

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

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

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

Reproduce

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