MathGroup Archive 2006

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

Search the Archive

Testing for squares

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66216] Testing for squares
  • From: "Julian Aguirre" <julian.aguirre at ehu.es>
  • Date: Thu, 4 May 2006 05:20:56 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi all,

1) I would like to have an efficient test to decide if an integer is a
square.

test1 = IntegerQ[Sqrt[#]]&

is too slow for my needs. I am using something like

test2 = Positive[#] && JacobiSymbol[#, p] && Sqrt[Round[N[#,
precission]]]^2==# &

where p is a prime (or I may use several primes). However test2 may
return False for very large integers. How large depends on the value of
precission. Do you know of a faster test?

2) Let MyList be a large list of integers (somewhere between 20.000 and
50.000 elements) and MyTest a function on the integers returning True
or False (for instance, test2 above). What is an efficient way of
deciding if there is an element in MyList for which MyTest is True?
Right now I use

Select[MyList, MyTest, 1] != {}

but may be some of you can provide a better way.

Thanks for any help,

Julián Aguirre


  • Prev by Date: NMinimize with numerically evaluated constraints
  • Next by Date: Re: "In progress" saving of data collected using Reap/Sow
  • Previous by thread: Re: NMinimize with numerically evaluated constraints
  • Next by thread: Re: Testing for squares