# Find possible sets of numbers for non-zero coefficients (optimization)

GROUPS:
 Hi,I need to optimize sets search of non-zero coefficients for real functions of the form (with possibly more harmonics):f = x3^(3/2) (A1 Cos[8 x1] + B1 Cos[9 x1] + C1 Cos[10 x1]) (Cos[x2] + Cos[3 x2]);f is to be expanded into double Fourier series with respect to x1 and x2, i.e. f = Sum f(nm) exp(i(n x1 + m x2)).And the values of (nm) for which f(nm)'s are non-zero should be found automaticaly. So far I've found 2 ways of extracting (nm). But I'm not sure that they are bug-free and they indeed not optimized.Method 1: f = x3^(3/2) (A1 Cos[8 x1] + B1 Cos[9 x1] + C1 Cos[10 x1]) (Cos[x2] + Cos[3 x2]);  set1 = FourierCoefficient[f, x1, n][[1]]; set2 = FourierCoefficient[f, x2, m][[1]];  l1 = Length[set1]; l2 = Length[set2];  ns = Table[set1[[i]][[2]], {i, 1, l1}];ms = Table[set2[[i]][[2]], {i, 1, l2}];ns = ToExpression[StringReplace[StringReplace[ToString[ns], "||" -> ","],"n == " -> " "]]ms = ToExpression[StringReplace[StringReplace[ToString[ms], "||" -> ","],"m == " -> " "]]Method 2: f = x3^(3/2) (A1 Cos[8 x1] + B1 Cos[9 x1] + C1 Cos[10 x1]) (Cos[x2] + Cos[3 x2]); f = f // TrigToExp // Expand;  array = Table[0, {i, 1, Length[f]}]; Do[{array[[i]] = f[[i]];}, {i, 1, Length[f]}];  ToString[array /. i_ E^n_ -> n]; StringReplace[% , "x1" -> ","]; StringReplace[% , "I" -> "1"];StringReplace[% , "x2" -> "1"];full = ToExpression[%];ns = Take[full, {1, Length[full], 2}];ms = Take[full, {2, Length[full], 2}];ns = DeleteDuplicates[ns]ms = DeleteDuplicates[ms]Any suggestions how to optimize (mn) extraction? Or maybe is there a better way to do it?Thanks,I.M.
 [It pays to post code that actually works. There is a definition mismatch between f and f1.]f1 = x3^(3/2) (A1 Cos[8 x1] + B1 Cos[9 x1] + C1 Cos[10 x1]) (Cos[x2] +      Cos[3 x2]);Timing[ fcoeffs =   Table[FourierCoefficient[     Table[FourierCoefficient[f1, x1, n], {n, -12, 12}], x2,     m], {m, -12, 12}];]Out[101]= {59.460000, Null}