Consider the function

#q(x) = { (1, "if x = 0"), (1/q, "if x = p/q for integers p, q in lowest terms"), (0, "if x is irrational") :}#

Then #q(x)# is continuous at every irrational number and discontinuous at every rational number.

Let us show that #q(x)# is continuous at any irrational number #alpha# by showing that #lim_(x->alpha) q(x)# exists and is zero.

Let #alpha# be an irrational number and #epsilon > 0#

We need to show that:

#EE delta > 0 : AA x in (alpha-delta, alpha+delta), abs(q(x)-0) < epsilon#

Let #I = (alpha-1, alpha+1)# so #alpha in I#

Let #N = ceil(1/epsilon) + 1#, so #1/N < epsilon#.

Let #S = { p/q : p, q in ZZ, 1 <= q <= N, "hcf"(p, q) = 1 } nn I#

Then #S# is finite and for all #x in S# we have #abs(x - alpha) > 0# since #alpha# is irrational.

Note that if #x in I and x !in S# then #abs(q(x)) < 1/N#

Let #delta = min_(x in S) abs(x - alpha)#

Then since #S# is finite, #delta > 0#.

From our definition of #delta#, if #x in (alpha-delta, alpha+delta)#, then #x in I#, #x !in S# and #abs(q(x)) < 1/N#.

So #AA x in (alpha-delta, alpha+delta), abs(q(x) - 0) < 1/N < epsilon#