Average Error: 7.3 → 0.2
Time: 4.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, \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 r230019 = x_re;
        double r230020 = r230019 * r230019;
        double r230021 = x_im;
        double r230022 = r230021 * r230021;
        double r230023 = r230020 - r230022;
        double r230024 = r230023 * r230019;
        double r230025 = r230019 * r230021;
        double r230026 = r230021 * r230019;
        double r230027 = r230025 + r230026;
        double r230028 = r230027 * r230021;
        double r230029 = r230024 - r230028;
        return r230029;
}

double f(double x_re, double x_im) {
        double r230030 = 3.0;
        double r230031 = x_re;
        double r230032 = x_im;
        double r230033 = r230031 * r230032;
        double r230034 = -r230032;
        double r230035 = r230033 * r230034;
        double r230036 = pow(r230031, r230030);
        double r230037 = fma(r230030, r230035, r230036);
        return r230037;
}

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

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

    \[\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 2020027 +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)))