5

Is there a simple function $f(x)$ that follows $2$ rules when $x$ is rational?

$x$'s simplest form is $\frac{a}{b}$ if $x$ is a rational number.

$$f(x) \in \begin{cases} \mathbb{R} \setminus \mathbb{Q}, \ \ \ \ x=\frac{a}{b} \text{ and } a + b = \text{even} \\ \mathbb{Q}, \ \ \ \ \ \ \ \ \ \ \ x \not\in \mathbb{Q} \text{ and } a + b = \text{odd} \end{cases}$$

for $x$ being irrational it doesn't need to follow any specific rule besides being continuous.

and for $x=0$ the simple fraction is $\frac{0}{1}$ so $f(0)$ is rational

VIVID
  • 11,667
  • I don't think there is a simple example of such a function since it smells like Dirichlet function that is nowhere continuous. And the fact that, usually, simple functions do not have this property... – VIVID Jul 17 '20 at 18:45
  • 1
    irrational number doesn't need to be rational? I'm not sure how to read this. I'm in 9th grade. I understand a lot of math does R/Q mean is a real number but isn't rational and when x is irrational f(x) can be either rational or irrational It doesn't madder does it say that? @VIVID –  Jul 17 '20 at 18:55

1 Answers1

4

How about

$$f(x)= \begin{cases} 0\quad\text{if }x\not\in\mathbb{Q}\\ \displaystyle{(-1)^a+(-1)^b\over b}\pi\quad\text{if }x=a/b\in\mathbb{Q}\text{ (with }\gcd(a,b)=1\text{ and }b\ge1) \end{cases}$$

Barry Cipra
  • 81,321