Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'algorithm': 0.04; 'plenty': 0.07; 'calculating': 0.09; 'subject:set': 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'benjamin': 0.16; 'force.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iteration': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'basically': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'decimal': 0.31; 'subject:numbers': 0.31; 'quite': 0.32; 'becomes': 0.33; 'subject:the': 0.34; 'subject:with': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'anything': 0.39; 'simple': 0.61; 'first': 0.61; 'talking': 0.65; 'mar': 0.68; 'square': 0.74; 'oscar': 0.84; 'roots.': 0.84; 'reasoning': 0.91; '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=G9rtDAkCk78cmDhRorggCc1LOYaMBhtVA+jAR/4cVss=; b=D5t8Q1UCMi2RFcoY9/cvK+fBGhThp/o0/FxOHUaIuUDEI2oW9HX53WIaZxgH3b1yjW yUhBOLIeGNMeQTTxMR5guRXYs1D8ofJA0/hUP/Su76HxCiy6M7dqjLyDj21awaKgw21x XogiOk9KU1bDW1/VyJZ9w6uKBV3+qCO700TzwJzAg2438/NW3ajSx6ksiUaEpux7Dcs2 CBBhKCe8M+VocfmtHKsIOvn/fUNm25SQ4wWvL8CryDlOYyiKG5bCI4SEt3OP0rQAW2vW gqTiKuErZJERjt4YbDGOHS6Z8lJuCqtcrvBOwn1BjtPXpN2y9mXS/Oo/6paoDUpEzqPx 68Nw== MIME-Version: 1.0 X-Received: by 10.68.112.164 with SMTP id ir4mr1866646pbb.153.1393967910038; Tue, 04 Mar 2014 13:18:30 -0800 (PST) In-Reply-To: References: <8e4c1ab1-e65d-483f-ad9d-6933ae2052c3@googlegroups.com> <85r478bv99.fsf_-_@benfinney.id.au> <53153e66$0$24931$e4fe514c@dreader36.news.xs4all.nl> <59dd57ad-39b0-4c71-a58e-b4ae6517b385@googlegroups.com> <53156a42$0$2923$c3e8da3$76491128@news.astraweb.com> <87iortoic0.fsf@elektro.pacujo.net> Date: Wed, 5 Mar 2014 08:18:29 +1100 Subject: Re: Working with the set of real numbers 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393967919 news.xs4all.nl 2968 [2001:888:2000:d::a6]:55366 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67722 On Wed, Mar 5, 2014 at 7:55 AM, Oscar Benjamin wrote: > I don't quite follow your reasoning here. By "cut-and-try" do you mean > bisection? If so it gives the first N decimal digits in N*log2(10) > iterations. However each iteration requires a multiply and when the > number of digits N becomes large the multiplication is worse than > linear. So the result is something like N**2 log(N)log(log(N)), By "cut and try" I'm talking about the really REALLY simple algorithm for calculating square roots. It's basically brute force. epsilon = 0.0001 def sqrt(n): guess1, guess2 = 1, n while abs(guess1-guess2) > epsilon: guess1 = n/guess2 guess2 = (guess1 + guess2)/2 return guess1 It's generally going to take roughly O(n*n) time to generate n digits, give or take. That's the baseline against which anything else can be compared. There are plenty of better ways to calculate them. ChrisA