def plexp_inv(P,xm,a):
C = <NUM_LIT:1>/(-xm/(<NUM_LIT:1> - a) - xm/a + math.exp(a)*xm/a)<EOL>Pxm = <NUM_LIT:1>+C*(xm/(<NUM_LIT:1>-a))<EOL>pp = P<EOL>x = xm*(pp-<NUM_LIT:1>)*(<NUM_LIT:1>-a)/(C*xm)**(<NUM_LIT:1>/(<NUM_LIT:1>-a)) if pp >= Pxm else (math.log( ((C*xm/a)*math.exp(a)-pp)/(C*xm/a)) - a) * (-xm/a)<EOL>return x<EOL>
Inverse CDF for a piecewise PDF as defined in eqn. 3.10
of Clauset et al.