Does any function $f(x)$ exists? such that

$$ f(x) = \begin{cases} a , & \text{if $x$ is rational} \\ b , & \text{if $x$ is irrational} \end{cases} $$ where $a \neq b $

  • 2
    $\begingroup$ It is not very clear... you mean $a$ for irrational values of $x$ and $b$ for rational values of $x$? If this is so, yes, it does exist. You just define it that way... $\endgroup$
    – Martigan
    Oct 10, 2014 at 16:08

2 Answers 2


Your definition is practically the same as Dirichlet Function.

It is a function, and can be defined analytically as:

$D(x)=\lim\limits_{m \to \infty }\lim\limits_{n \to \infty}cos^{2n}(m!\pi x)$

Further reading: Dirichlet Function


Yes..except that you probably mean $f(x) = b$ for rational values of $x$. And your description defines the function.

There's no polynomial expression that has this property, but there are many ways to define a function, and polynomials aren't the only one.

You might try to find a good set theory book and read about how functions are really defined.

One formal definition is that a function is a triple, $f = (D, C, R)$, where $D$ is a set called the domain, $C$ is a set called the codomain, and $R$ is a subset of $D \times C$ having two properties:

  1. Every element $d$ of $D$ is the first element of some pair $(d, c) \in R$

  2. Every element $d$ of $D$ is the first element of exactly ONE pair in $R$; more formally, if $(d, c_1) \in R$ and $(d, c_2) \in R$, then $c_1 = c_2$.

In your case, the function can be described by $$ D = \mathbb R \\ C = \mathbb R \\ R = (\mathbb Q \times \{a\} ) \cup ((\mathbb R \setminus \mathbb Q) \times \{b\}) $$ where $\mathbb Q$ denotes the rationals, and $(\mathbb R \setminus \mathbb Q)$ denotes the irrationals.


You must log in to answer this question.