comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Fun with Unbounded Rational Numbers
Date: Mon, 10 Apr 2017 19:18:08 +0200
Date: 2017-04-10T19:18:08+02:00	[thread overview]
Message-ID: <ocgeio$j21$1@dont-email.me> (raw)
In-Reply-To: <oce1qh$let$1@z-news.wcss.wroc.pl>

On 04/09/2017 09:25 PM, antispam@math.uni.wroc.pl wrote:
> Jeffrey R. Carter <spam.jrcarter.not@spam.not.acm.org> wrote:
>> On 04/09/2017 02:30 AM, antispam@math.uni.wroc.pl wrote:
>>>
>>> newton(y : Fraction(Integer), eps : Fraction(Integer)) : Fraction(Integer) ==
>>>     x : Fraction(Integer) := 1
>>>     while abs(y - x^2) >= eps repeat
>>>         x := (x + y/x)/2
>>>     x
>>
>> Maybe I'm missing something, but this doesn't look like Newton's method to me.
>>
>
> We are sloving equation f(x) - y = 0 where f(x) = x^2.  Newton says:
>
> x_{n+1} = x_{n} - (f(x_n) - y)/f'(x_n)
>
> we have
>
> f'(x) = 2x
>
> so
>
> x_{n+1} = x_{n} - (x_n^2 - y)/(2*(x_n)) =
>           x_{n} - x_n^2/(2*(x_n)) + y/(2*(x_n)) =
>           x_{n} - x_n/2 + y/(2*(x_n)) =
>           x_{n}/2 + y/(2*(x_n)) = (x_{n} + y/x_n)/2
>
> So indeed given the same initial approximation the formula produces
> exactly the same sequence of numbers as direct use of Newton formula,
> but is slightly cheaper to compute.

As I learned it, Newton's method is to iteratively improve an estimate of the 
(positive) root of

Y = X**2 - R

At each step, the next estimate is the root of the line through (X, Y) with slope

M = Y' = 2 * X

which works out to

X - Y/M

Substituting in the definitions of Y and M, it's easy to show this is the same 
as your version. I guess I'd never seen it simplified further.

As to being cheaper to calculate, is that true? For rational math, division is 
multiplication and subtraction is addition, so both have 2 multiplications and 
an addition.

-- 
Jeff Carter
"I didn't squawk about the steak, dear. I
merely said I didn't see that old horse
that used to be tethered outside here."
Never Give a Sucker an Even Break
103

  reply	other threads:[~2017-04-10 17:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 10:37 Fun with Unbounded Rational Numbers Jeffrey R. Carter
2017-04-08 11:19 ` Dmitry A. Kazakov
2017-04-08 14:14 ` Robert Eachus
2017-04-09  0:30 ` antispam
2017-04-09  8:47   ` Jeffrey R. Carter
2017-04-09 19:25     ` antispam
2017-04-10 17:18       ` Jeffrey R. Carter [this message]
2017-04-11 21:39         ` antispam
2017-04-09  7:15 ` Paul Rubin
2017-04-09  8:56   ` Jeffrey R. Carter
2017-04-09 21:18     ` Paul Rubin
2017-04-10 17:08       ` Jeffrey R. Carter
2017-04-10 19:39         ` Paul Rubin
2017-04-09 10:05   ` Jeffrey R. Carter
replies disabled

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