I have some expressions. For example:

 expr=f[x]^(7/3) + 2*f[x]^(2 + 2/(3*n)) + f[x]

where n is an integer.

I want to get the terms containing rational exponents to zero. For the example above; I want to reach f[x].

My try is

expr /. f[x]^Rational[_, _] -> 0


Assuming[expr /. f[x]^Rational[_, _] -> 0, n \[Element] Integers]

2 Answers 2

PossibleIntegerQ[a_, n] := 
  Resolve[Exists[n, Element[n, Integers], Element[a, Integers]]]

expr /. f[x]^a_. /; ! PossibleIntegerQ[a, n] -> 0
(*    f[x]    *)

The combination of Resolve and Exists determines for each term $f(x)^a$ whether there exists an integer $n$ that makes the exponent $a(n)$ integer-valued (i.e., whether or not $a$ is "possibly an integer"). If not, the term is set to zero.


Rational numbers are atomic (i.e., cannot be divided into subexpressions)


(* True *)

Consequently, rationals have no parts (although Numerator and Denominator act as if rationals had parts), and the pattern Rational[_, _] never occurs

expr = f[x]^(7/3) + 2*f[x]^(2 + 2/(3*n)) + f[x];

expr /. f[x]^(_?(! FreeQ[#, Rational] &)) :> 0

(* f[x] *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.