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

221 Views Asked by At

For working with countable sets I have to define a coding function of all finite subsets of N (natural numbers). How can I do this? I started with finding a function for all natural numbers: f(n)=1+2+...+(n-1)+n. But how can I express a coding function for all possible subsets of f? And how can I say that f contains all finite natural numbers? I can not say n=infinity-1 because infinity-1 is still infinity. Is there a formal way constitute all finite natural numbers?

1

There are 1 best solutions below

3
Cereal On

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 1s 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}.

In programming terms, say for instance in Python (here I'm using lists to represent subsets of N) this would look like

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