Average Error: 7.5 → 0.2
Time: 18.5s
Precision: 64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[\mathsf{fma}\left(x.re, x.im \cdot \left(3 \cdot x.re\right), -{x.im}^{3}\right)\]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\mathsf{fma}\left(x.re, x.im \cdot \left(3 \cdot x.re\right), -{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r167823 = x_re;
        double r167824 = r167823 * r167823;
        double r167825 = x_im;
        double r167826 = r167825 * r167825;
        double r167827 = r167824 - r167826;
        double r167828 = r167827 * r167825;
        double r167829 = r167823 * r167825;
        double r167830 = r167825 * r167823;
        double r167831 = r167829 + r167830;
        double r167832 = r167831 * r167823;
        double r167833 = r167828 + r167832;
        return r167833;
}

double f(double x_re, double x_im) {
        double r167834 = x_re;
        double r167835 = x_im;
        double r167836 = 3.0;
        double r167837 = r167836 * r167834;
        double r167838 = r167835 * r167837;
        double r167839 = pow(r167835, r167836);
        double r167840 = -r167839;
        double r167841 = fma(r167834, r167838, r167840);
        return r167841;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.5
Target0.2
Herbie0.2
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)\]

Derivation

  1. Initial program 7.5

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Simplified0.2

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

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

Reproduce

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

  :herbie-target
  (+ (* (* x.re x.im) (* 2 x.re)) (* (* x.im (- x.re x.im)) (+ x.re x.im)))

  (+ (* (- (* x.re x.re) (* x.im x.im)) x.im) (* (+ (* x.re x.im) (* x.im x.re)) x.re)))