Average Error: 7.7 → 0.2
Time: 45.0s
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.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot \left(x.re + x.re\right)\right) \cdot x.im\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.im + x.re, \left(x.re - x.im\right) \cdot x.re, \left(\left(-x.im\right) \cdot \left(x.re + x.re\right)\right) \cdot x.im\right)
double f(double x_re, double x_im) {
        double r4873139 = x_re;
        double r4873140 = r4873139 * r4873139;
        double r4873141 = x_im;
        double r4873142 = r4873141 * r4873141;
        double r4873143 = r4873140 - r4873142;
        double r4873144 = r4873143 * r4873139;
        double r4873145 = r4873139 * r4873141;
        double r4873146 = r4873141 * r4873139;
        double r4873147 = r4873145 + r4873146;
        double r4873148 = r4873147 * r4873141;
        double r4873149 = r4873144 - r4873148;
        return r4873149;
}

double f(double x_re, double x_im) {
        double r4873150 = x_im;
        double r4873151 = x_re;
        double r4873152 = r4873150 + r4873151;
        double r4873153 = r4873151 - r4873150;
        double r4873154 = r4873153 * r4873151;
        double r4873155 = -r4873150;
        double r4873156 = r4873151 + r4873151;
        double r4873157 = r4873155 * r4873156;
        double r4873158 = r4873157 * r4873150;
        double r4873159 = fma(r4873152, r4873154, r4873158);
        return r4873159;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

Original7.7
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.0 \cdot x.im\right)\]

Derivation

  1. Initial program 7.7

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

    \[\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\right) \cdot \left(x.im \cdot \left(x.re + x.re\right)\right)}\right)\]
  8. Final simplification0.2

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

Reproduce

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