Average Error: 7.5 → 0.2
Time: 3.6s
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, \left(x.re \cdot x.im\right) \cdot \left(-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(3, \left(x.re \cdot x.im\right) \cdot \left(-x.im\right), {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r235146 = x_re;
        double r235147 = r235146 * r235146;
        double r235148 = x_im;
        double r235149 = r235148 * r235148;
        double r235150 = r235147 - r235149;
        double r235151 = r235150 * r235146;
        double r235152 = r235146 * r235148;
        double r235153 = r235148 * r235146;
        double r235154 = r235152 + r235153;
        double r235155 = r235154 * r235148;
        double r235156 = r235151 - r235155;
        return r235156;
}

double f(double x_re, double x_im) {
        double r235157 = 3.0;
        double r235158 = x_re;
        double r235159 = x_im;
        double r235160 = r235158 * r235159;
        double r235161 = -r235159;
        double r235162 = r235160 * r235161;
        double r235163 = pow(r235158, r235157);
        double r235164 = fma(r235157, r235162, r235163);
        return r235164;
}

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, x.re \cdot \left(-x.im \cdot x.im\right), {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied distribute-rgt-neg-in7.5

    \[\leadsto \mathsf{fma}\left(3, x.re \cdot \color{blue}{\left(x.im \cdot \left(-x.im\right)\right)}, {x.re}^{3}\right)\]
  5. Applied associate-*r*0.2

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

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

Reproduce

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