Path: csiph.com!feeder.erje.net!1.us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Mon, 23 May 2016 02:35:24 +1000 Lines: 59 Message-ID: References: <573EC62F.4090401@lucidity.plus.com> <573f9322$0$1616$c3e8da3$5496439d@news.astraweb.com> <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de r7gNUXU5m3pPIoo2i6LQHQlF4IZYDGP0U8CC1+6kOwKw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'binary': 0.05; 'float': 0.05; 'remind': 0.05; 'that?': 0.05; 'cc:addr:python-list': 0.09; 'abstraction': 0.09; 'subject:while': 0.09; 'underlying': 0.09; 'stored': 0.10; 'python': 0.10; 'received:74.125.82.44': 0.15; 'languages.': 0.15; '2016': 0.16; '23,': 0.16; 'argument.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gotcha.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'circular': 0.18; 'integer': 0.18; '>>>': 0.20; 'people,': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; '64-bit': 0.22; 'minor': 0.22; 'am,': 0.23; '(you': 0.23; 'nearly': 0.23; "python's": 0.23; 'split': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'defining': 0.27; 'skip:( 20': 0.28; '"no': 0.29; 'division': 0.29; 'pep': 0.29; 'types.': 0.29; 'themselves': 0.29; 'ourselves': 0.30; 'everyone': 0.31; "can't": 0.32; 'says': 0.32; 'returned': 0.32; 'point': 0.33; 'problem': 0.33; 'int': 0.33; 'case,': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'could': 0.35; 'necessary.': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'basic': 0.36; 'apple': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'there,': 0.37; 'requirement': 0.37; 'things': 0.38; 'someone': 0.38; 'represent': 0.38; 'data': 0.39; 'enough': 0.39; 'where': 0.40; 'called': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'real': 0.62; 'skip:n 10': 0.62; 'course': 0.62; 'subject: / ': 0.63; 'times': 0.63; 'between': 0.65; 'today': 0.65; 'here': 0.66; 'computers': 0.70; "'foo'": 0.84; 'childhood': 0.84; 'chrisa': 0.84; 'divide': 0.84; 'leak.': 0.84; 'proves': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84; 'treats': 0.84; 'to:none': 0.91; 'cutting': 0.93 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; bh=sUyW0GzCBObt6AHv0MZGWJk0MIWj95OVpmNFpWvPjos=; b=n6O+fzPq0cYTmNwz55n0hFf/i58MKO5g8IglE2+1a+DYoppUocCNvYs5MKct7kwMHf z7aswJtswK4VWW8Arpqkvl4q/XFSPUNuF8r5S1SAlnJ1udDGFniH8sUbfeCI7/51MBHh p0/MhKrMadVdn6xeX2SY0orQs1EQo42+E4s+h6rK2q/X3RN8nTGuuDFJh8DTZ7p01krg h9rdHZauowEblrNuu94zOYKqER74/phLy8YXWweLGHl2+m5Mkq84qLRECqPjlLtMswFp 9ksp2rw88hQX+OJX6f9avXkqTFdYBXyV365GQ6dRvm1TAx4MrEgWhBahZSBFT63Zmfd1 TBwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=sUyW0GzCBObt6AHv0MZGWJk0MIWj95OVpmNFpWvPjos=; b=TnIhR/cD20dOJ9GRY50QvcQPiaMU5S+9smX8w846o8lXgLYnTJQ9Oh6PywXEA5N57L rksNut5jFl+Q5AK8LKFflA1Bp/7IM8yrnJAI+iv9IahNUE7U//0f15YgOA6ytGhvEwBP FZGfVS/T5/uD1ksV9GHVpD6uRyz9eAZQFxsFXerRhTsgx3nV0LdLsSi6ar8ALsl5Kkbo SoB15zJqabguvUq3EvoRX6eaNHRMsfsfR8J7Xzy5KPo5l54gzkYTiRuZwIGAjyAb6Px1 KPk/IQjzGEIMqlyQxDB0KFoEW/Ott4aequQ1Celu6oLr76WG918ljzUKBBp9w6S8mY0/ B/Jg== X-Gm-Message-State: AOPr4FUTHZzNg/1fyUlHNRSJKDhlURVBUTYsKMw0hbB2qfuHWWIZ/4H7izQBMo40er8AHPuUGdH+RzGZz3y50g== X-Received: by 10.194.86.129 with SMTP id p1mr12231478wjz.117.1463934924321; Sun, 22 May 2016 09:35:24 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <573EC62F.4090401@lucidity.plus.com> <573f9322$0$1616$c3e8da3$5496439d@news.astraweb.com> <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:108948 On Mon, May 23, 2016 at 1:52 AM, Jon Ribbens wrote: > That's a circular argument. You're defining the result as the > requirement and then saying that proves the result is necessary. > Clearly, people managed when 1/2 returned 0, and continue to do so > today in Python 2 and other languages. > Python's int and float types are both approximations to a non-representable type called a "real number". You learned about numbers in your early childhood - you learned about the basic concepts like addition (you have one apple here and one apple there, so you have two apples), and division (you take those two apples and split them between four people by cutting them both in half). If you ask someone how much apple everyone gets when you divide one apple between two people, the answer should be "half an apple". Not "no apples" - of course there are situations where things are indivisible, but numbers themselves aren't, because there are times when you can indeed halve those apples just fine. The problem is that computers can't actually represent real numbers. We have to content ourselves with a variety of approximations, which we call numeric data types. Python then treats those data types as being a minor detail, and the underlying real number as important: >>> 1 == 1.0 == (1+0j) True >>> {1.0: "foo"}[1] 'foo' Now, there is the small problem that the numeric types can't be arranged into a perfect tower. If Python's integer were restricted to 2**32, you could automatically upcast any integer to a float losslessly, and you can already losslessly upcast a float to a complex simply by adding 0j to it. But most people don't work with numbers big enough to be unrepresentable in 64-bit IEEE floating point: >>> (1<<53)+1 9007199254740993 >>> (1<<53)+1 == (1<<53) False >>> (1<<53)+1.0 == (1<<53) True So for *most people*, this treatment works perfectly. An int will upcast to a float when you apply the division operator to it. An int or float will upcast to complex when you apply the exponentiation operator: >>> (-4)**0.5 (1.2246467991473532e-16+2j) Nearly everything stored in a computer is an abstraction that can leak. In this case, we can't perfectly represent real numbers or calculate with them, so we do the best we can. Binary floating point is far from perfect in purity, but it's not bad in practicality. Remind me what PEP 20 says about that? Gotcha. ChrisA