def bc_dist(expr):
 (factor, mat) = expr.as_coeff_mmul()
 if ((factor != 1) and isinstance(unpack(mat), BlockMatrix)):
  B = unpack(mat).blocks
  return BlockMatrix([[(factor * B[(i, j)]) for j in range(B.cols)] for i in range(B.rows)])
 return expr

def bc_dist ( expr ) : ( factor , mat ) = expr . as_coeff_mmul ( ) if ( ( factor != 1 ) and isinstance ( unpack ( mat ) , BlockMatrix ) ) : B = unpack ( mat ) . blocks return BlockMatrix ( [ [ ( factor * B [ ( i , j ) ] ) for j in range ( B . cols ) ] for i in range ( B . rows ) ] ) return expr
turn a*[x .