Paul McGuire wrote: > Does Python's run-time do any optimization of multiplication > operations, like it does for boolean short-cutting? That is, for a > product a*b, is there any shortcutting of (potentially expensive) > multiplication operations
no. and the reason is very simple: to the extent such optimization makes sense, it has been done on assembler/CPU level already. i.e. when the multiplication is mapped to the machine code IMUL <op> the Pentium processor would be smart enough not to do the work if AX or the op are 0 or 1. Python has no job trying to outsmart Intel (and the other chipmakers). Boolean shortcuts are useful for entirely different reason, not speed. e.g. if lastDigit == 0 or i % lastDigit != 0: break if both operands of OR were to be evaluated, that would end up with division-by-zero exception for lastDigit=0. -- http://mail.python.org/mailman/listinfo/python-list