#NEWLINE# def blockinverse_2x2( expr ) : #NEWLINE# #INDENT# if ( isinstance ( expr . arg , BlockMatrix ) and ( expr . arg . blockshape == ( 2 , 2 ) ) ) : #NEWLINE# #INDENT# [ [ A , B ] , [ C , D ] ] = expr . arg . blocks . tolist ( ) #NEWLINE# return BlockMatrix ( [ [ ( A - ( ( B * D . I ) * C ) ) . I , ( ( ( - A ) . I * B ) * ( expr - ( ( C * A . I ) * B ) ) . I ) ] , [ ( ( ( - ( D - ( ( C * A . I ) * B ) ) . I ) * C ) * A . I ) , ( D - ( ( C * A . I ) * B ) ) . I ] ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return expr