Average Error: 6.6 → 0.3
Time: 21.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\]
\[\left(x.re + x.im\right) \cdot \left(x.re \cdot x.re\right) + \left(-x.im\right) \cdot \left(x.im \cdot \left(x.re + x.re\right) + x.re \cdot \left(x.re + x.im\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.re + x.im\right) \cdot \left(x.re \cdot x.re\right) + \left(-x.im\right) \cdot \left(x.im \cdot \left(x.re + x.re\right) + x.re \cdot \left(x.re + x.im\right)\right)
double f(double x_re, double x_im) {
        double r10198841 = x_re;
        double r10198842 = r10198841 * r10198841;
        double r10198843 = x_im;
        double r10198844 = r10198843 * r10198843;
        double r10198845 = r10198842 - r10198844;
        double r10198846 = r10198845 * r10198841;
        double r10198847 = r10198841 * r10198843;
        double r10198848 = r10198843 * r10198841;
        double r10198849 = r10198847 + r10198848;
        double r10198850 = r10198849 * r10198843;
        double r10198851 = r10198846 - r10198850;
        return r10198851;
}

double f(double x_re, double x_im) {
        double r10198852 = x_re;
        double r10198853 = x_im;
        double r10198854 = r10198852 + r10198853;
        double r10198855 = r10198852 * r10198852;
        double r10198856 = r10198854 * r10198855;
        double r10198857 = -r10198853;
        double r10198858 = r10198852 + r10198852;
        double r10198859 = r10198853 * r10198858;
        double r10198860 = r10198852 * r10198854;
        double r10198861 = r10198859 + r10198860;
        double r10198862 = r10198857 * r10198861;
        double r10198863 = r10198856 + r10198862;
        return r10198863;
}

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-rgt-in0.3

    \[\leadsto \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot \left(x.re + x.im\right) + \left(x.re \cdot \left(-x.im\right)\right) \cdot \left(x.re + x.im\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 \cdot x.re\right) \cdot \left(x.re + x.im\right) + \left(\left(x.re \cdot \left(-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\right)}\]
  12. Simplified0.3

    \[\leadsto \left(x.re \cdot x.re\right) \cdot \left(x.re + x.im\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.re + x.im\right) \cdot \left(x.re \cdot x.re\right) + \left(-x.im\right) \cdot \left(x.im \cdot \left(x.re + x.re\right) + x.re \cdot \left(x.re + x.im\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)))