From: Robert Dober Date: 2009-03-06T23:10:59+09:00 Subject: [ruby-core:22700] Re: [Bug #1243] 1 is prime On Wed, Mar 4, 2009 at 9:15 AM, Yugui (Yuki Sonoda) wrote: > On 3/4/09 1:40 AM, Dave B wrote: >> + � �value = -value if value < 0 �<--- NOT required ? >> + � �return false if value < 2 >> >> I think your negative guard is not required? > > For a arbitrary positive prime number p, -p is a prime element in the > ring of integers. On the other hand, it is sure that just saying "prime > numbers" means positive ones. > > (http://en.wikipedia.org/wiki/Prime_number) >> Without further specification, however, �prime number� always means a > positive integer prime > > I am at a loss whether -2.prime? should return true or false? �Which is > more useful for Rubyists? > IIRC 1 was discarded as prime because it messed up the uniqueness of factorization. If we want to keep this spirit I see no solution for negative numbers. One could maybe define that all negative numbers are composed with the exception of -1, which is prime ARRRGH and the additional rule that -1 can only occur ? times (in the regexp sense of ? ) in a factorization. But maybe it makes more sense to say x.prime? if and only if x.abs.prime? and for all x: x.primefactors.count{ | f| f.negative? } < 2 I guess these are lousy ideas, does anyone have something better to suggest? Cheers Robert > -- > Yugui > http://yugui.jp > > -- There are some people who begin the Zoo at the beginning, called WAYIN, and walk as quickly as they can past every cage until they get to the one called WAYOUT, but the nicest people go straight to the animal they love the most, and stay there. ~ A.A. Milne (from Winnie-the-Pooh)