Average Error: 7.7 → 0.2
Time: 55.6s
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, x.re \cdot x.re - x.re \cdot x.im, \left(x.re \cdot x.im\right) \cdot \left(-\left(x.im + x.im\right)\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.im + x.re, x.re \cdot x.re - x.re \cdot x.im, \left(x.re \cdot x.im\right) \cdot \left(-\left(x.im + x.im\right)\right)\right)
double f(double x_re, double x_im) {
        double r7689135 = x_re;
        double r7689136 = r7689135 * r7689135;
        double r7689137 = x_im;
        double r7689138 = r7689137 * r7689137;
        double r7689139 = r7689136 - r7689138;
        double r7689140 = r7689139 * r7689135;
        double r7689141 = r7689135 * r7689137;
        double r7689142 = r7689137 * r7689135;
        double r7689143 = r7689141 + r7689142;
        double r7689144 = r7689143 * r7689137;
        double r7689145 = r7689140 - r7689144;
        return r7689145;
}

double f(double x_re, double x_im) {
        double r7689146 = x_im;
        double r7689147 = x_re;
        double r7689148 = r7689146 + r7689147;
        double r7689149 = r7689147 * r7689147;
        double r7689150 = r7689147 * r7689146;
        double r7689151 = r7689149 - r7689150;
        double r7689152 = r7689146 + r7689146;
        double r7689153 = -r7689152;
        double r7689154 = r7689150 * r7689153;
        double r7689155 = fma(r7689148, r7689151, r7689154);
        return r7689155;
}

Error

Bits error versus x.re

Bits error versus x.im

Target

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

    \[\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.re \cdot x.im\right) \cdot \left(x.im + x.im\right)}\right)\]
  8. Taylor expanded around 0 0.2

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

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

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

Reproduce

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