On Sat, Sep 18, 2021 at 03:50:00PM -0700, Christopher Barker wrote:
> Folks are not surprised by:
>
> >> 2 * 3 == [2] * 3
>
> False
>
> Because 2 is not only a different type than [2] but because they are
> different values as well.
What counts as a value? In some programming languages, 2.0 != 2 and I
can't say that they are wrong to make that decision.
Given:
a, = [2]
b, = (2,)
then clearly a==b. In that sense, we can say that the two sequences
have the same value. But:
[2] != (2,)
[2]*5 != (2,)*5
so in Python, the concept of "same value" does depend on type.
Numeric types are an exception, because they are automatically coerced
to a common type. And that's a mixed benefit. It means that we have to
deal with surprises like this:
>>> 1234567890123456789 == 1234567890123456789.0
False
Even more surprising:
>>> x = 1234567890123456789
>>> x == x + 0
True
>>> x == x + 0.0
False
I still think that there is little or no justification for having
factorial automatically delegate to gamma *in Python*, but there are
languages where it would work. In the right circumstances, it works
fine. It's not a dumb idea.
For instance, in Javascript, there is no int type, everything is a
float. So in Javascript, there is no question that factorial(65) will
unquestionably equal factorial(65.0), and that it would be perfectly
safe to have factorial take fractional values and compute the gamma
function.
Similarly for the various calculator languages used in advanced
programmable calculators, where it is the case that fractional arguments
to factorial return the gamma function.
(Possibly in symbolic form.)
--
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/CBNLAVUV52KCLS7JV2KVVCJKS5CUYQFW/
Code of Conduct: http://python.org/psf/codeofconduct/