HP Forums

Full Version: A perfect example!?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The HP User Guide has an example so perfect I must share it with you.

There is an example procedure to check whether a number is a perfect number, and a test procedure showing the perfect numbers up to 100. The first of which is 6.
OK, all looking good.
To familiarise myself with my new calculator, I typed this in.
I was curious as to whether -6 was also a perfect number and also wanted to check that the Is Perfect routine didn't contain any nasties, like looping forever on an unexpected negative.
It didn't loop forever. But now it showed 1 as the first number.
Checking Wikipedia, 1 isn't a perfect number.
So why did Isperfect originally not show 1, and then did?

Inspecting the test harness, that is described as showing all perfect numbers up to 100, we see that it actually begins testing at 2, rather than the more obvious 1 or 0, which is why it never checked whether Isperfect was working correctly for 0 or 1.

Some more suspicious than I might wonder whether someone knew there was a bug in Isperfect and adjusted the test harness to avoid revealing the bug. Or whether other HP tests pass similarly.

But as it is, this example is a perfect example for debugging, and teaching that it's best to put the recognition test in one place, not - in effect - putting some "is it" tests in a separate routine.
1 isn't prefect for the same reason 1 isn't prime -- it doesn't make sense.

BTW: all even perfect numbers are of the form: 2pāˆ’1(2p āˆ’ 1) is an even perfect number when 2pāˆ’1 is prime

It is still unknown if there exists an odd perfect numbers.

OT: the computations led by the OddPerfect project, using factorizations of their own and from other sources (Brent composites, RSALS / NFS@Home, etc.), indicate that if any odd perfect numbers exist, they must be quite large.
Reference URL's