def convert_mp(mp):
    if hasattr(mp, 'mp'):
        mp_left = mp.mp(0)
        mp_right = mp.mp(1)
    else:
        mp_left = mp.mp_nofunc(0)
        mp_right = mp.mp_nofunc(1)
    if (mp.MUL() or mp.CMD_TIMES() or mp.CMD_CDOT()):
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if (lh.is_Matrix or rh.is_Matrix):
            return mat_mul_flat(lh, rh)
        else:
            return mul_flat(lh, rh)
    elif (mp.DIV() or mp.CMD_DIV() or mp.COLON()):
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if (lh.is_Matrix or rh.is_Matrix):
            return sympy.MatMul(lh, sympy.Pow(rh, (- 1), evaluate=False), evaluate=False)
        else:
            return sympy.Mul(lh, sympy.Pow(rh, (- 1), evaluate=False), evaluate=False)
    elif mp.CMD_MOD():
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if rh.is_Matrix:
            raise Exception('Cannot perform modulo operation with a matrix as an operand')
        else:
            return sympy.Mod(lh, rh, evaluate=False)
    elif hasattr(mp, 'unary'):
        return convert_unary(mp.unary())
    else:
        return convert_unary(mp.unary_nofunc())
def convert_mp(mp):
    if hasattr(mp, 'mp'):
        mp_left = mp.mp(0)
        mp_right = mp.mp(1)
    else:
        mp_left = mp.mp_nofunc(0)
        mp_right = mp.mp_nofunc(1)
    if (mp.MUL() or mp.CMD_TIMES() or mp.CMD_CDOT()):
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if (lh.is_Matrix or rh.is_Matrix):
            return mat_mul_flat(lh, rh)
        else:
            return mul_flat(lh, rh)
    elif (mp.DIV() or mp.CMD_DIV() or mp.COLON()):
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if (lh.is_Matrix or rh.is_Matrix):
            return sympy.MatMul(lh, sympy.Pow(rh, (- 1), evaluate=False), evaluate=False)
        else:
            return sympy.Mul(lh, sympy.Pow(rh, (- 1), evaluate=False), evaluate=False)
    elif mp.CMD_MOD():
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        if rh.is_Matrix:
            raise Exception('Cannot perform modulo operation with a matrix as an operand')
        else:
            return sympy.Mod(lh, rh, evaluate=False)
    elif hasattr(mp, 'unary'):
        return convert_unary(mp.unary())
    else:
        return convert_unary(mp.unary_nofunc())