| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 7040 |
\[x.re \cdot \left(x.re \cdot \left(x.im \cdot 3\right)\right) - {x.im}^{3}
\]
(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}
Results
| Original | 7.8 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
if x.re < -4.99999999999999962e125 or 1.85e128 < x.re Initial program 47.3
Applied egg-rr47.3
Taylor expanded in x.re around inf 47.3
Simplified0.4
[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.85e128Initial program 0.2
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 7040 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 1353 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 1344 |
| Alternative 4 | |
|---|---|
| Error | 0.3 |
| Cost | 969 |
| Alternative 5 | |
|---|---|
| Error | 5.7 |
| Cost | 841 |
| Alternative 6 | |
|---|---|
| Error | 6.1 |
| Cost | 777 |
| Alternative 7 | |
|---|---|
| Error | 6.1 |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 6.1 |
| Cost | 713 |
| Alternative 9 | |
|---|---|
| Error | 27.3 |
| Cost | 649 |
| Alternative 10 | |
|---|---|
| Error | 44.0 |
| Cost | 320 |
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)))