Is there any case you want to catch here other than Mul? It may be better to just do gcd.is_Pow and gcd.is_Mul cases explicitly rather than (not .is_Add and .is_Pow) and (not .is_Add and not .is_Pow).