Average Error: 7.4 → 0.2
Time: 16.4s
Precision: 64
\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
\[\left(x.re \cdot 3\right) \cdot \left(x.im \cdot x.re\right) + \left(-{x.im}^{3}\right)\]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\left(x.re \cdot 3\right) \cdot \left(x.im \cdot x.re\right) + \left(-{x.im}^{3}\right)
double f(double x_re, double x_im) {
        double r157138 = x_re;
        double r157139 = r157138 * r157138;
        double r157140 = x_im;
        double r157141 = r157140 * r157140;
        double r157142 = r157139 - r157141;
        double r157143 = r157142 * r157140;
        double r157144 = r157138 * r157140;
        double r157145 = r157140 * r157138;
        double r157146 = r157144 + r157145;
        double r157147 = r157146 * r157138;
        double r157148 = r157143 + r157147;
        return r157148;
}

double f(double x_re, double x_im) {
        double r157149 = x_re;
        double r157150 = 3.0;
        double r157151 = r157149 * r157150;
        double r157152 = x_im;
        double r157153 = r157152 * r157149;
        double r157154 = r157151 * r157153;
        double r157155 = pow(r157152, r157150);
        double r157156 = -r157155;
        double r157157 = r157154 + r157156;
        return r157157;
}

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.4
Target0.2
Herbie0.2
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right)\]

Derivation

  1. Initial program 7.4

    \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re\]
  2. Simplified0.2

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

    \[\leadsto \mathsf{fma}\left(x.re, \color{blue}{\left(x.im \cdot 3\right) \cdot x.re}, -{x.im}^{3}\right)\]
  5. Using strategy rm
  6. Applied fma-udef0.2

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

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

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

Reproduce

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

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

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