# Table with multiple indices and constraints (conditions)

I want to make a table with following data,

$$a_{ij} = b_{ij}$$ for $$1\le i and $$|i-j| \ge 2$$.

Try

n = 7;
Table[If[Abs[i - j] > 2, a[i, j] == b[i, j], Nothing], {i, 1,n - 2}, {j, i+1, n - 2}] // Flatten
(*{a[1, 4] == b[1, 4], a[1, 5] == b[1, 5], a[2, 5] == b[2, 5],a[4, 1] == b[4, 1], a[5, 1] == b[5, 1], a[5, 2] == b[5, 2]}*)
• Thanks! How to get only non-zero entries of the table? Otherwise it looks a bit clumsy. – Physics Moron Jul 25 '19 at 13:18
• Without knowing a,b it's difficult to distinguish non-zero entries! – Ulrich Neumann Jul 25 '19 at 13:22
• I just meant the trivial 0 or Null entries that are appearing without referring to a or b.. – Physics Moron Jul 25 '19 at 13:33
• Nothing inside If is what you're looking for. My answer is edited. – Ulrich Neumann Jul 25 '19 at 13:39
• Thanks! This is what I was looking for and I understand it too. – Physics Moron Jul 25 '19 at 13:42

Try

n = 7;
t=Table[a[i, j] == b[i, j], {j, 1,n - 2}, {i, 1,j - 2}]/.{}->Sequence[]

giving

{{a[1,3]==b[1,3]},
{a[1,4]==b[1,4],a[2,4]==b[2,4]},
{a[1,5]==b[1,5],a[2,5]==b[2,5],a[3,5]==b[3,5]}}

And you can use Flatten on that if you don't want the extra {}

• This is great! But I have no clue how it's working! Can you explain that {}->Sequence[] part? Also can I generalize this to different conditions, say, |i-j| >= 5 or something.. – Physics Moron Jul 25 '19 at 13:31
• If you try that without the /.{}->Sequence[] you will see that it leaves in "empty" rows where none of the items match both your conditions, so I used that "trick" to discard empty rows. For your generalized conditions try n = 12; t=Table[ a[i, j] == b[i, j], {j, 1,n - 2}, {i, 1,j - 5}]/.{}->Sequence[] – Bill Jul 25 '19 at 13:36
• Yes, that's perfect. That should be imposed. – Physics Moron Jul 25 '19 at 13:40