Failed to validate matrices' multiplication with pattern simplification

I try to validate the trick given on page 68 of this lecture note to simplify the matrices’ multiplication by using the pattern based simplification.

See the attached file for details. Any hints will be highly appreciated.

Regards,
HZ

13lectures.nb (6.91 KB)

This matmul only makes one simplification only, and then feeds the result to Dot. I would make the simplifications before using Dot:

{A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, B, 
  IA} //. ({x___, y_, z_, t___} /; 
    Simplify[y . z == IdentityMatrix[3]]) :> {x, t}
% == {A, B, B, B, B, B, IA}

Yes, it does the trick:

In[104]:= A = Array[x[#1, #2] &, {3, 3}];
IA = Inverse[A];
B = Array[y[#1, #2] &, {3, 3}];
IB = Inverse[B];

{A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, B, 
   IA} //. ({x___, y_, z_, t___} /; 
     Simplify[y . z == IdentityMatrix[3]]) :> {x, t};
% == {A, B, B, B, B, B, IA}

(*Timing[ 
{A,B,IA,A,B,IA,A,B,IA,A,B,IA,A,B,IA}//.({x___,y_,z_,t___}/;Simplify[y.\
z==IdentityMatrix[3]]):>{x,t};
%=={A,B,B,B,B,B,IA}
]*)

Out[109]= True

BTW, how to check the performance of the above code block by Timing? I tried the following, but failed:

A = Array[x[#1, #2] &, {3, 3}];
IA = Inverse[A];
B = Array[y[#1, #2] &, {3, 3}];
IB = Inverse[B];

(*{A,B,IA,A,B,IA,A,B,IA,A,B,IA,A,B,IA}//.({x___,y_,z_,t___}/;Simplify[\
y.z==IdentityMatrix[3]]):>{x,t};
%=={A,B,B,B,B,B,IA}*)

Timing[ 
 {A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, B, 
   IA} //. ({x___, y_, z_, t___} /; 
     Simplify[y . z == IdentityMatrix[3]]) :> {x, t};
 % == {A, B, B, B, B, B, IA}
 ]

{0.006172, False}

The operator % does not work inside Timing. You can introduce an intermediate variable:

Timing[simplifiedList = {A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, B,
     IA} //. ({x___, y_, z_, t___} /; 
      Simplify[y . z == IdentityMatrix[3]]) :> {x, t};
 simplifiedList == {A, B, B, B, B, B, IA}]

Thanks for the tip. It worked:

In[6]:= A = Array[x[#1, #2] &, {3, 3}];
IA = Inverse[A];
B = Array[y[#1, #2] &, {3, 3}];
IB = Inverse[B];
Timing[simplifiedList = {A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, B,
     IA} //. ({x___, y_, z_, t___} /; 
      Simplify[y . z == IdentityMatrix[3]]) :> {x, t};
 simplifiedList == {A, B, B, B, B, B, IA}]

Out[10]= {0.00468, True}