Average Error: 7.2 → 0.2
Time: 18.3s
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.re \cdot \left(x.im + x.re\right) + x.im \cdot \left(x.re + x.re\right)\right) \cdot \left(-x.im\right) + \left(x.re \cdot \left(x.im + x.re\right)\right) \cdot x.re\]
\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.re \cdot \left(x.im + x.re\right) + x.im \cdot \left(x.re + x.re\right)\right) \cdot \left(-x.im\right) + \left(x.re \cdot \left(x.im + x.re\right)\right) \cdot x.re
double f(double x_re, double x_im) {
        double r7829046 = x_re;
        double r7829047 = r7829046 * r7829046;
        double r7829048 = x_im;
        double r7829049 = r7829048 * r7829048;
        double r7829050 = r7829047 - r7829049;
        double r7829051 = r7829050 * r7829046;
        double r7829052 = r7829046 * r7829048;
        double r7829053 = r7829048 * r7829046;
        double r7829054 = r7829052 + r7829053;
        double r7829055 = r7829054 * r7829048;
        double r7829056 = r7829051 - r7829055;
        return r7829056;
}

double f(double x_re, double x_im) {
        double r7829057 = x_re;
        double r7829058 = x_im;
        double r7829059 = r7829058 + r7829057;
        double r7829060 = r7829057 * r7829059;
        double r7829061 = r7829057 + r7829057;
        double r7829062 = r7829058 * r7829061;
        double r7829063 = r7829060 + r7829062;
        double r7829064 = -r7829058;
        double r7829065 = r7829063 * r7829064;
        double r7829066 = r7829060 * r7829057;
        double r7829067 = r7829065 + r7829066;
        return r7829067;
}

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

Derivation

  1. Initial program 7.2

    \[\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. Taylor expanded around 0 7.1

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

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019163 
(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)))