Skip to main content
Bounty Awarded with 50 reputation awarded by Mario Krenn
Source Link
TimRias
  • 3.3k
  • 15
  • 17

Here is another faster solution:

prune[X_][expr_] := Select[expr, MemberQ[#, X, \[Infinity]] &]
h[expr_] := Plus@@Cases[Expand@prune[c]@prune[d]@prune[e]@prune[f]@expr, c d e f X_] 
r1 = g@func; //Timing
r2 = h@func; //Timing
r1 == r2

{12.0938, Null}

{1.39063, Null}

True

We see a speed up of almost a factor 10.