It's not really clear from what you've written what the problem is since `expr.as_leading_term(x,y) == expr.expand().as_leading_term(x,y)` so I don't see the need for expand.