Average Error: 6.6 → 0.2
Time: 18.2s
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(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, x.im \cdot \left(x.re \cdot \left(-x.im\right) + x.re \cdot \left(-x.im\right)\right)\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(x.im + x.re, \left(x.re - x.im\right) \cdot x.re, x.im \cdot \left(x.re \cdot \left(-x.im\right) + x.re \cdot \left(-x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r3132472 = x_re;
        double r3132473 = r3132472 * r3132472;
        double r3132474 = x_im;
        double r3132475 = r3132474 * r3132474;
        double r3132476 = r3132473 - r3132475;
        double r3132477 = r3132476 * r3132472;
        double r3132478 = r3132472 * r3132474;
        double r3132479 = r3132474 * r3132472;
        double r3132480 = r3132478 + r3132479;
        double r3132481 = r3132480 * r3132474;
        double r3132482 = r3132477 - r3132481;
        return r3132482;
}

double f(double x_re, double x_im) {
        double r3132483 = x_im;
        double r3132484 = x_re;
        double r3132485 = r3132483 + r3132484;
        double r3132486 = r3132484 - r3132483;
        double r3132487 = r3132486 * r3132484;
        double r3132488 = -r3132483;
        double r3132489 = r3132484 * r3132488;
        double r3132490 = r3132489 + r3132489;
        double r3132491 = r3132483 * r3132490;
        double r3132492 = fma(r3132485, r3132487, r3132491);
        return r3132492;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.6
Target0.3
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 6.6

    \[\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. Taylor expanded around -inf 6.5

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x.re + x.im, x.re \cdot \left(x.re - x.im\right), -\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\right)}\]
  6. Simplified0.2

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

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

Reproduce

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

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