Skip to main content
added 203 characters in body
Source Link
Simon
  • 10.2k
  • 5
  • 57
  • 73

My personal favourite for this type of task is LogicalExpand (and I can't believe that hasn't been mentioned in the existing 5 answers...)

In[1]:= A = Array[a, {2, 2}];
        B = Array[b, {2, 2}];
        LogicalExpand[A == B]

Out[3]= b[1, 1] == a[1, 1] && b[1, 2] == a[1, 2] && 
        b[2, 1] == a[2, 1] && b[2, 2] == a[2, 2]

This will also work just as simply in the case of the higher-rank tensors that you're interested in.

If you want the output as a list, then you could do a Block hack like:

In[4]:= Block[{And = List}, LogicalExpand[A == B]]

Out[4]= {b[1, 1] == a[1, 1], b[1, 2] == a[1, 2], 
         b[2, 1] == a[2, 1], b[2, 2] == a[2, 2]}

My personal favourite for this type of task is LogicalExpand (and I can't believe that hasn't been mentioned in the existing 5 answers...)

In[1]:= A = Array[a, {2, 2}];
        B = Array[b, {2, 2}];
        LogicalExpand[A == B]

Out[3]= b[1, 1] == a[1, 1] && b[1, 2] == a[1, 2] && 
        b[2, 1] == a[2, 1] && b[2, 2] == a[2, 2]

My personal favourite for this type of task is LogicalExpand (and I can't believe that hasn't been mentioned in the existing 5 answers...)

In[1]:= A = Array[a, {2, 2}];
        B = Array[b, {2, 2}];
        LogicalExpand[A == B]

Out[3]= b[1, 1] == a[1, 1] && b[1, 2] == a[1, 2] && 
        b[2, 1] == a[2, 1] && b[2, 2] == a[2, 2]

This will also work just as simply in the case of the higher-rank tensors that you're interested in.

If you want the output as a list, then you could do a Block hack like:

In[4]:= Block[{And = List}, LogicalExpand[A == B]]

Out[4]= {b[1, 1] == a[1, 1], b[1, 2] == a[1, 2], 
         b[2, 1] == a[2, 1], b[2, 2] == a[2, 2]}
Source Link
Simon
  • 10.2k
  • 5
  • 57
  • 73

My personal favourite for this type of task is LogicalExpand (and I can't believe that hasn't been mentioned in the existing 5 answers...)

In[1]:= A = Array[a, {2, 2}];
        B = Array[b, {2, 2}];
        LogicalExpand[A == B]

Out[3]= b[1, 1] == a[1, 1] && b[1, 2] == a[1, 2] && 
        b[2, 1] == a[2, 1] && b[2, 2] == a[2, 2]