Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'algorithm': 0.04; 'slow.': 0.09; 'cc:addr:python-list': 0.11; '*other*': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inability': 0.16; 'integer.': 0.16; 'left,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'proposed': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'fine': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'shown': 0.26; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'message- id:@mail.gmail.com': 0.30; 'getting': 0.31; '>>>>': 0.31; 'comparison': 0.31; 'division': 0.31; 'steven': 0.31; 'trouble': 0.34; 'possible.': 0.35; 'beyond': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'done': 0.36; 'should': 0.36; 'positive': 0.37; 'christian': 0.38; 'represent': 0.38; 'e.g.': 0.38; 'nov': 0.38; 'pm,': 0.38; 'short': 0.38; 'though,': 0.39; 'enough': 0.39; 'how': 0.40; 'most': 0.60; 'first': 0.61; 'details': 0.65; 'between': 0.67; 'improvements': 0.68; 'therefore': 0.72; '09:33,': 0.84; '7:25': 0.84; 'notably,': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=4X4DLMmMws8tOQ3FnhcIBI+V1mxnSyk8Jo5zRnENiqk=; b=KsSMh9Xwhm3AqYBVOsXlH752+k5auErbqi/VPzxawrpF4ed2E3crfzg76/FmZvRGu7 fY/a71Al83sRxCXA77rAVna56WUA53mVkx8l6NLHkY9Ls3kgj8snDFLi098FjlZFbWo8 DilPujTpogQdT3t/cJr63/4moKInuLycXAkih4I/L2zSw3lj3T8LTY/CGHEeyI706N/d 82jU0yf69Q8xtYe6LfC66vQV95mt5td8MfKZJpiKWSS7jl8YKTPecwdNQdlqLunjxX1c xaOrxggKyrkki4jiboM0UCuJLeNvEufe/GhRIQUpmI7YIT4oCsV6Grnm/3VS9q7IrZ3N 4IiQ== MIME-Version: 1.0 X-Received: by 10.42.237.211 with SMTP id kp19mr370851icb.70.1414831545552; Sat, 01 Nov 2014 01:45:45 -0700 (PDT) In-Reply-To: References: <54543787$0$13005$c3e8da3$5496439d@news.astraweb.com> Date: Sat, 1 Nov 2014 19:45:45 +1100 Subject: Re: Challenge: optimizing isqrt From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414831554 news.xs4all.nl 2941 [2001:888:2000:d::a6]:41325 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80081 On Sat, Nov 1, 2014 at 7:38 PM, Christian Gollwitzer wrote: > Am 01.11.14 09:33, schrieb Chris Angelico: >> >> On Sat, Nov 1, 2014 at 7:25 PM, Christian Gollwitzer >> wrote: >>>> >>>> Part of the point of that algorithm is that it never uses FP, and is >>>> therefore not limited by FP restrictions. >>> >>> >>> >>> which are??? >> >> >> Most notably, the inability to represent every integer beyond 2**53, >> and the inability to represent any integer beyond 2**1024. This >> algorithm should work fine with any positive integer. >> > OK so you did not bother to look at my proposed alternative implementation. > If I understood Steven correctly, he wanted to speed up the original isqrt > algorithm by using FP when this is possible. I have shown how to do it for > n<2**1022 (maybe 2**1024, I'm to lean to check it). I admit that there is > some microoptimizatio left, e.g. the first division is done twice, the > comparison should be bits>1022, not n>2*1022 etc. I did look at it. Trouble is, I don't know floating point's details well enough to prove that there are no *other* limitations. FWIW, I've proven the algorithm as far as 2**38. That's still a long way short of 2**53, though, and getting as far as 2**39 would, with my brute-force checker, require between 2.5 and 5 hours. I've made some improvements over the original, but it's still slow. ChrisA