Question: Extract terms from matrix using markers

I have written a Maple code which extracts terms in a matrix into two new matrices dependent on certain markers. I am running into problems with this particular code as it requires enormous amounts of RAM when going to large matrix sizes (32GB+); and will take 4-5 days to complete for larger matrix sizes, or simply crashes.

Each matrix element is an algebraic expression containing A and B and the markers hh and ss. The example in the attached Maple file (3 x 3 matrix) is a minimal working example and the actual expressions are much longer and the matrices much larger (5000 x 5000 or larger). I utilise the symmetry of the matrix to ease the process, and use the tril command of MTM to extract only the lower triangular matrix; as this is all that is needed for the next stage (I have yet to test how efficient this command is, but use it for now).

The two markers hh and ss are targeted and if found in an expression that term will be extracted accordingly. The matrix elements are expanded and a procedure run over the matrix and will extract terms with hh into one matrix and terms with ss into another matrix. I think the map(expand,...) part is what causes the memory issue; but I believe this needs to be done to correctly extract terms.

Any help or tips are greatly appreciated on how to increase efficiency and improve this method.
 

Sub_matrix_extraction.mw

-Yeti

 

 

Please Wait...