?

Average Error: 7.8 → 0.2
Time: 8.7s
Precision: binary64
Cost: 1353

?

\[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
\[\begin{array}{l} \mathbf{if}\;x.re \leq -5 \cdot 10^{+125} \lor \neg \left(x.re \leq 1.85 \cdot 10^{+128}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 2\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \end{array} \]
(FPCore (x.re x.im)
 :precision binary64
 (+
  (* (- (* x.re x.re) (* x.im x.im)) x.im)
  (* (+ (* x.re x.im) (* x.im x.re)) x.re)))
(FPCore (x.re x.im)
 :precision binary64
 (if (or (<= x.re -5e+125) (not (<= x.re 1.85e+128)))
   (* x.re (* x.re (* x.im 3.0)))
   (+
    (* x.re (* (* x.re x.im) 2.0))
    (* x.im (- (* x.re x.re) (* x.im 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_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_re <= -5e+125) || !(x_46_re <= 1.85e+128)) {
		tmp = x_46_re * (x_46_re * (x_46_im * 3.0));
	} else {
		tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	}
	return tmp;
}
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    code = (((x_46re * x_46re) - (x_46im * x_46im)) * x_46im) + (((x_46re * x_46im) + (x_46im * x_46re)) * x_46re)
end function
real(8) function code(x_46re, x_46im)
    real(8), intent (in) :: x_46re
    real(8), intent (in) :: x_46im
    real(8) :: tmp
    if ((x_46re <= (-5d+125)) .or. (.not. (x_46re <= 1.85d+128))) then
        tmp = x_46re * (x_46re * (x_46im * 3.0d0))
    else
        tmp = (x_46re * ((x_46re * x_46im) * 2.0d0)) + (x_46im * ((x_46re * x_46re) - (x_46im * x_46im)))
    end if
    code = tmp
end function
public static 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_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
}
public static double code(double x_46_re, double x_46_im) {
	double tmp;
	if ((x_46_re <= -5e+125) || !(x_46_re <= 1.85e+128)) {
		tmp = x_46_re * (x_46_re * (x_46_im * 3.0));
	} else {
		tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	}
	return tmp;
}
def code(x_46_re, x_46_im):
	return (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re)
def code(x_46_re, x_46_im):
	tmp = 0
	if (x_46_re <= -5e+125) or not (x_46_re <= 1.85e+128):
		tmp = x_46_re * (x_46_re * (x_46_im * 3.0))
	else:
		tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)))
	return tmp
function code(x_46_re, x_46_im)
	return Float64(Float64(Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im)) * x_46_im) + Float64(Float64(Float64(x_46_re * x_46_im) + Float64(x_46_im * x_46_re)) * x_46_re))
end
function code(x_46_re, x_46_im)
	tmp = 0.0
	if ((x_46_re <= -5e+125) || !(x_46_re <= 1.85e+128))
		tmp = Float64(x_46_re * Float64(x_46_re * Float64(x_46_im * 3.0)));
	else
		tmp = Float64(Float64(x_46_re * Float64(Float64(x_46_re * x_46_im) * 2.0)) + Float64(x_46_im * Float64(Float64(x_46_re * x_46_re) - Float64(x_46_im * x_46_im))));
	end
	return tmp
end
function tmp = code(x_46_re, x_46_im)
	tmp = (((x_46_re * x_46_re) - (x_46_im * x_46_im)) * x_46_im) + (((x_46_re * x_46_im) + (x_46_im * x_46_re)) * x_46_re);
end
function tmp_2 = code(x_46_re, x_46_im)
	tmp = 0.0;
	if ((x_46_re <= -5e+125) || ~((x_46_re <= 1.85e+128)))
		tmp = x_46_re * (x_46_re * (x_46_im * 3.0));
	else
		tmp = (x_46_re * ((x_46_re * x_46_im) * 2.0)) + (x_46_im * ((x_46_re * x_46_re) - (x_46_im * x_46_im)));
	end
	tmp_2 = tmp;
end
code[x$46$re_, x$46$im_] := N[(N[(N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision] + N[(N[(N[(x$46$re * x$46$im), $MachinePrecision] + N[(x$46$im * x$46$re), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision]), $MachinePrecision]
code[x$46$re_, x$46$im_] := If[Or[LessEqual[x$46$re, -5e+125], N[Not[LessEqual[x$46$re, 1.85e+128]], $MachinePrecision]], N[(x$46$re * N[(x$46$re * N[(x$46$im * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$re * N[(N[(x$46$re * x$46$im), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] + N[(x$46$im * N[(N[(x$46$re * x$46$re), $MachinePrecision] - N[(x$46$im * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\begin{array}{l}
\mathbf{if}\;x.re \leq -5 \cdot 10^{+125} \lor \neg \left(x.re \leq 1.85 \cdot 10^{+128}\right):\\
\;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.8
Target0.2
Herbie0.2
\[\left(x.re \cdot x.im\right) \cdot \left(2 \cdot x.re\right) + \left(x.im \cdot \left(x.re - x.im\right)\right) \cdot \left(x.re + x.im\right) \]

Derivation?

  1. Split input into 2 regimes
  2. if x.re < -4.99999999999999962e125 or 1.85e128 < x.re

    1. Initial program 47.3

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Applied egg-rr47.3

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

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

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

      [Start]47.3

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

      unpow2 [=>]47.3

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

      associate-*l* [=>]0.4

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

      distribute-rgt1-in [=>]0.4

      \[ x.re \cdot \left(x.re \cdot \color{blue}{\left(\left(2 + 1\right) \cdot x.im\right)}\right) \]

      metadata-eval [=>]0.4

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

      *-commutative [=>]0.4

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

    if -4.99999999999999962e125 < x.re < 1.85e128

    1. Initial program 0.2

      \[\left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re \]
    2. Applied egg-rr0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x.re \leq -5 \cdot 10^{+125} \lor \neg \left(x.re \leq 1.85 \cdot 10^{+128}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 2\right) + x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost7040
\[x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3} \]
Alternative 2
Error0.2
Cost1353
\[\begin{array}{l} \mathbf{if}\;x.re \leq -5 \cdot 10^{+101} \lor \neg \left(x.re \leq 1.8 \cdot 10^{+128}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right) + \left(x.re + x.im\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right)\\ \end{array} \]
Alternative 3
Error0.3
Cost1344
\[\frac{1}{\frac{\frac{1}{x.im}}{x.re + x.im}} \cdot \left(x.re - x.im\right) + x.re \cdot \left(\left(x.re \cdot x.im\right) \cdot 2\right) \]
Alternative 4
Error0.3
Cost969
\[\begin{array}{l} \mathbf{if}\;x.re \leq -5.8 \cdot 10^{+125} \lor \neg \left(x.re \leq 1.5 \cdot 10^{+74}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot \left(x.re \cdot 3\right) - x.im \cdot x.im\right)\\ \end{array} \]
Alternative 5
Error5.7
Cost841
\[\begin{array}{l} \mathbf{if}\;x.re \leq -5.5 \cdot 10^{-34} \lor \neg \left(x.re \leq 9.2 \cdot 10^{-7}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.re + x.im\right) \cdot \left(x.im \cdot \left(x.re - x.im\right)\right)\\ \end{array} \]
Alternative 6
Error6.1
Cost777
\[\begin{array}{l} \mathbf{if}\;x.re \leq -2.05 \cdot 10^{-35} \lor \neg \left(x.re \leq 9.2 \cdot 10^{-7}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x.re + x.im\right) \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 7
Error6.1
Cost713
\[\begin{array}{l} \mathbf{if}\;x.re \leq -2.05 \cdot 10^{-35} \lor \neg \left(x.re \leq 9.2 \cdot 10^{-7}\right):\\ \;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 8
Error6.1
Cost713
\[\begin{array}{l} \mathbf{if}\;x.re \leq -2.3 \cdot 10^{-35} \lor \neg \left(x.re \leq 9.2 \cdot 10^{-7}\right):\\ \;\;\;\;x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \end{array} \]
Alternative 9
Error27.3
Cost649
\[\begin{array}{l} \mathbf{if}\;x.im \leq -3.4 \cdot 10^{-109} \lor \neg \left(x.im \leq 1.5 \cdot 10^{-109}\right):\\ \;\;\;\;x.im \cdot \left(x.im \cdot \left(-x.im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x.im \cdot \left(x.re \cdot x.re\right)\\ \end{array} \]
Alternative 10
Error44.0
Cost320
\[x.im \cdot \left(x.re \cdot x.re\right) \]

Error

Reproduce?

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

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

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