Average Error: 7.1 → 0.2
Time: 22.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 \cdot -3, x.im \cdot x.re, {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(x.im \cdot -3, x.im \cdot x.re, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r103072 = x_re;
        double r103073 = r103072 * r103072;
        double r103074 = x_im;
        double r103075 = r103074 * r103074;
        double r103076 = r103073 - r103075;
        double r103077 = r103076 * r103072;
        double r103078 = r103072 * r103074;
        double r103079 = r103074 * r103072;
        double r103080 = r103078 + r103079;
        double r103081 = r103080 * r103074;
        double r103082 = r103077 - r103081;
        return r103082;
}

double f(double x_re, double x_im) {
        double r103083 = x_im;
        double r103084 = -3.0;
        double r103085 = r103083 * r103084;
        double r103086 = x_re;
        double r103087 = r103083 * r103086;
        double r103088 = 3.0;
        double r103089 = pow(r103086, r103088);
        double r103090 = fma(r103085, r103087, r103089);
        return r103090;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

    \[\leadsto \color{blue}{x.im \cdot \left(-3 \cdot \left(x.im \cdot x.re\right)\right) + {x.re}^{3}}\]
  5. Taylor expanded around 0 7.1

    \[\leadsto \color{blue}{{x.re}^{3} - 3 \cdot \left({x.im}^{2} \cdot x.re\right)}\]
  6. Simplified0.2

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

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

Reproduce

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