Average Error: 7.3 → 0.2
Time: 3.9s
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\]
\[\left(-3 \cdot \left(x.re \cdot x.im\right)\right) \cdot x.im + {x.re}^{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
\left(-3 \cdot \left(x.re \cdot x.im\right)\right) \cdot x.im + {x.re}^{3}
double f(double x_re, double x_im) {
        double r226355 = x_re;
        double r226356 = r226355 * r226355;
        double r226357 = x_im;
        double r226358 = r226357 * r226357;
        double r226359 = r226356 - r226358;
        double r226360 = r226359 * r226355;
        double r226361 = r226355 * r226357;
        double r226362 = r226357 * r226355;
        double r226363 = r226361 + r226362;
        double r226364 = r226363 * r226357;
        double r226365 = r226360 - r226364;
        return r226365;
}

double f(double x_re, double x_im) {
        double r226366 = -3.0;
        double r226367 = x_re;
        double r226368 = x_im;
        double r226369 = r226367 * r226368;
        double r226370 = r226366 * r226369;
        double r226371 = r226370 * r226368;
        double r226372 = 3.0;
        double r226373 = pow(r226367, r226372);
        double r226374 = r226371 + r226373;
        return r226374;
}

Error

Bits error versus x.re

Bits error versus x.im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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

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

    \[\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. Using strategy rm
  7. Applied fma-udef0.2

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

    \[\leadsto \color{blue}{-3 \cdot \left(\left(x.re \cdot x.im\right) \cdot x.im\right)} + {x.re}^{3}\]
  9. Using strategy rm
  10. Applied associate-*r*0.2

    \[\leadsto \color{blue}{\left(-3 \cdot \left(x.re \cdot x.im\right)\right) \cdot x.im} + {x.re}^{3}\]
  11. Final simplification0.2

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

Reproduce

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