There are definitely mathematics you can perform on “infinite sets”
though you’re not going to use a Python stdlib set to accomplish
those. Likely you’ll need to work out which properties of your
“infinite set” are relevant to the operations you’ll be performing,
and model a custom Python data structure (perhaps an object Class)
to have variables (e.g. class attributes) which represent those
properties.
Personally, I feel we luck enough context about what you’re trying to do in order to offer a proper alternative.
I don’t know what you mean by “evaluating it’s contents at once”. I might not have a PhD in Mathematics as yet, but I certainly feel it’s highly impossible. What’s possible however is to evaluate the properties of an infinite set based on its elements, but not each individual element of that set. I don’t know if I’m making sense.
Also, I think you’ll have to redefine your definition of infinite. Like @steven.daprano said, the universe is finite, and so is the memory on your PC. It just might be really really really huge, but not endless.
Lastly, if you consider your task computation intensive, I suggest you look into Python libraries targeted towards scientific calculations and computations, or you code use some C code for this.
Namely, the line Q = set(Q) doesn’t do anything. Python sets can’t be put into each other because they are mutable and therefore non-hashable. Perhaps you mean to use frozensets.
>>> ZERO = frozenset()
>>> Q = ZERO
>>> L = [ZERO]
>>> for i in range(5):
... Q = frozenset({Q})
... L.append(Q)
...
...
>>> L
[frozenset(), frozenset({frozenset()}), frozenset({frozenset({frozenset()})}), frozenset({frozenset({frozenset({frozenset()})})}), frozenset({frozenset({frozenset({frozenset({frozenset()})})})}), frozenset({frozenset({frozenset({frozenset({frozenset({frozenset()})})})})})]
Importing other libraries is the right way to do it. The inspect module is part of the std lib, it is guaranteed to be available.
The inspect module is the right tool for the job. If you asked a carpenter how to cut a piece of wood, and they said “use a saw”, would you say “I don’t want to use a saw. Can I use a screwdriver or a hammer instead?”
Just use the damn saw wink
But if you prefer, you can open the inspect.py file in your text editor, Select All, then Copy, then go into your file, and Paste. Then repeat for any imports which the inspect module uses.
Now you have duplicated all the code in inspect, so you can use it without an import. Your script is now 200 times bigger than it needs be, all to save a one line import. Yay!!!
I think people get confused because infinity is not a number. We’ll it’s not so stop trying to treat it like one. You don’t need to iterate up to infinity. Infinity is good on its own.
(Not saying regular numbers don’t need iteration, just saying that infinity has its own algorithm that makes it accessible; it’s not just a very large number)
Think mathematically. To draw an infinite line all you need is y=x, boom! Infinite line. On the other hand if you try to draw a very large line that’s not infinite, you need to have the calculator stop at some inconvenient location.
In the end, iteration is a limitation. Without the need for limitation, there is no need for iteration.
I am not confused by infinity. I am confused by your objective. I have no idea what you mean by “can see every number at once! (With proper focus)”, nor what problem you are trying to solve and asking about. Speaking as a math student, the best way to make yourself understood when your intuitions are not clear to everyone (and I don’t think they are clear to anyone here) is to use a formal language with technical and well-defined terms. Otherwise, it is impossible to read your mind.
Well, you might not know the most accurate terms, but you can try to explain what you mean with the words you use (‘adhere’, for example).
One thing that would also help is a bit of context. Are you a student solving assignments? Are you writing a module to do formal math? What is the background of your question?
If the goal is to produce von Neumann numbers, does Dennis’ code not suffice? Namely, put in a function,
def number(n):
result = frozenset()
for i in range(n):
result = frozenset({result})
return result
By the way, you’re using an altered definition of von Neumann numbers, which are usually S(n) = n ∪ {n} rather than S(n) = {n} (I’m not sure why this is more usual, maybe it’s easier to work with in some respects?).