There is an inconsistency in the use of the LU decomposition of a matrix. If matrix A is declared in the RDF ring then P, L, U = A.LU () provides PA = LU but if A is declared in the RR ring (or QQ, ZZ,...) then A = PLU. Therefore in a case P is P.transpose () on the other.