Symbolic manipulation of expression with undefined function
example = v[1, 1, 1, 1] + 10*v[0, 0, 2, 0];
Using a replacement rule:
inc[ex_, p_] :=
ex /. v[a_, b_, c_, d_] ->
{a, b, c, d}[[p]] (v @@ ({a, b, c, d} + UnitVector[4, p]))
and for a more general case - i.e., for an arbitrary number of arguments of v
(thanks: kgrl):
inc[ex_, p_] := ex /. v[a__] :> {a}[[p]] (v @@ ( {a} + UnitVector[Length@{a}, p] ))
Then
inc[example, 3]
20 v[0, 0, 3, 0] + v[1, 1, 2, 1]
and
inc[example, 2]
v[1, 2, 1, 1]
Update: a simpler version for OP's specific case:
ClearAll[f2]
f2[exp_, p_] := exp /. v[x__] :> v[x][[p]] MapAt[1 + # &, v[x], {p}]
exp = 10 v[0, 0, 2, 0] + v[1, 1, 1, 1] + k v[1, 2, 3, 4];
f2[exp , 2]
v[1, 2, 1, 1] + 2 k v[1, 3, 3, 4]
f2[exp, 3]
20 v[0, 0, 3, 0] + v[1, 1, 2, 1] + 3 k v[1, 2, 4, 4]
Original post:
ClearAll[foo]
foo = # /. a : #2[__] :> a[[#4]] MapAt[#3, a, {#4}] &;
(* or foo[exp_, func_, tr_, p_]:= exp/. a: func[__] :> a[[p]] MapAt[tr, a, {p}] *)
Examples:
example = v[1, 1, 1, 1] + 10*v[0, 0, 2, 0] + 5 w[1, 2, 3];
foo[example, v, 1 + # &, 2]
v[1, 2, 1, 1] + 5 w[1, 2, 3]
foo[example, v, 1 + # &, 3]
20 v[0, 0, 3, 0] + v[1, 1, 2, 1] + 5 w[1, 2, 3]
foo[example, v, h, 3]
20 v[0, 0, h[2], 0] + v[1, 1, h[1], 1] + 5 w[1, 2, 3]
foo[example, w, h, 3]
10 v[0, 0, 2, 0] + v[1, 1, 1, 1] + 15 w[1, 2, h[3]]
foo[example, w | v, h, 3]
20 v[0, 0, h[2], 0] + v[1, 1, h[1], 1] + 15 w[1, 2, h[3]]