the bugs that try men's souls

Serge Orlov Serge.Orlov at gmail.com
Sun Apr 3 05:32:50 EDT 2005


Sean McIlroy wrote:
> This needs some background so bear with me.
>
> The problem: Suppose p is a permutation on {0...n} and t is the
> transposition that switches x and y [x,y in {0...n}]. A "stepup pair"
> (just a term I invented) for p is a pair (a,b) of integers in {0...n}
> with a<b. A stepup pair (a,b) for p is an "inversion" (standard term)
> of p iff (p(a),p(b)) is NOT a stepup pair. Now, if {a,b}={x,y}, then
> clearly (a,b) is an inversion of p iff it is NOT an inversion of pt
> (functional composition). Also, if {a,b} and {x,y} are disjoint, then
> (a,b) is an inversion of p iff it is an inversion of pt. The remaining
> cases are the ones where {a,b} and {x,y} have a single element in
> common, and of these, there are exactly as many inversions of p as
> there are of pt, though in general it is not the same set of stepup
> pairs for each function.
>
> The code below represents my attempt to apply python toward getting
> insight into why the number of inversions, with exactly one coordinate
> in {x,y}, is the same for p and pt. The problem with the code is that
> if, at the relevant line ("MYSTERIOUSLY BROKEN"), I use the
> commented-out expression instead of the expression that's actually
> there, then in some cases the script gives a DIFFERENT ANSWER to the
> question whether a given pair is or is not an inversion of p
> respectively pt.

[snip the code]

Can you post a unit test that fails? Otherwise it's not clear what you mean
by saying "mysteriously broken" and "different answer".

  Serge.





More information about the Python-list mailing list