Average Error: 6.2 → 0.2
Time: 2.0m
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\]
\[{x.re}^{3} - \left(x.im + \left(x.im + x.im\right)\right) \cdot \left(x.im \cdot x.re\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
{x.re}^{3} - \left(x.im + \left(x.im + x.im\right)\right) \cdot \left(x.im \cdot x.re\right)
double f(double x_re, double x_im) {
        double r48785607 = x_re;
        double r48785608 = r48785607 * r48785607;
        double r48785609 = x_im;
        double r48785610 = r48785609 * r48785609;
        double r48785611 = r48785608 - r48785610;
        double r48785612 = r48785611 * r48785607;
        double r48785613 = r48785607 * r48785609;
        double r48785614 = r48785609 * r48785607;
        double r48785615 = r48785613 + r48785614;
        double r48785616 = r48785615 * r48785609;
        double r48785617 = r48785612 - r48785616;
        return r48785617;
}

double f(double x_re, double x_im) {
        double r48785618 = x_re;
        double r48785619 = 3.0;
        double r48785620 = pow(r48785618, r48785619);
        double r48785621 = x_im;
        double r48785622 = r48785621 + r48785621;
        double r48785623 = r48785621 + r48785622;
        double r48785624 = r48785621 * r48785618;
        double r48785625 = r48785623 * r48785624;
        double r48785626 = r48785620 - r48785625;
        return r48785626;
}

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.2
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 6.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. Simplified0.2

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

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

    \[\leadsto \color{blue}{{x.re}^{1}} \cdot {x.re}^{2} - \left(x.re \cdot x.im\right) \cdot \left(x.im + \left(x.im + x.im\right)\right)\]
  6. Applied pow-prod-up0.2

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

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

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

Reproduce

herbie shell --seed 2019125 +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 x.im))))

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