Clarity vs. code reuse/generality
Sat Jul 4 20:20:20 CEST 2009
kj <no.email at please.post> writes:
> sense = cmp(func(hi), func(lo))
> assert sense != 0, "func is not strictly monotonic in [lo, hi]"
bisection search usually just requires the function to be continuous
and to have its value cross the target somewhere between the endpoints,
not be monotonic.
> I regard the very special case of func(hi)==func(lo)==target as
> pathological (analogous to the fact that a stopped watch is "exactly
> right" twice a day), and not one I care to support.
I do think you should support that case, under the "do 'nothing'
gracefully" principle. Having your equation solver crash if the
equation is already solved is like having your sorting function crash
if the input is already sorted. E.g. the function should do something
reasonable if you end up calling it twice.
More information about the Python-list