1
$\begingroup$

I will first do an illustrative example. Suppose I have the following function:

$ f(\vec{x},\vec{t})=\frac{x_1x_2}{(1-x_1 x_2^{-1} t_1)(1-x_2x_1^{-1} t_2)}$

I want to expand it with respect to $(t_1,t_2)$, and then select only those terms that are proportional to $x_1,x_2$. So, basically, in my example, I can do

Coefficient[Expand[Normal[Series[x[1] x[2]/((1 - h t[1] x[1] x[2]^-1) (1 - h t[2] x[2] x[1]^-1)), {h, 0, 10}]] /. h -> 1], x[1] x[2]]

And the result will be

1 + t[1] t[2] + t[1]^2 t[2]^2 + t[1]^3 t[2]^3 + t[1]^4 t[2]^4 + t[1]^5 t[2]^5

Now, the problem comes when there are very complicated functions, depending on an arbitrary number of variables $\vec{t}$, so the series is very slow at higher powers because of the large coefficients that may be present. There is also a problem of Expand that will saturate the RAM eventually, and if I don't do the Expand, the Coefficient is not selected properly.

Is there a way to make the Series Expansion and at the same time select the coefficients satisfying a given criterion for the coefficients at the same time?

Here a more complicated example:

$\frac{x_{1} x_{2} x_{3} x_{4} x_{5} x_{6} x_{7} x_{8} x_{9} x_{10} x_{11} x_{12} x_{13}}{\left(1-\frac{t_{1}}{x_{1} x_{2}}\right) \left(1-\frac{t_{2}}{x_{1} x_{2}}\right) \left(1-\frac{t_{9} x_{1} x_{2}}{x_{4}}\right) \left(1-\frac{t_{3}}{x_{3} x_{4}}\right) \left(1-\frac{t_{4}}{x_{3} x_{4}}\right) \left(1-\frac{t_{11} x_{3} x_{4}}{x_{2}}\right) \left(1-\frac{t_{5}}{x_{5}}\right) \left(1-\frac{t_{6}}{x_{5}}\right) \left(1-\frac{t_{12} x_{2} x_{7}}{x_{9}}\right) \left(1-\frac{t_{7} x_{5} x_{9}}{x_{8}}\right) \left(1-\frac{t_{10} x_{4} x_{6}}{x_{10}}\right) \left(1-\frac{t_{8} x_{5} x_{10}}{x_{11}}\right) \left(1-\frac{t_{13} x_{4} x_{8}}{x_{12}}\right) \left(1-\frac{t_{14} x_{3} x_{12}}{x_{6}}\right) \left(1-\frac{t_{15} x_{2} x_{11}}{x_{13}}\right) \left(1-\frac{t_{16} x_{1} x_{13}}{x_{7}}\right)}$

and I would like to select only those terms that are multiplied by $x_{1} x_{2} x_{3} x_{4} x_{5} x_{6} x_{7} x_{8} x_{9} x_{10} x_{11} x_{12} x_{13}$

$\endgroup$
9
  • $\begingroup$ Can you, please, provide a more complicated example that you’d want to deal with? $\endgroup$ Commented Mar 22, 2021 at 19:28
  • $\begingroup$ I added a very complicated example that I cannot do on my laptop but I'm doing very slowly computing it on a cluster. $\endgroup$ Commented Mar 22, 2021 at 21:27
  • $\begingroup$ But that's simple, if you set numerator to 1, you need to pick up terms in the series expansion that are free from $x$. $\endgroup$
    – yarchik
    Commented Mar 22, 2021 at 21:31
  • $\begingroup$ Yes, exactly, I understand, but they must be free from all the x's and this is slow and RAM consuming. I was asking if there was a way to select the coefficients that are free from x while expanding, so that I don't need to drop the ones that contains x's only afterwards. $\endgroup$ Commented Mar 22, 2021 at 21:50
  • $\begingroup$ As you can see, if I replace the example I gave without the numerator and asking for Coefficient 0 for all the x's, first of all I need to loop over all the x's, so I add a loop, and then it's very RAM consuming the first time I do it. I hope I'm explaining myself. $\endgroup$ Commented Mar 22, 2021 at 21:52

1 Answer 1

1
$\begingroup$

My idea is as follows.

Start from a given function

f = x[1] x[2]/((1 - h t[1] x[1] x[2]^-1) (1 - h t[2] x[2] x[1]^-1))

and discard the prefactor. Thus we a looking for the terms in the expansion that do not contain x[i]

g = 1/((1 - (h t[1] x[1])/x[2]) (1 - (h t[2] x[2])/x[1])) /. {x[i_] ->y^(1 + 10 i)}
Coefficient[Normal[Series[g, {h, 0, 10}]] /. h -> 1, y, 0]
(* 1 + t[1] t[2] + t[1]^2 t[2]^2 + t[1]^3 t[2]^3 + t[1]^4 t[2]^4 + t[1]^5 t[2]^5*)

The replacement above allows to reduce many variables x[i] to a single one y. Hopefully it will speed up the things.

$\endgroup$
2
  • $\begingroup$ I like this solution, I have just a doubt: are we sure that in very complicated examples, the choice of an overall variable y with that power does not produce accidental cancellations? I haven't looked in details why you chose y^(1+10i), so maybe in this way there are possible cancellations, but is there a way to be sure? $\endgroup$ Commented Mar 23, 2021 at 11:51
  • $\begingroup$ @AlessandroMininno yes, you right about the cancellations. I haven't tried to estimate what would be the correct step, I have chosen 10. In the case of doubts we may want to increase that. $\endgroup$
    – yarchik
    Commented Mar 23, 2021 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.