python language: infimum and supremum of integers

Erik Max Francis max at alcyone.com
Wed Apr 23 23:00:37 CEST 2003


Grégoire Dooms wrote:

> I need a lower and higher integer for initializing lower and higher
> bounds in an algorithm.  I know integers have no limits(maximum and
> minimum) in python and infimum and supremum would do the job too.

Well, to start with, there's sys.maxint.  If you know you're dealing
with 2's complement integers, then minint would be -sys.maxint - 1.

> I empirically discovered (Python 2.2.2) that None could be considered
> an
> infimum and any string could be considered a supremum.
> e.g "a">int(x) is always true and None<int(x) is always false
> 
> But this fact is not stated in the language reference.

The language says that the ordering between objects of (some) different
types will be consistent in an implementation, but will be no be
guaranteed from implementation to implementation.  So in your
implementation, None might be less than all integers, but in another
implementation it might not be.

The best solution to your problem is probably what Alex suggested; make
a set of custom types that always compares less (or greater) than any
other object, and use that as your sentinel.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If I had known, I would have become a watchmaker.
\__/ Albert Einstein
    7 Sisters Productions / http://www.7sisters.com/
 Web design for the future.




More information about the Python-list mailing list