| Alternative 1 | |
|---|---|
| Error | 99.7% |
| Cost | 7040.00 |
(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 (<= x.re -4e+109)
(* 3.0 (* x.re (* x.re x.im)))
(if (<= x.re 9e+84)
(- (* 3.0 (* x.im (* x.re x.re))) (pow x.im 3.0))
(* x.re (* x.im (* x.re 3.0))))))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 <= -4e+109) {
tmp = 3.0 * (x_46_re * (x_46_re * x_46_im));
} else if (x_46_re <= 9e+84) {
tmp = (3.0 * (x_46_im * (x_46_re * x_46_re))) - pow(x_46_im, 3.0);
} else {
tmp = x_46_re * (x_46_im * (x_46_re * 3.0));
}
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 <= (-4d+109)) then
tmp = 3.0d0 * (x_46re * (x_46re * x_46im))
else if (x_46re <= 9d+84) then
tmp = (3.0d0 * (x_46im * (x_46re * x_46re))) - (x_46im ** 3.0d0)
else
tmp = x_46re * (x_46im * (x_46re * 3.0d0))
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 <= -4e+109) {
tmp = 3.0 * (x_46_re * (x_46_re * x_46_im));
} else if (x_46_re <= 9e+84) {
tmp = (3.0 * (x_46_im * (x_46_re * x_46_re))) - Math.pow(x_46_im, 3.0);
} else {
tmp = x_46_re * (x_46_im * (x_46_re * 3.0));
}
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 <= -4e+109: tmp = 3.0 * (x_46_re * (x_46_re * x_46_im)) elif x_46_re <= 9e+84: tmp = (3.0 * (x_46_im * (x_46_re * x_46_re))) - math.pow(x_46_im, 3.0) else: tmp = x_46_re * (x_46_im * (x_46_re * 3.0)) 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 <= -4e+109) tmp = Float64(3.0 * Float64(x_46_re * Float64(x_46_re * x_46_im))); elseif (x_46_re <= 9e+84) tmp = Float64(Float64(3.0 * Float64(x_46_im * Float64(x_46_re * x_46_re))) - (x_46_im ^ 3.0)); else tmp = Float64(x_46_re * Float64(x_46_im * Float64(x_46_re * 3.0))); 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 <= -4e+109) tmp = 3.0 * (x_46_re * (x_46_re * x_46_im)); elseif (x_46_re <= 9e+84) tmp = (3.0 * (x_46_im * (x_46_re * x_46_re))) - (x_46_im ^ 3.0); else tmp = x_46_re * (x_46_im * (x_46_re * 3.0)); 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[LessEqual[x$46$re, -4e+109], N[(3.0 * N[(x$46$re * N[(x$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x$46$re, 9e+84], N[(N[(3.0 * N[(x$46$im * N[(x$46$re * x$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[Power[x$46$im, 3.0], $MachinePrecision]), $MachinePrecision], N[(x$46$re * N[(x$46$im * N[(x$46$re * 3.0), $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 -4 \cdot 10^{+109}:\\
\;\;\;\;3 \cdot \left(x.re \cdot \left(x.re \cdot x.im\right)\right)\\
\mathbf{elif}\;x.re \leq 9 \cdot 10^{+84}:\\
\;\;\;\;3 \cdot \left(x.im \cdot \left(x.re \cdot x.re\right)\right) - {x.im}^{3}\\
\mathbf{else}:\\
\;\;\;\;x.re \cdot \left(x.im \cdot \left(x.re \cdot 3\right)\right)\\
\end{array}
Results
| Original | 88.1% |
|---|---|
| Target | 99.6% |
| Herbie | 99.7% |
if x.re < -3.99999999999999993e109Initial program 36.9
Simplified36.6
[Start]36.9 | \[ \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
\] |
|---|---|
*-commutative [=>]36.9 | \[ \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [<=]36.9 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
distribute-rgt-out [=>]36.9 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re
\] |
associate-*l* [=>]36.6 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) \cdot x.re\right)}
\] |
distribute-lft-out [=>]36.6 | \[ \color{blue}{x.im \cdot \left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re + x.re\right) \cdot x.re\right)}
\] |
+-commutative [<=]36.6 | \[ x.im \cdot \color{blue}{\left(\left(x.re + x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)}
\] |
associate-+r- [=>]36.6 | \[ x.im \cdot \color{blue}{\left(\left(\left(x.re + x.re\right) \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)}
\] |
count-2 [=>]36.6 | \[ x.im \cdot \left(\left(\color{blue}{\left(2 \cdot x.re\right)} \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
associate-*l* [=>]36.6 | \[ x.im \cdot \left(\left(\color{blue}{2 \cdot \left(x.re \cdot x.re\right)} + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
distribute-lft1-in [=>]36.6 | \[ x.im \cdot \left(\color{blue}{\left(2 + 1\right) \cdot \left(x.re \cdot x.re\right)} - x.im \cdot x.im\right)
\] |
fma-neg [=>]36.6 | \[ x.im \cdot \color{blue}{\mathsf{fma}\left(2 + 1, x.re \cdot x.re, -x.im \cdot x.im\right)}
\] |
metadata-eval [=>]36.6 | \[ x.im \cdot \mathsf{fma}\left(\color{blue}{3}, x.re \cdot x.re, -x.im \cdot x.im\right)
\] |
Taylor expanded in x.im around 0 36.9
Simplified99.4
[Start]36.9 | \[ 3 \cdot \left({x.re}^{2} \cdot x.im\right)
\] |
|---|---|
unpow2 [=>]36.9 | \[ 3 \cdot \left(\color{blue}{\left(x.re \cdot x.re\right)} \cdot x.im\right)
\] |
associate-*l* [=>]99.4 | \[ 3 \cdot \color{blue}{\left(x.re \cdot \left(x.re \cdot x.im\right)\right)}
\] |
if -3.99999999999999993e109 < x.re < 8.9999999999999994e84Initial program 99.7
Simplified99.8
[Start]99.7 | \[ \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
\] |
|---|---|
+-commutative [=>]99.7 | \[ \color{blue}{\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right) \cdot x.im}
\] |
*-commutative [=>]99.7 | \[ \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)}
\] |
distribute-rgt-out-- [<=]99.7 | \[ \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot x.im - \left(x.im \cdot x.im\right) \cdot x.im\right)}
\] |
associate-+r- [=>]99.7 | \[ \color{blue}{\left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im\right) - \left(x.im \cdot x.im\right) \cdot x.im}
\] |
*-commutative [<=]99.7 | \[ \left(\left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im\right) - \color{blue}{x.im \cdot \left(x.im \cdot x.im\right)}
\] |
*-commutative [<=]99.7 | \[ \left(\left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
count-2 [=>]99.7 | \[ \left(\color{blue}{\left(2 \cdot \left(x.re \cdot x.im\right)\right)} \cdot x.re + \left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
associate-*l* [=>]99.7 | \[ \left(\color{blue}{2 \cdot \left(\left(x.re \cdot x.im\right) \cdot x.re\right)} + \left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
*-commutative [<=]99.7 | \[ \left(2 \cdot \color{blue}{\left(x.re \cdot \left(x.re \cdot x.im\right)\right)} + \left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
associate-*r* [=>]99.7 | \[ \left(2 \cdot \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot x.im\right)} + \left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
distribute-lft1-in [=>]99.7 | \[ \color{blue}{\left(2 + 1\right) \cdot \left(\left(x.re \cdot x.re\right) \cdot x.im\right)} - x.im \cdot \left(x.im \cdot x.im\right)
\] |
metadata-eval [=>]99.7 | \[ \color{blue}{3} \cdot \left(\left(x.re \cdot x.re\right) \cdot x.im\right) - x.im \cdot \left(x.im \cdot x.im\right)
\] |
cube-unmult [=>]99.8 | \[ 3 \cdot \left(\left(x.re \cdot x.re\right) \cdot x.im\right) - \color{blue}{{x.im}^{3}}
\] |
if 8.9999999999999994e84 < x.re Initial program 51.3
Simplified51.0
[Start]51.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
\] |
|---|---|
*-commutative [=>]51.3 | \[ \color{blue}{x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right)} + \left(x.re \cdot x.im + x.im \cdot x.re\right) \cdot x.re
\] |
*-commutative [<=]51.3 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re \cdot x.im + \color{blue}{x.re \cdot x.im}\right) \cdot x.re
\] |
distribute-rgt-out [=>]51.3 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{\left(x.im \cdot \left(x.re + x.re\right)\right)} \cdot x.re
\] |
associate-*l* [=>]51.0 | \[ x.im \cdot \left(x.re \cdot x.re - x.im \cdot x.im\right) + \color{blue}{x.im \cdot \left(\left(x.re + x.re\right) \cdot x.re\right)}
\] |
distribute-lft-out [=>]50.9 | \[ \color{blue}{x.im \cdot \left(\left(x.re \cdot x.re - x.im \cdot x.im\right) + \left(x.re + x.re\right) \cdot x.re\right)}
\] |
+-commutative [<=]50.9 | \[ x.im \cdot \color{blue}{\left(\left(x.re + x.re\right) \cdot x.re + \left(x.re \cdot x.re - x.im \cdot x.im\right)\right)}
\] |
associate-+r- [=>]50.9 | \[ x.im \cdot \color{blue}{\left(\left(\left(x.re + x.re\right) \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)}
\] |
count-2 [=>]50.9 | \[ x.im \cdot \left(\left(\color{blue}{\left(2 \cdot x.re\right)} \cdot x.re + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
associate-*l* [=>]50.9 | \[ x.im \cdot \left(\left(\color{blue}{2 \cdot \left(x.re \cdot x.re\right)} + x.re \cdot x.re\right) - x.im \cdot x.im\right)
\] |
distribute-lft1-in [=>]50.9 | \[ x.im \cdot \left(\color{blue}{\left(2 + 1\right) \cdot \left(x.re \cdot x.re\right)} - x.im \cdot x.im\right)
\] |
fma-neg [=>]51.0 | \[ x.im \cdot \color{blue}{\mathsf{fma}\left(2 + 1, x.re \cdot x.re, -x.im \cdot x.im\right)}
\] |
metadata-eval [=>]51.0 | \[ x.im \cdot \mathsf{fma}\left(\color{blue}{3}, x.re \cdot x.re, -x.im \cdot x.im\right)
\] |
Taylor expanded in x.im around 0 50.8
Simplified50.8
[Start]50.8 | \[ 3 \cdot \left({x.re}^{2} \cdot x.im\right)
\] |
|---|---|
*-commutative [=>]50.8 | \[ 3 \cdot \color{blue}{\left(x.im \cdot {x.re}^{2}\right)}
\] |
unpow2 [=>]50.8 | \[ 3 \cdot \left(x.im \cdot \color{blue}{\left(x.re \cdot x.re\right)}\right)
\] |
Taylor expanded in x.im around 0 50.8
Simplified99.0
[Start]50.8 | \[ 3 \cdot \left({x.re}^{2} \cdot x.im\right)
\] |
|---|---|
associate-*r* [=>]50.5 | \[ \color{blue}{\left(3 \cdot {x.re}^{2}\right) \cdot x.im}
\] |
unpow2 [=>]50.5 | \[ \left(3 \cdot \color{blue}{\left(x.re \cdot x.re\right)}\right) \cdot x.im
\] |
*-commutative [<=]50.5 | \[ \color{blue}{\left(\left(x.re \cdot x.re\right) \cdot 3\right)} \cdot x.im
\] |
associate-*l* [=>]50.5 | \[ \color{blue}{\left(x.re \cdot \left(x.re \cdot 3\right)\right)} \cdot x.im
\] |
associate-*l* [=>]99.0 | \[ \color{blue}{x.re \cdot \left(\left(x.re \cdot 3\right) \cdot x.im\right)}
\] |
Final simplification99.7
| Alternative 1 | |
|---|---|
| Error | 99.7% |
| Cost | 7040.00 |
| Alternative 2 | |
|---|---|
| Error | 99.7% |
| Cost | 7040.00 |
| Alternative 3 | |
|---|---|
| Error | 99.6% |
| Cost | 1352.00 |
| Alternative 4 | |
|---|---|
| Error | 99.6% |
| Cost | 968.00 |
| Alternative 5 | |
|---|---|
| Error | 91.7% |
| Cost | 840.00 |
| Alternative 6 | |
|---|---|
| Error | 91.7% |
| Cost | 840.00 |
| Alternative 7 | |
|---|---|
| Error | 80.0% |
| Cost | 713.00 |
| Alternative 8 | |
|---|---|
| Error | 91.5% |
| Cost | 713.00 |
| Alternative 9 | |
|---|---|
| Error | 91.5% |
| Cost | 712.00 |
| Alternative 10 | |
|---|---|
| Error | 91.5% |
| Cost | 712.00 |
| Alternative 11 | |
|---|---|
| Error | 59.6% |
| Cost | 649.00 |
| Alternative 12 | |
|---|---|
| Error | 31.0% |
| Cost | 320.00 |
| Alternative 13 | |
|---|---|
| Error | 33.0% |
| Cost | 320.00 |
| Alternative 14 | |
|---|---|
| Error | 26.7% |
| Cost | 192.00 |
herbie shell --seed 2023093
(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)))