# How to represent "For all elements other than i & j in a table"

I have a function F, function of four other f functions, as shown below (1, 2, 3, 4 are indices here)

F = f[1]*f[2]*f[3]*f[4]


I want to create a table using this function such that for each (i, j)th element f[i], f[j] and other f elements are replaced by functions X, Y and Z respectively. Replacing f[i] and f[j] is easy as follows, but I am not able to figure out how to represent "indices other than i and j" in this function.

G = Table[F/.{f[i] -> X, f[j] -> Y}, {i, 1, 4}, {j, 1, 4}]


Will appreciate any help. thanks

• Are you meaning some conditions about $i$ and $j$ ? Nov 14, 2017 at 20:53
• f[Except[i|j]] ? Nov 14, 2017 at 20:54
• For example if I take the second element of table i = 1, j = 2. It should have f[1] -> X, f[2] -> Y and f[3] -> Z and f[4] -> Z. So, {1,2}th element of the table should be XYZ*Z and so on. In the example above, I am giving the simplified form of my problem. Thanks Nov 14, 2017 at 20:58
• All the solutions suggested here working fine for problem I mentioned here, but not for my original problem. Sorry, It seems I oversimplified my problem. so let me rephrase - To be precise, I want to replace f[m, k] with f[m-1, k], where m is an independent integer and k is 1-4 other than i & j. The suggestion like f[m, Except[ i | j ] ] -> f[m-1, Except[ i | j ]] works fine on up to some extent as m is getting replaced by m-1, but then k instead of remaining k becomes "Except[ i | j ]". I am posting the problem again as well. Nov 15, 2017 at 7:16

It should be noted that it feels a bit counter-intuitive to use Table and ReplaceAll like that but since it is used in the question, this answer will go along similar lines as there is not much context to favor a different approach.

G/.f[_]->Z


The rule f[_]->Z will match all instances of f[_] in G where _ is anything that is not already replaced by ReplaceAll in Table (as described in the question) .

The output is

{
{X Z^3, X Y Z^2, X Y Z^2, X Y Z^2},
{X Y Z^2, X Z^3, X Y Z^2, X Y Z^2},
{X Y Z^2, X Y Z^2, X Z^3, X Y Z^2},
{X Y Z^2, X Y Z^2, X Y Z^2, X Z^3}
}

• Or one character shorter: G/._f->Z :) (+1) Nov 14, 2017 at 23:07