I have a rather big expression which contains many sums of form q x + w y
. I know that y
is much smaller than x
and i want to omit it where possible, namely if both q
and w
are integers. So i apply the replacement rule
q_?IntegerQ x + w_?IntegerQ y -> q x
However this rule obviously doesn't work if either q
or w
(or both) is equal to unity because FullForm
of q x
contains Times
and one of x
doesn't. So to get replacement done i need to use the ugly set of rules
{ q_?IntegerQ x + w_?IntegerQ y -> q x , x + w_?IntegerQ y -> x , ... }
and in place of dots there are two more rules with w
and both w
and q
omitted.
So the question is whether it is possible (in general) to somehow simplify this ugly set to anything more simple.
q_. x + w_. y /; IntegerQ /@ And[q, w]
? $\endgroup$And @@ IntegerQ /@ {q, w}
, otherwiseq=w=True
would match) $\endgroup$