comp.lang.ada
 help / color / mirror / Atom feed
From: "frikk" <frikker@gmail.com>
Subject: Re: Unsigned Integer Restraint Errors
Date: 16 Mar 2007 06:38:44 -0700
Date: 2007-03-16T06:38:44-07:00	[thread overview]
Message-ID: <1174052324.689881.20710@e1g2000hsg.googlegroups.com> (raw)
In-Reply-To: <10l92gksnkfjl$.1rhbr6sokrtjy.dlg@40tude.net>

On Mar 13, 1:23 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> On 13 Mar 2007 09:04:14 -0700, Adam Beneschan wrote:
>
> > on the theory that using Sqrt is just a waste of cycles when you can
> > just use integer arithmetic.  But I've been programming for way too
> > long---long enough that I remember what a Hollerith card is
>
> ... and what was the Hollerith format of strings? (:-))
>
> >---and I'm
> > sure that doing a square-root doesn't take nearly as long as it used
> > to, so there are probably some reasonable values of N for which
> > computing the square-root first makes things more efficient than the
> > repeated integer multiplications.  I don't know.  Use Sqrt if you want
> > to.
>
> (for very large number like in infinite arithmetic it could become an
> issue)
>
> BTW, the arithmetic complexity can be further "reduced" by removing
> multiplication and computing k**2 using binomial decomposition
> (k+1)*(k+1)=k*k+2*k+1. So it could be:
>
> quadratic := 1; -- k*k, k=1
> linear := 2; -- 2*k+1, k=1
>
> loop
>    linear := linear + 2; -- 2*k+1
>    quadratic := quadratic + linear; -- k*k
>    exit when k>=n;
>    ...
> end loop;
>
> Whether this really would be any faster than multiplication or square root
> computed once, God knows...
>
> --
> Regards,
> Dmitry A. Kazakovhttp://www.dmitry-kazakov.de

That's very cool. I've had the opportunity to work with algorithms
like that.  You guys have definitely made me think about what it takes
to break down an algorithm into more simple parts.

Thanks!
Blaine




  parent reply	other threads:[~2007-03-16 13:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-12 15:07 Unsigned Integer Restraint Errors frikk
2007-03-12 16:27 ` Georg Bauhaus
2007-03-12 17:17 ` Adam Beneschan
2007-03-12 17:23 ` Adam Beneschan
2007-03-12 18:11   ` frikk
2007-03-12 20:00     ` frikk
2007-03-12 20:07       ` Adam Beneschan
2007-03-12 18:00 ` Dmitry A. Kazakov
2007-03-12 19:00   ` Martin Krischik
2007-03-12 21:13     ` Dmitry A. Kazakov
2007-03-12 19:13   ` frikk
2007-03-12 19:22     ` Randy Brukardt
2007-03-13  3:13       ` Jeffrey R. Carter
2007-03-13  3:00         ` Randy Brukardt
2007-03-13 12:09           ` frikk
2007-03-13 14:58             ` frikk
2007-03-13 15:31               ` frikk
2007-03-13 15:59                 ` Robert A Duff
2007-03-13 16:18                 ` Dmitry A. Kazakov
2007-03-13 16:21                 ` Jeffrey R. Carter
2007-03-13 16:04               ` Adam Beneschan
2007-03-13 16:41                 ` Adam Beneschan
2007-03-13 16:42                   ` Adam Beneschan
2007-03-14 14:06                     ` frikk
2007-03-13 17:23                 ` Dmitry A. Kazakov
2007-03-13 17:31                   ` Adam Beneschan
2007-03-14  0:54                   ` Jeffrey R. Carter
2007-03-16 13:38                   ` frikk [this message]
2007-03-13 16:16           ` Jeffrey R. Carter
2007-03-12 21:04     ` Dmitry A. Kazakov
replies disabled

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