# How to collect polynomials with multi-variables whose coefficients are not integers

I have a Mathematica code that generates a complicated output that runs into more than 200+ lines of output. Here is my code:

ClearAll["Global*"]
h = q/(2 g) + I (1/(2 g))*f;

rules = {a :> -h/q, b :> -1/g, z :> (q*t)/g};
rulse = {a :> -Conjugate[h]/q, b :> -1/g, z :> (-q*t)/g};

L = Normal[(Gamma[1 - b + a]/Gamma [1 - b]) E^(z - h*t) Gamma[
1 - a] ((-(Gamma[b - 1]/Pi)) ((-z^(1 - b)) Sin[
Pi a] + (-z)^(1 - b) Sin[Pi (b - a)]) Series[
Hypergeometric1F1[1 - a, 2 - b, -z], {z, 0, 3}] + (1/
Gamma[1 + a - b]) Series[
HypergeometricU[-a + b, b, -z], {z, 0, 3}])] /. rules;

K = Normal[(Gamma[1 - b + a]/
Gamma [1 - b]) E^(z + Conjugate[h]*t) Gamma[
1 - a] ((-(Gamma[b - 1]/Pi)) ((-z^(1 - b)) Sin[
Pi a] + (-z)^(1 - b) Sin[Pi (b - a)]) Series[
Hypergeometric1F1[1 - a, 2 - b, -z], {z, 0, 3}] + (1/
Gamma[1 + a - b]) Series[
HypergeometricU[-a + b, b, -z], {z, 0, 3}])] /. rulse;

Integrate[K, {t, -Infinity, 0},
Assumptions -> {g < -1/2, q > 0, f \[Element] Reals}] +
Integrate[L, {t, 0, Infinity},
Assumptions -> {g < -1/2, q > 0, f \[Element] Reals}]


Running the above code and generating an output takes around 10 minutes on my machine. Here is a screenshot of the output:

Even trying Fullsimplify or Multinomiallist takes more than 3+ hours, without any results. I just want to collect the $f^xg^yq^z$ terms together, without any expansion of $(If+q)^k$ terms or the Gamma function terms.

I am a beginner in Mathematica and I am unable to write any custom functions for the same.

Edit: Sorry for not stating my problem clearly. As you can see from the output, it looks like a complex number. However, I have checked theoretically that all the imaginary parts cancel out and only real parts remain. But, my question is how to get Mathematica do the same. Thank you for the help

One can change $p$, $q$ and $g$ in the sub-expressions not to be expanded on formal variables:
expr1 = expr /. {I f + q -> \[FormalF] + I \[FormalQ]} /.
Gamma[$_] :> Gamma[$ /. {f -> \[FormalF], q -> \[FormalQ], g -> \[FormalG]}]

and then apply CoefficientList (or Series` if powers of $g$ etc are not integer) to find coefficients.
• Even if the imaginary part is zero it doesn't mean that the expression containing gamma functions can be somehow simplified. Say $\Gamma(1+i)+\Gamma(1-i)$ is real, but Mma cannot simplify it and chances it can be somehow be rewritten in without $i$ seem fin to me. May 1, 2018 at 11:36