Plot a function involving lowest terms
Hi,
How do I use sage to plot the following function?
$$ f(x)= \left[ \begin {array} {cc} 0, & x \text{ irrational, } 0 \lt x \lt 1 \\ \frac{1}{q},& x = \frac{p}{q} \text{ in lowest term, } 0 < x < 1.\end{array} \right.$$
I actually wrote a function that would generate the following sequence: $$ \frac{1}{n}, \dots , \frac{n-1}{n}$$ for a given $n$.
Then I created a list of lists that contains the above sequence for each n. After flattening that list, I call the set function on it to remove duplicates. Then I use that to creat a list (x,y) tuple to plot the function using scatter plot.
I was wondering if there is a simpler way of doing this.