Average Error: 7.3 → 0.2
Time: 14.1s
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.im \cdot x.re\right) \cdot 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, \left(x.im \cdot x.re\right) \cdot x.im, {x.re}^{3}\right)
double f(double x_re, double x_im) {
        double r217020 = x_re;
        double r217021 = r217020 * r217020;
        double r217022 = x_im;
        double r217023 = r217022 * r217022;
        double r217024 = r217021 - r217023;
        double r217025 = r217024 * r217020;
        double r217026 = r217020 * r217022;
        double r217027 = r217022 * r217020;
        double r217028 = r217026 + r217027;
        double r217029 = r217028 * r217022;
        double r217030 = r217025 - r217029;
        return r217030;
}

double f(double x_re, double x_im) {
        double r217031 = -3.0;
        double r217032 = x_im;
        double r217033 = x_re;
        double r217034 = r217032 * r217033;
        double r217035 = r217034 * r217032;
        double r217036 = 3.0;
        double r217037 = pow(r217033, r217036);
        double r217038 = fma(r217031, r217035, r217037);
        return r217038;
}

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(x.im, 3 \cdot \left(\left(-x.im\right) \cdot x.re\right), {x.re}^{3}\right)}\]
  3. Using strategy rm
  4. Applied associate-*r*0.2

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

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{\left(-3 \cdot x.im\right)} \cdot x.re, {x.re}^{3}\right)\]
  6. Using strategy rm
  7. Applied associate-*l*0.2

    \[\leadsto \mathsf{fma}\left(x.im, \color{blue}{-3 \cdot \left(x.im \cdot x.re\right)}, {x.re}^{3}\right)\]
  8. Taylor expanded around 0 7.3

    \[\leadsto \color{blue}{{x.re}^{3} - 3 \cdot \left({x.im}^{2} \cdot x.re\right)}\]
  9. Simplified0.2

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

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

Reproduce

herbie shell --seed 2019198 +o rules:numerics
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"

  :herbie-target
  (+ (* (* x.re x.re) (- x.re x.im)) (* (* x.re x.im) (- x.re (* 3.0 x.im))))

  (- (* (- (* x.re x.re) (* x.im x.im)) x.re) (* (+ (* x.re x.im) (* x.im x.re)) x.im)))