# How to define linear mappings on a vector space spanned by abstract symbols?

Say I have an infinite dimensional vector space $$V$$ with basis consists of abstract symbols $$\{ a_j \}^\infty_{j=0}$$, and consider a linear function $$f$$ on $$V$$ defined by its action on the basis elements, say $$f[a_j]=j *a_{j}+j^2 * a_{j+1}, \forall j\geq 0$$. I want to implement this function $$f$$ in mathematica that computes $$f$$ for any finite linear combination of $$\{a_j\}^\infty_{j=0}$$ (i.e. any vector in $$V$$). Sure I can input $$f[a_j]$$ into the definition of $$f$$, but how could I let mathematica know that $$f$$ is a linear function?

Linearity is defined as f[x_+y_]= f[x]+f[y] and f[lam x_] = lam f[x], where lam is a scalar. Further, do not use subscripted variables, use indexed ones instead. Therefore:

Clear["Global*"];
f[a[j_]] := j  a[j] + j^2 a[j + 1];
f[x_ + y_] := f[x] + f[y];
f[lam_?NumericQ  x_] := lam f[x]


We can now calculate e.g. the image of some vector a + a + 2 a:

f[a + a + 2 a1]
%% // Simplify

a + a + 2 (2 a + 4 a)

a + 5 a + 8 a
`