def subst(f,x,c):
if c==1:
return sum([t/x for t in f.terms() if t.reducibleBy(x)])+\
sum([t for t in f.terms() if not t.reducibleBy(x)])
else:
#c==0
return sum([t for t in f.terms() if not t.reducibleBy(x)])