In reply to n347:
$size(arr,2) is the size of arr’s second dimension, in this example index j.
The implications are to prevent out-of-bounds index selects. Any time there is a +1 or -1 in the comparison, you need a guard to prevent out-of bounds. I do believe
i>0 && j>0 -> arr[i]j] != arr[i+1][j-1];
should have been
i<$size(arr,1)-1 && j>0 -> arr[i]j] != arr[i+1][j-1];