$\textbf{Problem:}$ Consider the function $f: [0,1] \rightarrow \mathbb{R}$ defined by letting $f(x)=0$ for rational $x$ and $f(x)=x$ for irrational $x$. Calculate the upper and lower Riemann integrals of $f$. Is $f$ Riemann integrable?  

$\textbf{	Solution Attempt:}$ Let $P_n=\{0=t_0,...,t_n=1\}$ be a partition of $[0,1]$, where $t_k = \frac{k}{n}$. For this partition, we have $$U(f,P_n)=\sum^{n}_{k=1} t_k (t_k - t_{k-1}) = \sum^{n}_{k=1} t_k (\frac{k}{n} - \frac{k-1}{n})=\sum^{n}_{k=1} \frac{k}{n} (\frac{1}{n})= \frac{1}{n^2} \sum^{n}_{k=1} k.$$ A familiar property of the natural numbers gives us that $\sum^{n}_{k=1} k= \frac{1}{2}n(n+1).$ Thus, $U(f,P)= \frac{1}{2} + \frac{1}{2n}.$ Recall, the upper Riemann integral $U(f)$ is defined as $U(f)=\inf
\{U(f,P)\}$, where $P$ is a parition of $[0,1].$ As $n \rightarrow \infty$, $P_n \rightarrow \frac{1}{2}.$ [Note: this is where I am a little unsure of myself.] Thus, $U(f)=\frac{1}{2}$. However, the lower Riemann integral is $0$. Hence, the upper and lower Riemann integrals disagree. We conclude that $f$ is not Riemann integrable. $\blacksquare$

If the aforementioned function was changed so that it took on the value of $0$ for irrational $x$ and $x$ for rational $x$, then $f$ would be zero almost-everywhere. Hence, it would be Lebesgue integrable. Is this correct? I am quite unsure of the Lebesgue integrability for the original function. A hint would great! Thank you!


Question: Create heatmap with PSTricks or TikZ
Answer: There is tikzDevice for R which will generate TikZ code for a plot created in R. So, if you use R to create your heat map (say, using ggplot2's geom_density2d()), you also get the TikZ code with little effort. There is a learning curve, though.

However, this kind of image should be included as a (perhaps high-resolution) raster image in your document, as the vector version might take a long time to render. So you can create a TikZ version of the plot, compile it to PDF and then convert to PNG at the required resolution/pixel density.