Average Error: 6.8 → 0.2
Time: 29.7s
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 \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.re \cdot \left(x.im + x.re\right), x.re - x.im, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\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 \cdot x.im + x.re \cdot x.im, x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right) + \mathsf{fma}\left(x.re \cdot \left(x.im + x.re\right), x.re - x.im, \left(-x.im\right) \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r3598818 = x_re;
        double r3598819 = r3598818 * r3598818;
        double r3598820 = x_im;
        double r3598821 = r3598820 * r3598820;
        double r3598822 = r3598819 - r3598821;
        double r3598823 = r3598822 * r3598818;
        double r3598824 = r3598818 * r3598820;
        double r3598825 = r3598820 * r3598818;
        double r3598826 = r3598824 + r3598825;
        double r3598827 = r3598826 * r3598820;
        double r3598828 = r3598823 - r3598827;
        return r3598828;
}

double f(double x_re, double x_im) {
        double r3598829 = x_im;
        double r3598830 = -r3598829;
        double r3598831 = x_re;
        double r3598832 = r3598831 * r3598829;
        double r3598833 = r3598832 + r3598832;
        double r3598834 = r3598829 * r3598833;
        double r3598835 = fma(r3598830, r3598833, r3598834);
        double r3598836 = r3598829 + r3598831;
        double r3598837 = r3598831 * r3598836;
        double r3598838 = r3598831 - r3598829;
        double r3598839 = r3598830 * r3598833;
        double r3598840 = fma(r3598837, r3598838, r3598839);
        double r3598841 = r3598835 + r3598840;
        return r3598841;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original6.8
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 6.8

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

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

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

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

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

Reproduce

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