Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*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 2006

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

Search the Archive

Re: Testing for squares

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66260] Re: Testing for squares
  • From: "Julian Aguirre" <julian.aguirre at ehu.es>
  • Date: Sat, 6 May 2006 01:54:31 -0400 (EDT)
  • References: <e3cimv$a3k$1@smc.vnet.net><e3f5kf$s8r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Ray,

Thank you for your message. However, most of the integers I need to
test are not machine size, and test2 reverts to the uncompiled code.

Julián

Ray Koopman wrote:

> In[1]:= test1 = IntegerQ[Sqrt[#]]&;
>         test2 = Compile[{{n,_Integer}},Round[Sqrt[N[n]]]^2 === n];
>         v = Range[123456];
>         Timing[a = test1/@v;]
>         Timing[b = test2/@v;]
>         a === b
>
> Out[4]= {3.49 Second,Null}
> Out[5]= {0.34 Second,Null}
> Out[6]= True
>
> Julian Aguirre wrote:
> > 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?
> >
> > Thanks for any help,
> > 
> > Julián Aguirre


  • Prev by Date: Re: Determining Linear dependent vectors
  • Next by Date: Re: Determining Linear dependent vectors
  • Previous by thread: Re: Testing for squares
  • Next by thread: Re: Selecting Many Things Rather Than Selecting One Thing FromMany