Let a1, a2, ..., am be he distinct real roots of P(q1,q2, ..., q(k-1),xk), in ascending order. Let a0 be minus infinity and a(m+1) be plus infinity. Let i be the unique index such that qk is in [ai,a(i+1)). The index of P in q is 2i if ai = qk, and 2i + 1 otherwise.