Average Error: 6.9 → 0.2
Time: 19.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, \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, \left(x.re - x.im\right) \cdot x.re, \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 r3446886 = x_re;
        double r3446887 = r3446886 * r3446886;
        double r3446888 = x_im;
        double r3446889 = r3446888 * r3446888;
        double r3446890 = r3446887 - r3446889;
        double r3446891 = r3446890 * r3446886;
        double r3446892 = r3446886 * r3446888;
        double r3446893 = r3446888 * r3446886;
        double r3446894 = r3446892 + r3446893;
        double r3446895 = r3446894 * r3446888;
        double r3446896 = r3446891 - r3446895;
        return r3446896;
}

double f(double x_re, double x_im) {
        double r3446897 = x_im;
        double r3446898 = x_re;
        double r3446899 = r3446897 + r3446898;
        double r3446900 = r3446898 - r3446897;
        double r3446901 = r3446900 * r3446898;
        double r3446902 = -r3446897;
        double r3446903 = r3446898 * r3446897;
        double r3446904 = r3446903 + r3446903;
        double r3446905 = r3446902 * r3446904;
        double r3446906 = fma(r3446899, r3446901, r3446905);
        return r3446906;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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 0 6.8

    \[\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 + 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(-\left(x.im \cdot x.re + x.im \cdot x.re\right)\right)}\right)\]
  7. Final simplification0.2

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

Reproduce

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