Average Error: 7.3 → 0.2
Time: 9.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(x.im, -3 \cdot \left(x.re \cdot x.im\right), {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, -3 \cdot \left(x.re \cdot x.im\right), {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r271563 = x_re;
        double r271564 = r271563 * r271563;
        double r271565 = x_im;
        double r271566 = r271565 * r271565;
        double r271567 = r271564 - r271566;
        double r271568 = r271567 * r271563;
        double r271569 = r271563 * r271565;
        double r271570 = r271565 * r271563;
        double r271571 = r271569 + r271570;
        double r271572 = r271571 * r271565;
        double r271573 = r271568 - r271572;
        return r271573;
}

double f(double x_re, double x_im) {
        double r271574 = x_im;
        double r271575 = -3.0;
        double r271576 = x_re;
        double r271577 = r271576 * r271574;
        double r271578 = r271575 * r271577;
        double r271579 = 3.0;
        double r271580 = pow(r271576, r271579);
        double r271581 = fma(r271574, r271578, r271580);
        return r271581;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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.re \cdot x.im\right), {x.re}^{3}\right)}\]
  3. Final simplification0.2

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

Reproduce

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