Message Boards Message Boards

0
|
1672 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Failed to validate matrices' multiplication with pattern simplification

Posted 2 years ago

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

Attachments:
POSTED BY: Hongyi Zhao
4 Replies
Posted 2 years ago

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}
POSTED BY: Hongyi Zhao

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}]
POSTED BY: Gianluca Gorni
Posted 2 years ago

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}
POSTED BY: Hongyi Zhao

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}
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract