2
$\begingroup$

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.

$\endgroup$

closed as off-topic by Wjx, m_goldberg, user31159, MarcoB, Edmund Sep 23 '16 at 1:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Wjx, m_goldberg, Community, MarcoB, Edmund
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ 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 $\endgroup$ – mattiav27 Sep 21 '16 at 11:33
  • $\begingroup$ 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! $\endgroup$ – Michael E2 Sep 21 '16 at 11:36
  • $\begingroup$ 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 $\endgroup$ – Michael E2 Sep 21 '16 at 11:37
6
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ As the OP seems to be a newbie, it might be good to point out the perils of MatrixForm. $\endgroup$ – Michael E2 Sep 21 '16 at 11:49
  • $\begingroup$ 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 $\endgroup$ – user43246 Sep 21 '16 at 12:39
  • $\begingroup$ @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. $\endgroup$ – mattiav27 Sep 21 '16 at 14:10
  • $\begingroup$ 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. $\endgroup$ – user43246 Sep 21 '16 at 15:14
  • $\begingroup$ @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! :) $\endgroup$ – mattiav27 Sep 21 '16 at 15:23
3
$\begingroup$

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}}  *)
$\endgroup$

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