Average Error: 6.6 → 0.3
Time: 27.2s
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(x.im + x.re\right) \cdot \left(x.re \cdot x.re\right) + \left(-x.im\right) \cdot \left(\left(x.re + x.re\right) \cdot x.im + x.re \cdot \left(x.im + x.re\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
\left(x.im + x.re\right) \cdot \left(x.re \cdot x.re\right) + \left(-x.im\right) \cdot \left(\left(x.re + x.re\right) \cdot x.im + x.re \cdot \left(x.im + x.re\right)\right)
double f(double x_re, double x_im) {
        double r10479332 = x_re;
        double r10479333 = r10479332 * r10479332;
        double r10479334 = x_im;
        double r10479335 = r10479334 * r10479334;
        double r10479336 = r10479333 - r10479335;
        double r10479337 = r10479336 * r10479332;
        double r10479338 = r10479332 * r10479334;
        double r10479339 = r10479334 * r10479332;
        double r10479340 = r10479338 + r10479339;
        double r10479341 = r10479340 * r10479334;
        double r10479342 = r10479337 - r10479341;
        return r10479342;
}

double f(double x_re, double x_im) {
        double r10479343 = x_im;
        double r10479344 = x_re;
        double r10479345 = r10479343 + r10479344;
        double r10479346 = r10479344 * r10479344;
        double r10479347 = r10479345 * r10479346;
        double r10479348 = -r10479343;
        double r10479349 = r10479344 + r10479344;
        double r10479350 = r10479349 * r10479343;
        double r10479351 = r10479344 * r10479345;
        double r10479352 = r10479350 + r10479351;
        double r10479353 = r10479348 * r10479352;
        double r10479354 = r10479347 + r10479353;
        return r10479354;
}

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

Original6.6
Target0.3
Herbie0.3
\[\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 6.6

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

    \[\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 *-commutative0.2

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

    \[\leadsto \left(x.re + x.im\right) \cdot \left(x.re \cdot \color{blue}{\left(x.re + \left(-x.im\right)\right)}\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  9. Applied distribute-lft-in0.3

    \[\leadsto \left(x.re + x.im\right) \cdot \color{blue}{\left(x.re \cdot x.re + x.re \cdot \left(-x.im\right)\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im\]
  10. Applied distribute-lft-in0.3

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

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

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

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

Reproduce

herbie shell --seed 2019162 
(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 x.im))))

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