Average Error: 7.4 → 0.2
Time: 18.0s
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, \left(x.im \cdot x.re\right) \cdot -3, {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, \left(x.im \cdot x.re\right) \cdot -3, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r124798 = x_re;
        double r124799 = r124798 * r124798;
        double r124800 = x_im;
        double r124801 = r124800 * r124800;
        double r124802 = r124799 - r124801;
        double r124803 = r124802 * r124798;
        double r124804 = r124798 * r124800;
        double r124805 = r124800 * r124798;
        double r124806 = r124804 + r124805;
        double r124807 = r124806 * r124800;
        double r124808 = r124803 - r124807;
        return r124808;
}

double f(double x_re, double x_im) {
        double r124809 = x_im;
        double r124810 = x_re;
        double r124811 = r124809 * r124810;
        double r124812 = -3.0;
        double r124813 = r124811 * r124812;
        double r124814 = 3.0;
        double r124815 = pow(r124810, r124814);
        double r124816 = fma(r124809, r124813, r124815);
        return r124816;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

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

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

Reproduce

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