Average Error: 7.3 → 0.2
Time: 12.4s
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(\left(-3 \cdot x.re\right) \cdot x.im, 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(\left(-3 \cdot x.re\right) \cdot x.im, x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r175806 = x_re;
        double r175807 = r175806 * r175806;
        double r175808 = x_im;
        double r175809 = r175808 * r175808;
        double r175810 = r175807 - r175809;
        double r175811 = r175810 * r175806;
        double r175812 = r175806 * r175808;
        double r175813 = r175808 * r175806;
        double r175814 = r175812 + r175813;
        double r175815 = r175814 * r175808;
        double r175816 = r175811 - r175815;
        return r175816;
}

double f(double x_re, double x_im) {
        double r175817 = -3.0;
        double r175818 = x_re;
        double r175819 = r175817 * r175818;
        double r175820 = x_im;
        double r175821 = r175819 * r175820;
        double r175822 = 3.0;
        double r175823 = pow(r175818, r175822);
        double r175824 = fma(r175821, r175820, r175823);
        return r175824;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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(-3 \cdot \left(x.re \cdot x.im\right), x.im, {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

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

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

Reproduce

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