Average Error: 7.0 → 0.2
Time: 37.7s
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.re + x.im, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)\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.re + x.im, \left(x.re - x.im\right) \cdot x.re, \left(-x.im\right) \cdot \left(\left(x.re + x.re\right) \cdot x.im\right)\right)
double f(double x_re, double x_im) {
        double r10553637 = x_re;
        double r10553638 = r10553637 * r10553637;
        double r10553639 = x_im;
        double r10553640 = r10553639 * r10553639;
        double r10553641 = r10553638 - r10553640;
        double r10553642 = r10553641 * r10553637;
        double r10553643 = r10553637 * r10553639;
        double r10553644 = r10553639 * r10553637;
        double r10553645 = r10553643 + r10553644;
        double r10553646 = r10553645 * r10553639;
        double r10553647 = r10553642 - r10553646;
        return r10553647;
}

double f(double x_re, double x_im) {
        double r10553648 = x_re;
        double r10553649 = x_im;
        double r10553650 = r10553648 + r10553649;
        double r10553651 = r10553648 - r10553649;
        double r10553652 = r10553651 * r10553648;
        double r10553653 = -r10553649;
        double r10553654 = r10553648 + r10553648;
        double r10553655 = r10553654 * r10553649;
        double r10553656 = r10553653 * r10553655;
        double r10553657 = fma(r10553650, r10553652, r10553656);
        return r10553657;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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. Using strategy rm
  3. Applied difference-of-squares7.0

    \[\leadsto \color{blue}{\left(\left(x.re + x.im\right) \cdot \left(x.re - x.im\right)\right)} \cdot x.re - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  4. Applied associate-*l*0.2

    \[\leadsto \color{blue}{\left(x.re + x.im\right) \cdot \left(\left(x.re - x.im\right) \cdot x.re\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  5. Using strategy rm
  6. Applied fma-neg0.2

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

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

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

Reproduce

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