# ReplaceAll giving different answer than actual replacement

I have an expression, and I wanted to evaluate it for a certain value of a variable. However, /. gives a calculation error, whereas manually replacing the variable with the value succeeds. Why?

$$\sum _{n=0}^{\infty } \frac{1}{(k+n)! (n-k)!}\text{/.}\, \{k\to 4\}$$ $$\sum _{n=0}^{\infty } \frac{1}{(n+4)! (n-4)!}$$

The first errors Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. and returns Indeterminate, whereas the second yields BesselI[8, 2]. My understanding of ReplaceAll was that the two should be functionally identical. What's wrong?

(Mathematica 11.0.1.0, Windows 10, 64 bit)

• Hi Erhannis, welcome to the Mathematica Stack Exchange. Could you post the exact code that's exhibiting the issue in copy-pasteable format? It helps a lot if we can just plug your code straight into Mathematica. Thanks! Feb 2, 2019 at 8:09

The issue appears to be an order of precedence thing.

When you evaluate your first function $$\sum _{n=0}^{\infty } \frac{1}{(k+n)! (n-k)!}$$, it simplifies to $$\frac{\, _1F_2(1;1-k,k+1;1)}{(-k)! k!}$$.

Since it will do this simplification before replacing $$k$$, and since $${(-k)! k!}$$ evaluates to ComplexInfinity (as does the top half of the function), you get the error message.

The trick is to do the replacement earlier:

$$\sum _{n=0}^{\infty } \left(\frac{1}{(k+n)! (n-k)!}\text{/.}\, k\to 4\right)$$

Which evaluates to BesselI[8, 2] as expected.

• This kind of problem is exactly why HypergeometricPFQRegularized was introduced. Your general sum formula can be simplified to be non-singular: Sum[1/((n+k)!(n-k)!), {n,0,Infinity}] // FullSimplify gives HypergeometricPFQRegularized[{1},{1-k,1+k},1], which at k=4 gives Hypergeometric0F1Regularized[9,1], which in turn fullsimplifies to BesselI[8,2]. Feb 2, 2019 at 8:56