# Elementary syntax question

With the function

P[n_] :=  Module[{s,t} ,
s = Sum[z^k/k!, {k, 0,Infinity}];
t = Series[s^x, {z, 0, n+1}];
f[x_] = n!^2 Coefficient[t, z, n]
]


I get for

Map[P[3], {0, 1}]

{(6 x^3)[0],(6 x^3)[1]}


What I want is {0, 6}, the x evaluated at {0,1}. How to do it right?

In at least this case, you might consider using SeriesCoefficient[] instead:

P[n_Integer?NonNegative] := Block[{x, z},
Function[x, n!^2 SeriesCoefficient[Exp[z]^x, {z, 0, n}] // Evaluate]]

P[3] /@ {0, 1}
{0, 6}


Something like:

P[n_]:=Module[{s,t},
s=Sum[z^k/k!,{k,0,Infinity}];
t=Series[s^x,{z,0,n+1}];
Function@@{x,n!^2 Coefficient[t,z,n]}
]

P[3] /@ {0, 1}


{0, 6}

• It's probably worth mentioning that the f=... isn't needed. – jjc385 May 29 '17 at 18:15
• Thanks. But how to do it with Map[]? – Sophia Antipolis May 29 '17 at 18:17
• P[3] /@ {0, 1} and Map[P[3], {0, 1}] are syntactically equivalent. – Carl Woll May 29 '17 at 18:20

I would probably use Carl Woll's answer. However, the following approach might be more intuitive to a new user.

You could allow P[n] to take an argument x :

ClearAll[P]
P[n_][x_] := Module[{s, t},
s = Sum[z^k/k!, {k, 0, Infinity}];
t = Series[s^x, {z, 0, n + 1}];
n!^2 Coefficient[t, x, n]
]


Then:

Map[ P[3], {0,1} ]

{0, 6}


Note that the Module will re-evaluate for each different x call. Avoiding this is possible (as Carl Woll does), but the syntax gets a bit more messy.