# How to use pattern matching for integral identities?

I have an unknown pdf f[x], and I need to express integrals involving f[x] as expansions of the moments of f[x]. For example:

gau[x_, v_] = ((2*Pi*v)^(-1/2))*E^-((x^2)/(2*v));
ns = Series[gau[x - z, v], {v, Infinity, 4}] // Normal;
p = Integrate[f[z]*ns, {z, -Infinity, Infinity}]


How can I us pattern matching to express p in terms of m[1], m[2], m[3]..., where Integrate[f[x]*x^n,{x,-Infinity,Infinity}]->m[n]?

I need this to work even if the variable of integration is something other than x, and I need it to make the substitution ONLY when n is a non-negative integer.

Thanks!

• Your code defines p as an integral over z but you wish it to be expressed as a sum of integrals over x. This seems inconsistent. Mar 1, 2015 at 3:39

Total@MapIndexed[#1 m[First@#2 - 1] &, CoefficientList[ns, z]]

This extracts a list of the coefficients of the powers of z in ns, then multiplies each one of them by m[n] (I subtract one since index 1 corresponds to m[0]), finally totaling all the terms together.