Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: What exactly is "exact" (was Clean Singleton Docstrings) Date: Tue, 19 Jul 2016 15:27:24 +1000 Lines: 37 Message-ID: References: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de cxEJH/M5cd7rrChoig/U4Q4ScRFsnCNYu9q5BhwICEQw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'cc:addr :python-list': 0.09; '(use': 0.09; 'yeah,': 0.09; 'def': 0.13; 'value.': 0.15; '2016': 0.16; 'cares': 0.16; 'failure?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'measurement': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sorts': 0.16; 'subject:Singleton': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'absolute': 0.23; 'accuracy': 0.23; 'header:In-Reply-To:1': 0.24; 'earlier': 0.27; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'equality': 0.29; 'really,': 0.29; 'code': 0.30; 'relative': 0.30; 'maybe': 0.33; 'adjust': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'problem.': 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'smaller': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'mean': 0.38; 'means': 0.39; 'some': 0.40; 'ever': 0.60; 'your': 0.60; 'real': 0.62; 'jul': 0.72; 'chrisa': 0.84; 'systematic,': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=wJpCh6E7dRiD8XbJWKXRd1028eJJrUtMVDMQK2fxvzg=; b=AuJZRj2WRFmy/4KE1heReOoCPV+iq7mmU3bLElKZDzf+QRJ+bL5fLBBJ8vrHi4LQNQ PLKVgijlwIaT3fohjQF8aqpd3r1Rl8CaLVyU8zaMuL8So5UTawju6T83PQkKN7+l3tlP 56hNU7GtyqPsaUF7ukAkhLkrsb1RyUy6EM8CQJ3776uDV20tnd21X5fCSeeq1/C55qyh UELccC6p0sGTGZrD9TY0cqrWd7P5XcqcAjbV9p+U4m4e0OL/FefMSOpEJ5z3RajMSkkt 3RCDcgo08+UBQUApIZwf0ClYa1UTGc1b+UCj/3P4lUckQJpTXigEbsKo4HOYLaUUPkYU G6xw== 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:from:date :message-id:subject:cc; bh=wJpCh6E7dRiD8XbJWKXRd1028eJJrUtMVDMQK2fxvzg=; b=FungnWn7/Sl8KOsiFBuNG5trHWbXjYWIFDp+gROkysX6EIzGJ0iRyHRwEPCBOvy0DU 3elX5HA8oSPqFm2+/vnQyYRrZJnuJyxQcaQiqpGyh5dW6g+y4igrexDcVOswtk1ra3pJ wydavdEzOUppmKUWJKD4uVppawqTFdZrbNKUdRQ+iLUEPhIHuxm8Z0Z7OaG9Y0wtGbi4 BlP24tZAAJqCkixF4paEJGipNw798aRPFfZSwEs+hnrdq6dVDJP6J+QI8Xjx59kGmHeF ApLrxtNpnXiMJBHZPwW5hTs93d9Dh3qoGFqf/6ZkRgQ4q7YnU+62lw3XB+PO/RKCTGY1 Xo1g== X-Gm-Message-State: ALyK8tKZZYI2lB4Njz3Hsq+IFY0zxAEgvjUg20szYYhYCWeuGwCne+Ai0gPw9QzHrBkh4Z5qY5abZqYc3Ix8rg== X-Received: by 10.28.50.199 with SMTP id y190mr1511841wmy.61.1468906045843; Mon, 18 Jul 2016 22:27:25 -0700 (PDT) In-Reply-To: <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> 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: <7046c74e-e5ea-4dde-8847-8c556756a563@googlegroups.com> <5789B601.9000604@stoneleaf.us> <9d2a0934-bf26-42a8-9bb2-e4e75b2d2ad3@googlegroups.com> <1468652038.1427719.667878897.460955C0@webmail.messagingengine.com> <578a027c$0$1616$c3e8da3$5496439d@news.astraweb.com> <69d8d886-c18a-4c05-8bca-9a05afacd9a9@googlegroups.com> <578ca188$0$1505$c3e8da3$5496439d@news.astraweb.com> <877fcjcllf.fsf@elektro.pacujo.net> <578da1b5$0$1591$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:111628 On Tue, Jul 19, 2016 at 1:42 PM, Steven D'Aprano wrote: >> And then you get these sorts of functions: >> >> EPSILON = 0.000001 # Adjust to control numeric accuracy >> def is_equal(f1, f2, epsilon=EPSILON): >> if abs(f1) > abs(f2): >> f1, f2 = f2, f1 >> return abs(f2-f1) < f1*epsilon >> >> and interminable debates about how to pick an epsilon, whether it >> should be relative to the smaller value (as here) or the larger (use >> f2 instead), or maybe should be an absolute value, or maybe it should >> be relative to the largest/smallest value that was ever involved in >> the calculation, or........ > > Your code is buggy. Consider: > > py> is_equal(-1.0, -1.0) > False Duh, I got the < and <= bug! Shows how easy it is to get this kind of function wrong. (Even more so, it shows how easy it is to get code wrong when you type straight into an email and never test it.) > Earlier you mentioned "interminable debates > about how to pick an epsilon", but the reason for that is that it is > really, really hard to pick an epsilon in any systematic, objective way. Yeah, and that's the problem. If you're working with some concept of measurement error, what you actually mean is that every number in your calculation is actually a range centered on that number; which means that "equality" really means "overlapping ranges". Epsilon-based equality is just that, only with a global epsilon instead of one that actually cares about the real error value. How can that NOT be doomed to failure? ChrisA