2
$\begingroup$

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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – mikado
    Commented Dec 11, 2022 at 14:38

1 Answer 1

4
$\begingroup$

BlockMap and Tr.

n=2;
A = {{1, 2}, {3, 4}};
B = KroneckerProduct[A, IdentityMatrix[n]];
BlockMap[Tr, B, {n, n}]/n
$\endgroup$
8
  • $\begingroup$ And how the code would determine the suitable n? $\endgroup$
    – Anixx
    Commented Dec 11, 2022 at 8:00
  • $\begingroup$ The matrices that do not allow such simplification should not be affected, and those which allow several ways should choose the best simplification. $\endgroup$
    – Anixx
    Commented Dec 11, 2022 at 8:02
  • 1
    $\begingroup$ @Anixx We needs an example to illustrate such complex cases. $\endgroup$
    – cvgmt
    Commented Dec 11, 2022 at 8:15
  • 1
    $\begingroup$ @Anixx Edit the original question and add such examples can help other people to read the comple question. $\endgroup$
    – cvgmt
    Commented Dec 11, 2022 at 9:27
  • 1
    $\begingroup$ squeeze[x_] := SelectFirst[BlockMap[Tr, x, {#, #}]/# & /@ Divisors[Length[x]] // Reverse, KroneckerProduct[#, IdentityMatrix[Length[x]/Length[#]]] == x &] $\endgroup$ Commented Dec 12, 2022 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.