I have some trouble with taking the inverse matrix of a product. The inverse is not calculated correctly. Could you please tell me what the problem is.

The full problem is in the OPL:

Library/NAU/setLinearAlgebra/similar3.pg

TEXT(beginproblem());

Context("Matrix");

{

$P=Matrix([[random(-3,3,1),random(-3,3,1)],[random(-3,3,1),random(-3,3,1)]]);

redo if (abs($P->det) != 1);

$Pi=$P->inverse;

}

{

$Q=Matrix([[random(-3,3,1),random(-3,3,1)],[random(-3,3,1),random(-3,3,1)]]);

redo if (abs($Q->det) != 1);

}

$I=Matrix([[1,0],[0,1]]);

{

$B=Matrix([[random(-3,3,1),random(-3,3,1)],[random(-3,3,1),random(-3,3,1)]]);

$A=$Pi*$B*$P;

redo if ($B==$A);

}

$R=$Q*$P;

$Rin = $R->inverse; # This does not seem to work. Please tell me why?

$Ri = $P->inverse*$Q->inverse; # This works.

...