Average Error: 6.7 → 0.2
Time: 28.9s
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 r8568807 = x_re;
        double r8568808 = r8568807 * r8568807;
        double r8568809 = x_im;
        double r8568810 = r8568809 * r8568809;
        double r8568811 = r8568808 - r8568810;
        double r8568812 = r8568811 * r8568807;
        double r8568813 = r8568807 * r8568809;
        double r8568814 = r8568809 * r8568807;
        double r8568815 = r8568813 + r8568814;
        double r8568816 = r8568815 * r8568809;
        double r8568817 = r8568812 - r8568816;
        return r8568817;
}

double f(double x_re, double x_im) {
        double r8568818 = x_im;
        double r8568819 = -r8568818;
        double r8568820 = x_re;
        double r8568821 = r8568820 * r8568818;
        double r8568822 = r8568821 + r8568821;
        double r8568823 = r8568818 * r8568822;
        double r8568824 = fma(r8568819, r8568822, r8568823);
        double r8568825 = r8568818 + r8568820;
        double r8568826 = r8568820 * r8568825;
        double r8568827 = r8568820 - r8568818;
        double r8568828 = r8568819 * r8568822;
        double r8568829 = fma(r8568826, r8568827, r8568828);
        double r8568830 = r8568824 + r8568829;
        return r8568830;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

    \[\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 2019139 +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)))