Can there exist a function that has a weak derivative, but is not differentiable almost everywhere? I am currently learning about Sobolev spaces, and I am trying to build some intuition of weak derivatives. My current intuition is imagining the weak derivative of f as a function equal to f's derivative almost everywhere. However, this assumption assumes that f is differentiable almost everywhere. Is this always the case for weakly differentiable functions?
 A: If $p>n$, then the function is differentiable a.e. and the derivative coincides with the weak derivative a.e.
If $p\leq n$ (or even $f\in BV$) the function is only approximately differentiable a.e.
Both results can be found in Evans & Gariepy, Measure theory and fine property of functions, section 6.1 (and if I recall correctly "a.e." can be replaced by "outside a set of zero $p$-capacity", which is slightly stronger).
To construct a counterexample to a.e. differentiability for $p$ strictly below $n$, consider a nonnegative function $\eta \in C^\infty (\mathbb{R}^n)$ with support in $B_1$ and with value $1$ on $B_{1/2}$, and enumerate the rationals as $\mathbb{Q}=\{q_i\}_{i\in \mathbb{N}}$. Choose a sequence $r_i\searrow 0$ to be specified later, and define
$$f(x)=\sum_{i\in \mathbb{N}}\eta\left(\frac{x-q_i}{r_i}\right).$$
This is a dense sum of bumps with smaller and smaller support. By the scaling of the $L^p$ norms you can check that indeed  $f\in W^{1,p}$, provided $\sum_{i\in \mathbb{N}}r_i^{\frac{n}{p}-1}<\infty$.
However, the support of $f$ is contained in $\bigcup_{i\in \mathbb{N}} B(q_i,r_i)$ which can be made as small as wanted by sending $r_i$ quickly to zero, therefore at most points the function is zero. On the other hand, $f$ has value at least $1$ on a dense set (and the same holds for any function in the same equivalence class), therefore it can not be differentiable where it attains value zero.
I couldn't come up with a similar counterexample for $f\in W^{1,n}(\mathbb{R}^n)$, but maybe a similar construction would work.
A: Fellow time travelers, allow me to highlight a good example which I found in the notes that Hass Saidane refers to:

The Heaviside step function is differentiable almost everywhere. However, it is not weakly differentiable.

[Edit: thus, we see that even for functions which are classically differentiable almost everywhere, OP's proposed intuition still isn't entirely air-tight].
Indeed, it can be said that $H'=h$ weakly if two conditions are met: First, (integrating against) $h$ is the distributional derivative of (integrating against) $H$. Second, $h$ lives in some appropriate $L^p$ space.
However, the distributional derivative of (integrating against) the Heaviside functional is the dirac-delta, in a sense which is very different from the technically legitimate $L^p$ function $\infty \cdot \chi_{\{0\}}$ (which is precisely the zero element of $L^p$).
Therefore, the distributional derivative of $H$ fails to be of the form "integrate against an $L^p$ function."
Good luck, fellow students.
A: Here are 2 references on the topic:
https://www.math.ucdavis.edu/~hunter/pdes/ch3.pdf
https://en.wikipedia.org/wiki/Weak_derivative
