Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80078

Re: Challenge: optimizing isqrt

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.python
Subject Re: Challenge: optimizing isqrt
Date Sat, 01 Nov 2014 09:25:40 +0100
Organization A noiseless patient Spider
Lines 19
Message-ID <m325dt$lsl$1@dont-email.me> (permalink)
References <54543787$0$13005$c3e8da3$5496439d@news.astraweb.com> <m3241t$ihv$1@dont-email.me> <mailman.15379.1414830070.18130.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Sat, 1 Nov 2014 08:25:33 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="0ca390f552aaaca2fd2a25e51821864b"; logging-data="22421"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fYBpMnag4+GWxpoJrQcd9hvbEls4/gsk="
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <mailman.15379.1414830070.18130.python-list@python.org>
Cancel-Lock sha1:8b56VSDIZetxBMuSL6PFPXuaH4g=
Xref csiph.com comp.lang.python:80078

Show key headers only | View raw


Am 01.11.14 09:13, schrieb Chris Angelico:
> On Sat, Nov 1, 2014 at 7:02 PM, Christian Gollwitzer <auriocus@gmx.de> wrote:
>> Your above algorithm is obviously doing Heron- or Newton-Raphson iterations,
>> so the same as with floating point math. The first line before the while
>> loop computes some approximation to sqrt(n). Instead of doing bit shuffling,
>> you could compute this by FP math and get closer to the desired result,
>> unless the integer is too large to be represented by FP. Now, the
>> terminating condition seems to rely on the fact that the initial estimate
>> x>=sqrt(n), but I don't really understand it. My guess is that if you do
>> x=int(sqrt(n)), then do the first iteration, then swap x and y such that
>> x>y, then enter the loop, you would simply start with a better estimate in
>> case that the significant bits can be represented by the float.
>
> Part of the point of that algorithm is that it never uses FP, and is
> therefore not limited by FP restrictions.

which are???

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Challenge: optimizing isqrt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:29 +1100
  Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 13:12 +1100
  Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:02 +0100
    Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:09 +0100
    Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:13 +1100
      Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:25 +0100
        Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:33 +1100
          Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:38 +0100
            Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:45 +1100
  Re: Challenge: optimizing isqrt Akira Li <4kir4.1i@gmail.com> - 2014-11-01 12:12 +0300
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-20 20:00 +0200
  Re: Challenge: optimizing isqrt Stephen Tucker <stephen_tucker@sil.org> - 2014-11-21 08:15 +0000
  Re: Challenge: optimizing isqrt Dave Angel <davea@davea.name> - 2014-11-23 10:43 -0500
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-25 21:31 +0200
  Re: Challenge: optimizing isqrt Dave Angel <davea@davea.name> - 2014-11-25 19:46 -0500
  Re: Challenge: optimizing isqrt Stephen Tucker <stephen_tucker@sil.org> - 2014-11-26 07:57 +0000
    Re: Challenge: optimizing isqrt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-26 21:25 +1100
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-26 18:24 +0200

csiph-web