# Symbolic manipulation of matrix elements [closed]

Can Mathematica compute matrix multiplications/additions symplifying them by a defined set of rules? For example if I have the rules $bc=x, ac=z, ze=w$ and give Mathematica the expression $$\begin{pmatrix} a & 0\\ b & 0 \end{pmatrix} \begin{pmatrix} ce & d\\ 0 & 0 \end{pmatrix}$$ I would want to get $$\begin{pmatrix} ace & ad\\ bce & bd \end{pmatrix} \rightarrow \begin{pmatrix} w & ad\\ xe & bd \end{pmatrix}$$ i.e. the shortest expression possible for all elements.

• If I understand correctly, you need to read this reference.wolfram.com/language/ref/Dot.html and this: reference.wolfram.com/language/ref/Replace.html Sep 21, 2016 at 11:33
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Sep 21, 2016 at 11:36
• People here generally like users to post code as Mathematica code instead of images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this this meta Q&A helpful Sep 21, 2016 at 11:37

Building on my comment:

m1 = {{a, 0}, {b, 0}};
m2 = {{c e, d}, {0, 0}};

(m1.m2) //. {b*c -> x, a*c -> z, z*e -> w} // MatrixForm

gives what you want.

You may want to read the docmentation for Dot, Replace and ReplaceRepeated. Dot (also .) is the matrix product, Replace (also \.) applies rules to change your expression (only once!) and ReplaceRepeted (also \\.) performs replacements until the expression doesn't change anymore.

• As the OP seems to be a newbie, it might be good to point out the perils of MatrixForm. Sep 21, 2016 at 11:49
• Thank you! Maybe you also know if there is a way to tell Mathematica that the elements a, b, c ... are actually block matrices? So for example it uses a block matrix inversion, instead of the inversion for matrices of numbers Sep 21, 2016 at 12:39
• @user43246 a,b,... can be anything (that's the power of symbolic calculation!): you could replace their matrix form at the end of all the calculations. I assume you know all of them, otherwise it might be complicated and I don't know how to treat this case. Sep 21, 2016 at 14:10
• However Inverse[{{a,b},{c,d}}] gives a generic {{d/(da-bc), ...}}, while the right answer in the case of block matrices is {{Inverse[da-bc].d, ...}} (notice also how the order is important since the matrix product is non-commutative). For this reason I was wondering if there was a way to tell Mathematica that a,b,c,d are not numbers, but matrices. Sep 21, 2016 at 15:14
• @user43246 I suggest you to open another post with this problem (maybe add a simple example too): in this way people with more knowledge then me will be able to see and possibly answer it! :) Sep 21, 2016 at 15:23

Simplify also works:

m1 = {{a, 0}, {b, 0}};
m2 = {{c e, d}, {0, 0}};

Simplify[m1.m2, {b*c == x, a*c == z, z*e == w}]
(*  {{w, a d}, {e x, b d}}  *)