Average Error: 7.2 → 3.8
Time: 3.6s
Precision: binary64
\[\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 \]
\[\begin{array}{l} \mathbf{if}\;x.re \leq -2.1348970050771735 \cdot 10^{-305}:\\ \;\;\;\;\left({x.re}^{3} - x.re \cdot {x.im}^{2}\right) - x.im \cdot \left(2 \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left({x.re}^{3} - {\left(x.im \cdot \sqrt{x.re}\right)}^{2}\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \end{array} \]
\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
\begin{array}{l}
\mathbf{if}\;x.re \leq -2.1348970050771735 \cdot 10^{-305}:\\
\;\;\;\;\left({x.re}^{3} - x.re \cdot {x.im}^{2}\right) - x.im \cdot \left(2 \cdot \left(x.re \cdot x.im\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left({x.re}^{3} - {\left(x.im \cdot \sqrt{x.re}\right)}^{2}\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\


\end{array}
(FPCore (x.re x.im)
 :precision binary64
 (-
  (* (- (* x.re x.re) (* x.im x.im)) x.re)
  (* (+ (* x.re x.im) (* x.im x.re)) x.im)))
(FPCore (x.re x.im)
 :precision binary64
 (if (<= x.re -2.1348970050771735e-305)
   (-
    (- (pow x.re 3.0) (* x.re (pow x.im 2.0)))
    (* x.im (* 2.0 (* x.re x.im))))
   (-
    (- (pow x.re 3.0) (pow (* x.im (sqrt x.re)) 2.0))
    (* x.im (+ (* x.re x.im) (* x.re x.im))))))
double code(double x_46_re, double x_46_im) {
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_re) - (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_im);
}
double code(double x_46_re, double x_46_im) {
	double tmp;
	if (x_46_re <= -2.1348970050771735e-305) {
		tmp = (pow(x_46_re, 3.0) - (x_46_re * pow(x_46_im, 2.0))) - (x_46_im * (2.0 * (x_46_re * x_46_im)));
	} else {
		tmp = (pow(x_46_re, 3.0) - pow((x_46_im * sqrt(x_46_re)), 2.0)) - (x_46_im * ((x_46_re * x_46_im) + (x_46_re * x_46_im)));
	}
	return tmp;
}

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
Herbie3.8
\[\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. Split input into 2 regimes
  2. if x.re < -2.13489700507717355e-305

    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 in x.re around 0 7.1

      \[\leadsto \color{blue}{\left({x.re}^{3} - x.re \cdot {x.im}^{2}\right)} - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
    3. Taylor expanded in x.re around 0 7.1

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

    if -2.13489700507717355e-305 < x.re

    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 in x.re around 0 7.2

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

      \[\leadsto \left({x.re}^{3} - \color{blue}{{\left(x.im \cdot \sqrt{x.re}\right)}^{2}}\right) - \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.im \]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \leq -2.1348970050771735 \cdot 10^{-305}:\\ \;\;\;\;\left({x.re}^{3} - x.re \cdot {x.im}^{2}\right) - x.im \cdot \left(2 \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left({x.re}^{3} - {\left(x.im \cdot \sqrt{x.re}\right)}^{2}\right) - x.im \cdot \left(x.re \cdot x.im + x.re \cdot x.im\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (x.re x.im)
  :name "math.cube on complex, real part"
  :precision binary64

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

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