Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Peculiar behaviour of Mathematica code

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57929] Peculiar behaviour of Mathematica code
  • From: "Tony King" <mathstutoring at ntlworld.com>
  • Date: Mon, 13 Jun 2005 05:50:46 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

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