I wanted to get a better understanding of OOP in Python and wrote a bit of code describing (infinite) ordinal arithmetic. I defined a class named Omega()
with the usual comparison operators (==
, <=
, etc.), addition and multiplication.
I thought I'd check whether (as should be true) the first infinite ordinal added to itself was less-than-or-equal-to the first uncountable ordinal. Launching the interactive shell, here's what I found:
>>> a, b = Omega(), Omega(1)
>>> (a+a) <= b
False
>>> (a+a) <= b
True
>>> (a+a) <= b
False
The same expression produces different truth values.
I continued to test the expression and could not spot any pattern. If I re-interpret the code, I find that repeatedly testing the expression produces a different sequence of True
/False
values.
What could be causing this behaviour?
If it's relevant, I'm using CPython 2.7.5 on Windows 8.1.
Here's the Python code I ran: http://pastebin.com/XPqMphBw
print
statements in your methods to see what values the variables actually contain each time you do the comparison.index
andcopies
sometimes appear to be integers, other times instances ofOmega
. It's not clear how your implementation works.(a+a) <= b, (a+a).__dict__, b.__dict__
shows no difference in the dicts between True and False results. Agree that the types of copies,index,power are confusing. All the comparison code expects them to be Omegas, but all the assignments are to ints.