# All possible cases of a matrix

Assume that I have two number $a$ and $b$ and an $n \times n$ matrix. How can I write code which can compute all determinants of the matrices with entries $a$ or $b$. In other words, I want to see the determinant of all $2^{n^{2}}$ matrices with entries $a$ and $b$.

• A short example with a Mathematica code would be helpful for understanding the problem. At least show what you have tried. – Sumit Sep 29 '17 at 12:16
• Do you need the multiplicity of each possible determinant value? – Coolwater Sep 29 '17 at 12:23
• A.Mpi, please see Michael E2's comment here which is our community's standard welcome message to new users. – kglr Sep 29 '17 at 12:57

n = 3;
matrices = Tuples[{a, b}, {n, n}];
Length@matrices


512

Det /@ matrices // Simplify // Short


{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-a (a-b)^2, -a (a-b)^2, a (a-b)^2, <<486>>, (a-b)^2 b, -(a-b)^2 b, -(a-b)^2 b, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

Det /@ matrices // Simplify // Tally // Grid[#, Dividers -> All] &