comp.lang.ada
 help / color / mirror / Atom feed
From: "Howard W. LUDWIG" <howard.w.ludwig@lmco.com>
To: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Calculating SQRT in ADA
Date: 1999/03/26
Date: 1999-03-26T00:00:00+00:00	[thread overview]
Message-ID: <36FBAFF6.6C6648CC@lmco.com> (raw)
In-Reply-To: gGUJY5yd#GA.202@pet.hiwaay.net

David C. Hoos, Sr. wrote:

> Mark A Biggar wrote in message <36FAA3DF.42C31CF@lmco.com>...
> >Hans Marqvardsen wrote:
> >>
> >> John Herro wrote:
> >
> >No,no,no,no!
> >
> >This algorithm has quadratic convergence.  This means that each time
> through the
> >loop doubles the number of correct bits in the answer.  So with IEEE double
> >precession float you need loop at most 6 times, and even with extended
> float
> >7 times, so don't test against a torerance at all, just loop 6 or 7 times
> >and be done with it.
> >
> No,no,no,no! (to coin a phrase)
>
> The number of correct bits doubles with every iteration, only if you are
> counting place holding bits as well as mantissa bits.  So,
> if you take the square root of 2.0e100, for example, 173 iterations are
> required if the argument is used as the initial estimate.
>
> similar number is required for 0.5e-100, but only six iterations are
> required for 2.0e00 or 0.5e00.

No, no, no, no! (to plagiarize a coined phrase)

It is a common oversimplified assumption that Newton[-Raphson] has quadratic
convergence.  There are many well-known cases where the method does not converge
at all.  Even when the method does converge, the convergence can be linear.
Quadratic convergence applies when the quadratic term is negligible compared to
the linear term in the Taylor series expansion of the function in question.
When the initial guess is far off, "negligible" does not describe the situation.

To find the actual  a = sqrt(c), where c is known, involves calculating
    x(n+1) = 0.5 * (x(n) + c/x(n)).
Let x(n) = a + d(n), where d(n) measures the deviation of the estimate x(n) from
the actual value a.  Then
    d(n+1) = x(n+1) - a
           = 0.5 * (a + d(n) + a**2/(a + d(n))) - a
           = 0.5 * d(n)**2/(a + d(n)).
When d(n) is small compared to a, the denominator behaves more and more like a,
so the deviation is indeed proportional to d(n)**2.  However, when d(n) is large
compared to a, the denominator for some iterations looks more like d(n),
canceling out one of the d(n) factors in the numerator, so the deviation is cut
each time by a factor of 2, thus linear convergence, until the iterations get to
the place of having the deviation be of the order of a, at which time the
convergence transitions to quadratic.

In the case of the example given [c = 2E100, a =1.4142...E50], starting with an
initial guess of c requires 166 iterations of halving the deviation each time to
get to the point of the deviation being smaller than the actual root a.  Then
quadratic convergence kicks in, apparently requiring only another 7 iterations
to achieve the ultimate desired result. If we simply counted place-holder bits,
roughly 167, plus the desired 53 bits of precision, then we have about 220 bits
to deal with.  _Assuming_ the first bit to be fine and doubling the number of
good bits each iteration, only 8 iterations would be needed (2^8 = 256), nowhere
close to the 173 iterations quoted above.  This shows that you cannot assume
that the first bit is good.  If you want to do a "back of the envelope"
calculation based on quadratic convergence, the 2E100 case using 2E100 as the
initial guess would say your first guess has less than 1E-50 bit good, in order
to double the number of good bits each iteration and to obtain 53 good bits
after 173 iterations.  A better way of looking at it is that the place-holder
bits are lopped off at the rate of one per iteration for the first 166
iterations.

HWL





  reply	other threads:[~1999-03-26  0:00 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-24  0:00 Calculating SQRT in ADA cmcrae
1999-03-23  0:00 ` Chris Morgan
1999-03-24  0:00   ` Marin David Condic
     [not found]   ` <36F913E0.75F51763@lmco.com>
1999-03-24  0:00     ` Ada 83 - Sometimes still chosen Richard D Riehle
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` Richard D Riehle
1999-03-25  0:00           ` Larry Kilgallen
1999-03-26  0:00           ` robert_dewar
1999-03-26  0:00             ` Richard D Riehle
1999-03-26  0:00               ` Tom Moran
1999-03-26  0:00                 ` Larry Kilgallen
1999-03-29  0:00                 ` Marin David Condic
1999-03-29  0:00                   ` Tarjei Tj�stheim Jensen
1999-03-27  0:00               ` Matthew Heaney
1999-03-26  0:00             ` Tom Moran
1999-03-26  0:00             ` Tarjei Tj�stheim Jensen
1999-03-27  0:00               ` robert_dewar
1999-03-27  0:00                 ` Tarjei Tj�stheim Jensen
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` Richard D Riehle
1999-03-25  0:00           ` Marin David Condic
1999-03-26  0:00           ` robert_dewar
1999-03-24  0:00     ` Calculating SQRT in ADA John Herro
1999-03-24  0:00       ` Hans Marqvardsen
     [not found]         ` <36FAA3DF.42C31CF@lmco.com>
1999-03-26  0:00           ` Tom Moran
1999-03-25  0:00       ` robert_dewar
1999-03-25  0:00         ` John Herro
1999-03-24  0:00           ` Hans Marqvardsen
1999-03-25  0:00             ` David C. Hoos, Sr.
1999-03-25  0:00           ` robert_dewar
1999-03-25  0:00             ` David C. Hoos, Sr.
1999-03-26  0:00               ` Howard W. LUDWIG [this message]
1999-03-26  0:00             ` Ole-Hjalmar Kristensen
1999-03-27  0:00               ` robert_dewar
1999-03-29  0:00                 ` Robert I. Eachus
1999-03-30  0:00                   ` robert_dewar
1999-04-02  0:00                     ` Robert I. Eachus
1999-03-30  0:00                   ` robert_dewar
1999-04-02  0:00                     ` Robert I. Eachus
1999-04-03  0:00                       ` robert_dewar
1999-03-25  0:00           ` robert_dewar
1999-03-26  0:00             ` Calculating SQRT in Ada John Herro
1999-03-26  0:00               ` David C. Hoos, Sr.
1999-03-26  0:00                 ` John Herro
1999-03-25  0:00       ` Calculating SQRT in ADA robert_dewar
1999-03-25  0:00     ` robert_dewar
1999-03-24  0:00       ` Howard W. LUDWIG
1999-03-25  0:00         ` Larry Kilgallen
1999-03-24  0:00 ` bob
1999-03-24  0:00   ` Niklas Holsti
1999-03-26  0:00     ` als0045
1999-03-26  0:00       ` als0045
1999-03-26  0:00     ` bob
1999-03-26  0:00 ` Marin David Condic
1999-03-26  0:00   ` David C. Hoos, Sr.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox