Average Error: 7.3 → 0.2
Time: 14.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 r336812 = x_re;
        double r336813 = r336812 * r336812;
        double r336814 = x_im;
        double r336815 = r336814 * r336814;
        double r336816 = r336813 - r336815;
        double r336817 = r336816 * r336812;
        double r336818 = r336812 * r336814;
        double r336819 = r336814 * r336812;
        double r336820 = r336818 + r336819;
        double r336821 = r336820 * r336814;
        double r336822 = r336817 - r336821;
        return r336822;
}

double f(double x_re, double x_im) {
        double r336823 = -3.0;
        double r336824 = x_re;
        double r336825 = x_im;
        double r336826 = r336824 * r336825;
        double r336827 = r336823 * r336826;
        double r336828 = 3.0;
        double r336829 = pow(r336824, r336828);
        double r336830 = fma(r336827, r336825, r336829);
        return r336830;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.3
Target0.3
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(-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 2020042 +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)))