# Counting all matrices in a family obeying a certain rule

I would like to use the Count[list, pattern] method to count all 4x4 matrices with entries in $\lbrace 0 ,1 \rbrace$ that have a certain Jordan canonical form. The problem is that I haven't the slightest clue how to "generate" the family of matrices or phrase the rule in the argument of Count... how would I go about these things? Any help is much appreciated (and sorry if this is a basic question that could've been found with more persistent google-ing).

• It's very hard to give advice as to how to generate the family of matrices without any details about this family. – yohbs Feb 16 '18 at 3:01
• @yohbs The only rules I have for this family are that all matrices should be 4x4 and the entries should be either 0 or 1. From there, I want to count all of the matrices in this family that have a certain Jordan form (pattern argument). – Dan Feb 16 '18 at 3:04

fourbyfourbinarymatrices = Tuples[{0, 1}, {4, 4}];

Length @ fourbyfourbinarymatrices


65536

Among the first 1000 elements of fourbyfourbinarymatrices 136 of them have a JordanDecomposition whose first component has a trace equal to 2:

Count[fourbyfourbinarymatrices[[;; 1000]],
_?(Tr[JordanDecomposition[#][[1]]] == 2 &)]


136

And 4 of them have a similarity matrix in their JordanDecomposition that is equal to Reverse/@IdentityMatrix[4]:

Count[fourbyfourbinarymatrices[[;; 1000]],
_?(JordanDecomposition[#][[1]] === (Reverse /@ IdentityMatrix[4]) &)]


4

• The concrete constructions and examples are very helpful. Thanks a bunch! Follow-up question: how does Mathematica enumerate the tuples in our matrix list? – Dan Feb 16 '18 at 3:27
• @Dan, glad it was useful. Thank you for the accept. Welcome mma.se. Re how Tuples enumerates the tuples, I don't know how it is implemented. – kglr Feb 16 '18 at 3:32
• @Dan This should give you some hint: base = 2; FromDigits[Flatten[#], base] & /@ Tuples[Range[0, base-1], {4, 4}][[1 ;; 10]] ;o) Does also work with other bases... – Henrik Schumacher Feb 16 '18 at 7:04
Count[myMatrixList, # == JordanDecomposition[#]&]