Python code optimization

The implementation of is_abundant has a “bug”, really a joke. The function won’t return False for a non-abundant, perfect, odd. Instead it raises ValueError to alert that a Mathematical discovery has been made.

1 Like

I’m not sure what number you tried, and what is meant here by “Mathematical discovery”?

I wish I was saying that because I found it by trying. I only read the implementation. It is not known if there exist perfect odd numbers.
So, the implementation of is_perfect (which is used by is_abundant) raises if one inputs an odd number that is perfect.

raise ValueError(filldedent('''In 1888, Sylvester stated: "
            ...a prolonged meditation on the subject has satisfied
            me that the existence of any one such [odd perfect number]
            -- its escape, so to say, from the complex web of conditions
            which hem it in on all sides -- would be little short of a
            miracle." I guess SymPy just found that miracle and it
            factors like this: %s''' % factorint(n)))
1 Like

This is probably the nicest “ValueError” you will ever see in Python. :slight_smile:

On odd perfect numbers, if you wanted to prove the general result you should surely start from multiples of the number 3 - it has some interesting properties, one of which is nice: n is divisible by 3 if and only if the sum of its digits is divisible by 3. My guess is there are no perfect odd multiples of 3.