# Part::pkspec1: The expression j cannot be used as a part specification

I want to do some stuff with symbolic arrays like this

a[[j]] + a[[j + 1]] == a[[j - 1]] + a[[j - 2]]


But upon declaring such an expression I get

Part::pkspec1: The expression j cannot be used as a part specification.


for all indices in the expression. It also does not work with the above expression when, for example, putting it into solve.

How can I do symbolic math with smybolic arrays?

EDIT:
Example

Solve[a[[j]] + a[[j + 1]] == a[[j - 1]] + a[[j - 2]], a[[j]]]

• I don't want to do recursive stuff – chr Mar 17 '19 at 20:39
• Use Indexed[]. – J. M.'s ennui Mar 17 '19 at 20:45
• Use Solve[a[j] + a[j + 1] == a[j - 1] + a[j - 2], a[j]], which solves for a[j]. – bill s Mar 17 '19 at 23:49

You probably really want to use a[j] and RSolve[] instead. The code

RSolve[a[j] + a[1 + j] == a[-2 + j] + a[-1 + j], a[j], j]


returns

{{a[j] -> (-1)^j*C[1] + (-1)^j*j*C[2] + C[3]}}


But you may still want to do it your way. The code

Solve[ a[j] + a[j + 1] == a[j - 1] + a[j - 2], a[j]]


returns

{{a[j] -> a[-2 + j] + a[-1 + j] - a[1 + j]}}


which may be what you want. A third alternative mentioned in comments is to use Indexed[a,j] instead of a[[j]]. The function Indexed[] was introduced in 2014 with version 10.0 of Mathematica.

• I had used this Notation before but I did not like the "wrong" semantics since single parantheses are for function calls but if does not work otherwise…. – chr Mar 20 '19 at 16:34
• Keep in mind that Mathematica does not have "functions" as in other computer languages.It has pattern matching, rewrite rules, evaluation rules, and symbolic expressions. You may think that f[x] = x^2 defines a "squaring function" but it doesn't. Even f[x_] := x^2 which is the closest equivalent is not a function. – Somos Mar 20 '19 at 17:19