Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.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.104 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; '(of': 0.07; 'seemed': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'assume': 0.14; 'arbitrary.': 0.16; 'multiplied': 0.16; 'nonempty': 0.16; 'wrote:': 0.18; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'regardless': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; '???': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:numbers': 0.31; 'subject:other': 0.31; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'too': 0.37; 'list': 0.37; 'clear': 0.37; 'list,': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'itself': 0.39; 'how': 0.40; 'even': 0.60; 'liked': 0.60; 'full': 0.61; 'course': 0.61; 'times': 0.62; 'kind': 0.63; 'choose': 0.64; 'our': 0.64; 'therefore,': 0.64; 'products,': 0.74; '2015': 0.84; 'explanation:': 0.84; 'no:': 0.84; 'factors': 0.97 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:to :cc:content-type; bh=Xo+8+V94v6MW0/JbiNKcR/9+WEfE9oNg+lGt6mv/g/c=; b=euqIPGZxYof+r81GRcJfn84Gg59SK6OEgtRWaJ+BQ/wARc0eGYwyqc49CLPL6pvqGK J0+CxUWGmBjY0vs4MaLKq/rGH1M8Ygk93bAxY1WZKCo27Dt0Eri6V3Vuk9IDgACWzxyf R4iBRgj003P5Qi4U2hZFEddPB4fcp4CgI4XPsioeDiDS8sy1VdCtybHViTFHJEidPhIY HD27i8J1hl0RIqz09u5TfbOh+HQ8uc7Fzk5sUM9TL7bile8nmIEixkyFFuh3ahjdzhLy 9lSpK8pO3797dLQRMyPnRSt7zEj/udpt49oI+jWdDJByfLZhfVC4FnzeyOc4EHjzreDP QMRw== X-Received: by 10.224.131.70 with SMTP id w6mr23893643qas.78.1420862281650; Fri, 09 Jan 2015 19:58:01 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <54AF405C.6020609@davea.name> <54af9612$0$12995$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Fri, 9 Jan 2015 19:57:20 -0800 Subject: Re: Decimals and other numbers To: Gregory Ewing Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420862283 news.xs4all.nl 2894 [2001:888:2000:d::a6]:57853 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83490 On Fri, Jan 9, 2015 at 7:05 PM, Gregory Ewing wrote: > It's far from clear what *anything* multiplied by > itself zero times should be. > > A better way of thinking about what x**n for integer > n means is this: Start with 1, and multiply it by > x n times. The result of this is clearly 1 when n > is 0, regardless of the value of x. > >> 5**4 = 5*5*5*5 = 625 > > No: > > 5**4 = 1*5*5*5*5 > 5**3 = 1*5*5*5 > 5**2 = 1*5*5 > 5**1 = 1*5 > 5**0 = 1 I never liked that, it seemed too arbitrary. How about this explanation: Assume that we know how to multiply a nonempty list numbers. so product([a]) == a, product([a, b]) = a * b, and so on. def product(nums): if len(nums) == 0: return ??? return reduce(operator.mul, nums) It should be the case that given a list of factors A and B, product(A + B) == product(A) * product(B) (associativity). We should let this rule apply even if A or B is the empty list, otherwise our rules are kind of stupid. Therefore, product([] + X) == product([]) * product(X) But since [] + X == X, product([] + X) == product(X) There's only one number like that: product([]) == 1 (Of course if you choose not to have the full associativity rule for empty products, then anything is possible.) -- Devin