if by `F` you mean that the rational expression can be inside a function like `cos` then your match is going to fail. So I would guess you have to see if b is a Function (and thus match the arg of that function) or a Mul (and thus match the Mul itself).