# Looking for a function that can squeeze matrices

I am looking for a function that could replace matrices composed of scalar matrices subparts with matrices where those subparts are replaced with numbers.

That is,

$$\left( \begin{array}{cccc} 1 & 0 & 2 & 0 \\ 0 & 1 & 0 & 2 \\ 3 & 0 & 4 & 0 \\ 0 & 3 & 0 & 4 \\ \end{array} \right)\to \left( \begin{array}{cc} 1 & 2 \\ 3 & 4 \\ \end{array} \right)$$

That is, an operation inverse to KroneckerProduct[A, IdentityMatrix[n]] (which replaces numbers with scalar matrices of order n).

The function should look for the best replacement possible, that is the result should be a matrix of minimal possible order.

How to realise this?

• I would look at the paper Van Loan, Charles F. "The ubiquitous Kronecker product." (core.ac.uk/download/pdf/82128039.pdf). I think it discusses the solution of such of equations. Dec 11, 2022 at 14:38

BlockMap and Tr.
n=2;

• squeeze[x_] := SelectFirst[BlockMap[Tr, x, {#, #}]/# & /@ Divisors[Length[x]] // Reverse, KroneckerProduct[#, IdentityMatrix[Length[x]/Length[#]]] == x &] Dec 12, 2022 at 17:01