tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: silly behavior of factor(6)



On Wed, Apr 28, 2010 at 08:16:09PM +0000, David Holland wrote:
 > [...] the whole point of this thread is to strike a balance between
 > what's strictly meaningful and what makes the most ad hoc sense.

Specifically, I see four criteria:

   1. The numbers printed, when multiplied together, should equal the
      input number.
   2. The numbers printed should be uniquely determined.
   3. The numbers printed should be prime except for special cases.
   4. The numbers printed should be prime in the strictest sense.

For numbers > 1 the behavior is clear. Otherwise the following
possibilities have been suggested:
   - for 1: print 1, print no factors, or error;
   - for 0: print 0, print no factors, error, or exit silently;
   - for negatives, insert -1 and factor the absolute value, or error.

Erroring on 1 does not make much sense; neither does exiting silently
or skipping to the next input (POLA); printing no factors for zero is
incorrect (violates the first criterion). This leaves these
possibilities:
   - for 1: print 1, or print no factors;
   - for 0: print 0, or error;
   - for negatives, insert -1 and factor the absolute value, or error.

For each of these, the first case satisfies the first three criteria
but not the fourth; the second case satisfies the fourth as well.
Therefore it seems that there are only two real possibilities here,
and the choice is whether to adopt the fourth criterion or relax it.

ISTM that the first three criteria are an adequate compromise between
pragmatism and purity, but not everyone agrees. There isn't really any
overwhelmingly compelling argument for accepting zero or negative
numbers; and as we haven't for years and nobody's especially
complained it seems unlikely that one will appear.

So I think I'm going to fix it to behave in accordance with the second
set of alternatives: 1 will print no factors, and integers < 1 will be
rejected.

Since this has already been beaten to death, please speak up only if
you have a strong argument for the other choice, or if you think the
above analysis is bunk.

-- 
David A. Holland
dholland%netbsd.org@localhost


Home | Main Index | Thread Index | Old Index