Why does 1**2**3**4**5 raise a MemoryError?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Apr 1 00:16:43 EDT 2013
On Mon, 01 Apr 2013 00:39:56 +0000, Alex wrote:
> Chris Angelico wrote:
>
>
>> Opening paragraph, "... exponentiation, which groups from right to
>> left". It follows the obvious expectation from mathematics. (The OP is
>> using Python 2, but the same applies.)
>
> Thanks. I did miss that parenthetical comment in para 6.15, and that
> would have been the correct place to look, since it appears that
> operators are not parts of expressions, but rather separate them. Is
> that the "obvious expectation from mathematics," though? Given that
>
> 3
> 5
> 4
>
> (i.e.: 4**5**3) is transitive, I would have expected Python to exhibit
> more consistency with the other operators. I guess that is one of the
> foolish consistencies that comprise the hobgoblins of my little mind,
> though.
I don't think you mean "transitive" here. Transitivity refers to
relations, not arbitrary operators. If ≎ is some relation, then it is
transitive if and only if:
x ≎ y and y ≎ z implies that x ≎ y.
http://en.wikipedia.org/wiki/Transitive_relation
Concrete examples of transitive relations: greater than, equal to, less
than and equal to.
On the other hand, "unequal to" is not a transitive relation. Nor is
"approximately equal to". Suppose we say that two values are
approximately equal if their difference is less than 0.5:
2.1 ≈ 2.4 and 2.4 ≈ 2.7
but 2.1 ≉ 2.7
Exponentiation is not commutative:
2**3 != 3**2
nor is it associative:
2**(3**2) != (2**3)**2
so I'm not really sure what you are trying to say here.
--
Steven
More information about the Python-list
mailing list