# Method to determine a set contains rational whose denominator is 2

Suppose S is a set of (complex) numbers.

I want to know whether S contains rational whose denominator is 2.

For example,

when S={1,2,3,4,1/4}, return "False".

when S={1,2,3,1/4,-5/2}, return "True" (because of -5/2).

when S={1/3,1/4,1/5,2/7,Sqrt[2]/2,i/2}, return "False" (since both sqrt(2)/2 and i/2 are not rational).

when S={Sqrt[9/4],2/3}, return "True". (because Sqrt[9/4]=3/2).

Please give me any hint or any code.

Thank you!

• AnyTrue[S, # \[Element] Rationals && Denominator[#] == 2 &] Jul 2 '20 at 6:55
• Thank you, It works very well! Jul 2 '20 at 7:18

Try this:

MemberQ[S,Rational[n_Integer,2]]


For example, if

S1 = {1, 2, 3, 4, 1/4};
MemberQ[S1,Rational[n_Integer,2]]

(*  False  *)


while if

S2 = {1, 2, 3, 1/4, -5/2};
MemberQ[S2,Rational[n_Integer,2]]

(*  True  *)


Have fun!