MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Peculiar behaviour of Mathematica code


I have some Mathematica code which I borrowed from the Divisors package.
This code should return True if its argument is semiperfect and False if it 
is not.

Here is the code

SemiperfectQ[n_Integer?Positive]:=Module[{d=Most[Divisors[n]]},

    n==Plus@@#&/@(Or@@Rest[Subsets[d]])

]

This seems to work fine if the argument is composite. However, if the input 
is prime it returns {False} rather than False.

Similarly the code for returning True if a number is weird behaves in the 
same way

WeirdQ[n_Integer?Positive]:=DivisorSigma[1,n]>2n&&

            n!=Plus@@#&/@(And@@Rest[Subsets[Most[Divisors[n]]]])

Any ideas how these codes could be modified to return False (rather than 
{False}) for prime inputs

Thank you

Tony


  • Prev by Date: Re: Beginner's Question on I/O Files for Raw Numerical Data
  • Next by Date: Text Manipulation
  • Previous by thread: where's DrBob's web site now?
  • Next by thread: Re: Peculiar behaviour of Mathematica code