Re: Integer test for perfect square
- From: riderofgiraffes <mathforum.org_am@xxxxxxxxxxxxxx>
- Date: Thu, 12 Mar 2009 13:41:06 EDT
Is there an integer test for a perfect square?Henri Cohen's ... algorithm 1.7.3. ... check if
the number is a square modulo some small numbers
(11, 63, 64, 65 is suggested), then square the
integer square root.
I guess Cohen outlines a way to find the integer
square root without using floating point? Some
form of Newton's method?
Unlikely. There is an algorithm, resembling long
division, which rapidly finds the integer floor R
of the square root of any integer N, and the
remainder S, i.e. N = R^2 + S where 0 <= S <= 2R.
You can find a description of it at:
http://www.mathpath.org/Algor/squareroot/algor.square.root.why.htm
and on various other web sites.
The algorithm was taught in schools up until perhaps
1960, so only quite elderly people are familiar
enough with it to just do it on automatically on
paper. But it could be expected to be the method
of choice in a multiple-precision integer package.
I have implemented it several times, in different
languages. Newton's method would be much slower.
Are you sure? Have you tested that? Newton's method
doubles the nubmer of digits on each iteration, but
the "long-division" method that I know so well only
gives one extra digit per phase. My speed tests show
integer variants of Newton's Method to be far faster
for large numbers.
In short, my results disagree with your assertion, and
I would be interested to see how your evidence comapares
with my tests.
.
- Follow-Ups:
- Re: Integer test for perfect square
- From: bert
- Re: Integer test for perfect square
- From: Tim Smith
- Re: Integer test for perfect square
- References:
- Re: Integer test for perfect square
- From: bert
- Re: Integer test for perfect square
- Prev by Date: Re: Is a non-decreasing function necessarily continuous?
- Next by Date: Re: Is a non-decreasing function necessarily continuous?
- Previous by thread: Re: Integer test for perfect square
- Next by thread: Re: Integer test for perfect square
- Index(es):
Relevant Pages
|