Question: How to count the number of nonlinear terms in a list?

Hello

I need to count and separate the nonlinear terms in a list.  Example:

w:=[[z, y, x, 1], [x*z, x*y, y, 1], [x*z, z, x*y]];

there are 4 nonlinear terms, x*z, x*y, x*z, and x*y.  

The terms can be any combination of the given variables, that is, x, y, and z.  

My solution to the problem of counting the nonlinear terms is 

aux1:=[seq([seq(nops(w[j,i]),i=1..nops(w[j]))],j=1..nops(w))];

aux2:=[seq(selectremove(x->x>1,aux1[i])[1],i=1..nops(aux1))]

res:=convert([seq(convert(nops(aux2[i]),`+`),i=1..nops(aux2))],`+`);

It works but I wonder whether there is a better solution that includes showing the nonlinear terms themselves.

Many thanks

Ed

Please Wait...