Define the F
function as follows
F[m_,i_,j_]:=Module[{rls},
rls = {
f[arg1_, arg2_] :> f[arg1 - 2, arg2] /; MemberQ[{i, j}, arg2],
f[arg1_, arg2_] :> f[arg1 - 1, arg2] /; Not[MemberQ[{i, j}, arg2]]
};
Fold[ReplaceAll[#1, #2] &, f[m, 1] f[m, 2] f[m, 3] f[m, 4], rls]
]
Evaluating F[m,1,3]
returns
f[-2 + m, 1] f[-2 + m, 3] f[-1 + m, 2] f[-1 + m, 4]
Effectively, what the solution does is to apply repeatedly the transformation rules for f[m,i]
; it first tackles the case where i,j
's in the f
's are equal to the inputs and then deals with all the remaining cases (ie those indexes not equal to either of the inputs).