0

When I run this code:

S={a,b};
G=Subsets[S];
R=Table[SymmetricDifference[G[[i]],G[[j]]],{i,1,Length@G},{j,1,Length@G}];
TableForm[R/.({#1->1,#2->2,#3->3,#4->4}&@@G)]

It works as desired, ie: It outputs:

>[![enter image description here][1]][1]

But when I do this with T being a list with the Slot[i] -> i:

S={a,b};
G=Subsets[S];
R=Table[SymmetricDifference[G[[i]],G[[j]]],{i,1,Length@G},{j,1,Length@G}];
T=Table[Slot[i]->i,{i,Length@G}];
TableForm[R/.(T&@@G)]

I get:

enter image description here

I don't understand why this change of behavior happens. Can you help me?

Red Banana
  • 5,329
  • 2
  • 29
  • 47
  • 1
    Related: https://mathematica.meta.stackexchange.com/q/2414/1871 BTW, you've posted a wrong screenshot for the first output. – xzczd Nov 10 '23 at 15:01
  • 3
    Function is HoldAll. Use TableForm[R /. (Evaluate[T] & @@ G)]. – Domen Nov 10 '23 at 15:02
  • 3
    Simpler example showing the issue: expr = #; {expr &@aaaaaa, Evaluate[expr] &@aaaaa} – xzczd Nov 10 '23 at 15:03
  • 1
    I know you didn't ask, but you might find this to be a bit cleaner, generalizable to different-sized lists, and ultimately easier to understand: TableForm[Map[First@FirstPosition[G, #] &, R, {2}]]. Or, since we know the elements of G are unique, TableForm[Map[First@Position[G, #] &, R, {2}]]. When I saw {#1 -> 1, #2 -> 2, #3 -> 3, #4 -> 4} & @@ G, I asked myself "isn't that just mapping each element to its position?". – lericr Nov 10 '23 at 17:21
  • @lericr I'm always open to tips and suggestions. I learn a lot with you guys! – Red Banana Nov 11 '23 at 01:31

0 Answers0