Movatterモバイル変換


[0]ホーム

URL:


homepage

Message344292

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Authortim.peters
RecipientsDavid Radcliffe, FR4NKESTI3N, josh.r, jwilk, kellerfuchs, mark.dickinson, pablogsal, rhettinger, serhiy.storchaka, steven.daprano, tim.peters
Date2019-06-02.15:19:39
SpamBayes Score-1.0
Marked as misclassifiedYes
Message-id<1559488779.31.0.84783706415.issue35431@roundup.psfhosted.org>
In-reply-to
Content
I'm not convinced, although I agree relaxing k <= n is less damaging than relaxing k >= 0.Python isn't aimed at mathematicians (although some 3rd-party packages certainly are, and they're free to define things however they like).  We have to trade off convenience for experts in edge cases against the likelihood that an ordinary user is making a mistake.For example, that's why, despite that Python supports complex numbers, math.sqrt(-1) raises ValueError.  For _most_ users, trying that was probably an error in their logic that led to the argument being negative.  Experts can use cmath.sqrt() instead.Ordinary users think comb(n, k) is the value of n!//(k!*(n-k)!), and as far as they're concerned factorial is only defined for non-negative integers.  0 <= k <= n follows from that.  (Indeed, the current docs for `comb()` _define_ the result via the factorial expression.)And ordinary users think of the sum of the first n integers as "number of terms times the average", or memorize directly that the answer is n*(n+1)/2.  That works fine for n=0.  Only an expert thinks of it as `comb(n+1, 2)`.So I would still rather enforce 0 <= k <= n at the start, and relax it later only if there's significant demand.  In going on three decades of using Python and having written my own `comb()` at least a dozen times, I've never found that constraint limiting, and enforcing it _has_ caught errors in my code.
History
DateUserActionArgs
2019-06-02 15:19:39tim.peterssetrecipients: +tim.peters,rhettinger,mark.dickinson,jwilk,steven.daprano,serhiy.storchaka,josh.r,pablogsal,kellerfuchs,FR4NKESTI3N,David Radcliffe
2019-06-02 15:19:39tim.peterssetmessageid: <1559488779.31.0.84783706415.issue35431@roundup.psfhosted.org>
2019-06-02 15:19:39tim.peterslinkissue35431 messages
2019-06-02 15:19:39tim.peterscreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp