| If I read the paper correctly, then it compares three-way comparison with two two-way comparisons, for a recursively defined (tree) data type. The paper points out that the convenience of just defining "less than", and heaving "equals" derived from that can be costly. Specifically, for the recursively defined data structure (tree), a three-way comparison which is derived canonically from the two way compare seems to entail not a linear but an quadratic number of comparisons. What I don't understand is what is happening in 'lt2'. this is what I'd expect for __lt__ lt(a, b) also known as (a __lt__ b) is returning
True, iff a < b, elementwise for lists
False otherwise
for same length lists.
I also do understand cmp2. (a __eq__ b) iff not (a __lt__ b) and not (b __lt__ a)
so looking at cmp(a, b) = lt(a, b) - lt(b, a)
I get a < b: 1 - 0 ==> 1
b < a: 0 - 1 ==> -1
a == b: 0 - 0 ==> 0
which makes sense.Now two questions arise with respect to the presented hypothesis and the paper: 1. why does the paper call lt2 twice, recursively? 2. why does the paper compare the performance of their lt2 and lt3 instead of the performance of cmp2 and cmp3? I intuit, when taking the double recursion out of lt2, which imnsho is erroneous, and when comparing cmp2 and cmp3, we'll see a performance penalty of a factor 2, between cmp2 and cmp3, and identical run times for lt2 and lt3, as it should be. What am I missing? edit: updated for clarity |