Average Error: 7.2 → 0.2
Time: 3.0s
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(3, \left(x.im \cdot x.re\right) \cdot 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(3, \left(x.im \cdot x.re\right) \cdot x.re, -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r135536 = x_re;
        double r135537 = r135536 * r135536;
        double r135538 = x_im;
        double r135539 = r135538 * r135538;
        double r135540 = r135537 - r135539;
        double r135541 = r135540 * r135538;
        double r135542 = r135536 * r135538;
        double r135543 = r135538 * r135536;
        double r135544 = r135542 + r135543;
        double r135545 = r135544 * r135536;
        double r135546 = r135541 + r135545;
        return r135546;
}

double f(double x_re, double x_im) {
        double r135547 = 3.0;
        double r135548 = x_im;
        double r135549 = x_re;
        double r135550 = r135548 * r135549;
        double r135551 = r135550 * r135549;
        double r135552 = pow(r135548, r135547);
        double r135553 = -r135552;
        double r135554 = fma(r135547, r135551, r135553);
        return r135554;
}

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

    \[\leadsto \color{blue}{3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right) - {x.im}^{3}}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

    \[\leadsto 3 \cdot \color{blue}{\left(\left(x.im \cdot x.re\right) \cdot x.re\right)} - {x.im}^{3}\]
  5. Using strategy rm
  6. Applied fma-neg0.2

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

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

Reproduce

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