Ask Your Question

# Revision history [back]

I am not sure how I should interpret your criterion: do you want to allow a variable to appear more than once in the same monomial? Supposing you do, and supposing p is your polynomial expression, here's a fancy solution

[m for m in p.iterator() if sum(m({x:0}).is_zero() for x in (i_L, d, v_g, v_C)) == 1]


There's certainly many other, but I am afraid none is going to be very simple. A word of explanation:

• The first for loops over each monomial.
• For each monomial m, m({x:0}) evaluates the monomial at the point x=0, where x ranges over i_L, d, etc.
• If is_zero() returns True, the variable is obviously in the monomial.
• In a summation, True and False get converted to 0 and 1, thus sum(...) == 1 guarantees that the monomial contains exactly one of the variables i_l, d, etc.

Thanks for this refreshing riddle :)