def inv_quick(M):
 from sympy.matrices import zeros
 if any((i.has(Symbol) for i in M)):
  if all((i.has(Symbol) for i in M)):
   det = (lambda _: det_perm(_))
  else:
   det = (lambda _: det_minor(_))
 else:
  return M.inv()
 n = M.rows
 d = det(M)
 if (d is S.Zero):
  raise ValueError('Matrix det == 0; not invertible.')
 ret = zeros(n)
 s1 = (-1)
 for i in range(n):
  s = s1 = (- s1)
  for j in range(n):
   di = det(M.minorMatrix(i, j))
   ret[(j, i)] = ((s * di) / d)
   s = (- s)
 return ret

def inv_quick ( M ) : from sympy . matrices import zeros if any ( ( i . has ( Symbol ) for i in M ) ) : if all ( ( i . has ( Symbol ) for i in M ) ) : det = ( lambda _ : det_perm ( _ ) ) else : det = ( lambda _ : det_minor ( _ ) ) else : return M . inv ( ) n = M . rows d = det ( M ) if ( d is S . Zero ) : raise ValueError ( 'Matrix det == 0; not invertible.' ) ret = zeros ( n ) s1 = ( - 1 ) for i in range ( n ) : s = s1 = ( - s1 ) for j in range ( n ) : di = det ( M . minorMatrix ( i , j ) ) ret [ ( j , i ) ] = ( ( s * di ) / d ) s = ( - s ) return ret
return the inverse of m .