This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benrg
Recipients benrg, mark.dickinson, rhettinger, tim.peters
Date 2022-02-28.19:09:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646075385.81.0.168111910593.issue46868@roundup.psfhosted.org>
In-reply-to
Content
Anything that produces output of O(m+n) size in O(m+n) time. Ordered merging operations. Mergesort is a binary ordered merge with log-depth tree reduction, and insertion sort is the same binary operation with linear-depth tree reduction. Say you're merging sorted lists of intervals, and overlapping intervals need special treatment. It's easier to write a manifestly correct binary merge than an n-way merge, or a filter after heapq.merge that needs to deal with complex interval clusters. I've written that sort of code.

Any situation that resembles a fast path but doesn't qualify for the fast path. For example, there's an optimized factorial function in math, but you need double factorial. Or math.prod is optimized for ints as you suggested, but you have a class that uses ints internally but doesn't pass the CheckExact test. Usually when you miss out on a fast path, you just take a (sometimes large) constant-factor penalty, but here it pushes you into a different complexity class. Or you have a class that uses floats internally and wants to limit accumulated roundoff errors, but the struture of the computation doesn't fit fsum.

>Tree reduction is very popular in the parallel processing world, for obvious reasons.

It's the same reason in every case: the log depth limits the accumulation of some bad thing. In parallel computing it's critical-path length, in factorial and mergesort it's size, in fsum it's roundoff error. Log depth helps in a range of situations.

>I've searched in vain for other languages that try to address this "in general"

You've got me there.

>As Guido will tell you, the only original idea in Python is adding an "else" clause to loops ;-)

I don't think that's really true, except in the sense that there's nothing new under the sun. No one would use Python if it was just like other languages except slower and with for-else.
History
Date User Action Args
2022-02-28 19:09:45benrgsetrecipients: + benrg, tim.peters, rhettinger, mark.dickinson
2022-02-28 19:09:45benrgsetmessageid: <1646075385.81.0.168111910593.issue46868@roundup.psfhosted.org>
2022-02-28 19:09:45benrglinkissue46868 messages
2022-02-28 19:09:45benrgcreate