In reply to nnd:
First unroll the foreach
A[0].sum() with (int'(A[item.index][0] * AI[0][item.index])) == (0 == 0)
A[0].sum() with (int'(A[item.index][0] * AI[1][item.index])) == (0 == 1)
A[1].sum() with (int'(A[item.index][1] * AI[0][item.index])) == (1 == 0)
A[1].sum() with (int'(A[item.index][1] * AI[1][item.index])) == (1 == 1)
Then expand the sum
( A[0][0] * AI[0][0] + A[1][0] * AI[0][1] ) == 1 // 1 * 5 + 2 * 7
( A[0][0] * AI[1][0] + A[1][0] * AI[1][1] ) == 0 // 1 * 6 + 2 * 8
( A[0][1] * AI[0][0] + A[1][1] * AI[0][1] ) == 0 // 3 * 5 + 4 * 7
( A[0][1] * AI[1][0] + A[1][1] * AI[1][1] ) == 1 // 3 * 6 + 4 * 8
This assumes D1 is the column and D2 is the row of your matrices.