# Efficient way to extract expression

I have large expressions linear in x. I would like to take all multiples of x off the expressions to have only the remaining terms free of x. For example, if I have U=(y+3z t)x-(5 y^2-t)x+2t^2, I want to extract and keep 2t^2. I have tried U - Coefficient[U,x]and Collect[U,x], but they take long time given that the expressions are large and I have to use Simplify to get the final expression. Is there some efficient way for doing this?

• Why not simply set x to zero: (y+3z t)x-(5 y^2-t)x+2t^2 /. x->0 Commented Nov 7, 2020 at 20:42
• @DanielHuber Thanks. But some of the terms contain some functions of x and other variables e.g. f[x,y], not sure the effect of setting x to 0 on this?
– Bran
Commented Nov 7, 2020 at 20:47

## 1 Answer

You can use Select and FreeQ as follows:

Select[FreeQ @ x][ExpandAll @ U]

2 t^2

• Thanks but it is not working. It just gives 0, although the answer is not.
– Bran
Commented Nov 7, 2020 at 20:29
• @Bran, trySelect[FreeQ @ x][ExpandAll @ U], If it does not work, please update the example in your post with an example U that shows the issue.
– kglr
Commented Nov 7, 2020 at 20:48
• That seems to do the trick. Thank you.
– Bran
Commented Nov 7, 2020 at 21:14