Skip to main content
added 26 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

Perhaps

funs = {f, e, g, h}
apply = {sf, se, sgen, sgen}
k[a_, b_, c_]b_] := c[a](Head@b /. Thread[funs -> apply])[a] b

Collect[ z[x]Collect[z@x expr , Blank /@ funs]@funs] /. (Times[a___, l : #Blank@#, r___] :> 
         k[a r, l, Head@l /. Thread[funs -> apply]]l] & /@ (Blank /@ funs)@funs)
 
(*

e[y] se[(x + y) z[x]] +
e[x] se[(-2 x + x^2 + y) z[x]] + 
f[x] sf[(x^2 + y^2) z[x]] +
g[x] sgen[x^2 z[x]] + 
h[x] sgen[y^2 z[x]]
*)

Perhaps

funs = {f, e, g, h}
apply = {sf, se, sgen, sgen}
k[a_, b_, c_] := c[a] b

Collect[ z[x] expr , Blank /@ funs] /. (Times[a___, l : #, r___] :> 
         k[a r, l, Head@l /. Thread[funs -> apply]] & /@ (Blank /@ funs))
 
(*

e[y] se[(x + y) z[x]] +
e[x] se[(-2 x + x^2 + y) z[x]] + 
f[x] sf[(x^2 + y^2) z[x]] +
g[x] sgen[x^2 z[x]] + 
h[x] sgen[y^2 z[x]]
*)

Perhaps

funs = {f, e, g, h}
apply = {sf, se, sgen, sgen}
k[a_, b_] := (Head@b /. Thread[funs -> apply])[a] b

Collect[z@x expr, Blank/@funs] /. (Times[a___, l: Blank@#, r___] :> k[a r, l] &/@funs)
(*

e[y] se[(x + y) z[x]] +
e[x] se[(-2 x + x^2 + y) z[x]] + 
f[x] sf[(x^2 + y^2) z[x]] +
g[x] sgen[x^2 z[x]] + 
h[x] sgen[y^2 z[x]]
*)
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

Perhaps

funs = {f, e, g, h}
apply = {sf, se, sgen, sgen}
k[a_, b_, c_] := c[a] b

Collect[ z[x] expr , Blank /@ funs] /. (Times[a___, l : #, r___] :> 
         k[a r, l, Head@l /. Thread[funs -> apply]] & /@ (Blank /@ funs))

(*

e[y] se[(x + y) z[x]] +
e[x] se[(-2 x + x^2 + y) z[x]] + 
f[x] sf[(x^2 + y^2) z[x]] +
g[x] sgen[x^2 z[x]] + 
h[x] sgen[y^2 z[x]]
*)