简体   繁体   English

如何为 N 的所有有限子集定义编码 function?

[英]How to define a coding function for all finite subsets of N?

For working with countable sets I have to define a coding function of all finite subsets of N (natural numbers).为了处理可数集,我必须定义 N(自然数)的所有有限子集的编码 function。 How can I do this?我怎样才能做到这一点? I started with finding a function for all natural numbers: f(n)=1+2+...+(n-1)+n.我开始为所有自然数找到一个 function:f(n)=1+2+...+(n-1)+n。 But how can I express a coding function for all possible subsets of f?但是我如何为 f 的所有可能子集表达编码 function? And how can I say that f contains all finite natural numbers?我怎么能说 f 包含所有有限自然数呢? I can not say n=infinity-1 because infinity-1 is still infinity.我不能说 n=infinity-1 因为 infinity-1 仍然是无穷大。 Is there a formal way constitute all finite natural numbers?有没有一种形式化的方式来构成所有的有限自然数?

If I understand you correctly, you wish to define a function that would count through all finite subsets of N. One way to achieve this is to use the 1 s in the binary representation of a number n to encode the elements of f(n) , that is f(n) = {k \in N | the k-th binary digit of n is 1}如果我理解正确的话,您希望定义一个 function 来计算 N 的所有有限子集。实现此目的的一种方法是使用数字n的二进制表示中的1来编码f(n)的元素, 即f(n) = {k \in N | the k-th binary digit of n is 1} f(n) = {k \in N | the k-th binary digit of n is 1} . f(n) = {k \in N | the k-th binary digit of n is 1}

In programming terms, say for instance in Python (here I'm using lists to represent subsets of N) this would look like在编程术语中,例如在 Python 中(这里我使用列表来表示 N 的子集)这看起来像

def f(n):
    result = []
    k = 1
    while n != 0:
        if n % 2 == 1:
            result.append(k)
        k += 1
        n //= 2
    return result

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将函数定义为有限和 - Define a function as a finite sum 如何使用递归编写all_subsets函数? - How to write all_subsets function using recursion? Matlab编码n维函数 - matlab coding n-dimensional function 如何复制定义函数以使其成为'n'变体? (蟒蛇) - How to copy define function to make 'n' variations of it? (Python) 如何使用数组在fortran中定义变量函数 - How to define a n variable function in fortran using array 将 arguments 传递给 function 时如何定义条件? (在python中编码更有效) - How to define a condition when passing arguments to a function? ( coding more efficiently in python) 如何在 C 中定义变量“N”类型,当 N 是 C 的输入并且它也由输入函数定义时(N 将提示用户输入) - How to define a variable “N” type in C when N it is an input to C and its also defined by an input function( N will prompt the user for input) Scala函数用于获取大小为k的所有已排序子集 - Scala function to get all sorted subsets of size k 将功能应用于拆分数据帧所有子集的一列 - Applying a function to one column over all subsets of a split dataframe r:将 n 个 dataframe 子集从在自定义 function 中创建的列表中分配给全局环境中的对象 - r: Assign n dataframe subsets from a list created in a custom function to objects in global environment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM