Average Error: 7.5 → 0.2
Time: 15.3s
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(-3 \cdot \left(x.re \cdot x.im\right), 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(-3 \cdot \left(x.re \cdot x.im\right), x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r212378 = x_re;
        double r212379 = r212378 * r212378;
        double r212380 = x_im;
        double r212381 = r212380 * r212380;
        double r212382 = r212379 - r212381;
        double r212383 = r212382 * r212378;
        double r212384 = r212378 * r212380;
        double r212385 = r212380 * r212378;
        double r212386 = r212384 + r212385;
        double r212387 = r212386 * r212380;
        double r212388 = r212383 - r212387;
        return r212388;
}

double f(double x_re, double x_im) {
        double r212389 = -3.0;
        double r212390 = x_re;
        double r212391 = x_im;
        double r212392 = r212390 * r212391;
        double r212393 = r212389 * r212392;
        double r212394 = 3.0;
        double r212395 = pow(r212390, r212394);
        double r212396 = fma(r212393, r212391, r212395);
        return r212396;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Final simplification0.2

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

Reproduce

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