TITLE: Existence of an antiderivative function on an arbitrary subset of $\mathbb{R}$
QUESTION [18 upvotes]: Let $f:\mathbb{R}\to \mathbb{R}$ be  continuous at $x$ for every $x\in I$  where $I\subset \mathbb R$ could be arbitrary. Does there always exist a function $F:\mathbb{R}\to \mathbb{R}$ differentiable on $I$ and $F'(x) = f(x)$ for every $x \in I$?
The definition of a primitive is naturally defined on an interval. what sort of weaker result can we obtain under weaker hypotheses?. 

If I is an interval or an open set, the answer to the question is
positive.
If f is locally Lebesgue integrable,the answer to the question is
also positive.

I have already asked the question here https://math.stackexchange.com/questions/2855483/existence-of-an-antiderivative-function-on-an-arbitrary-subset-of-mathbbr

REPLY [4 votes]: As requested, I turn my comments into an answer.

First of all, we replace $f$ by its lower semi-continuous envelope:
$$ g(x) = \liminf_{y \to x} f(x) . $$
Observe that $g(x) = f(x)$ for $x \in I$ and $g$ is continuous at every $x \in I$. Furthermore, $g$ is lower semi-continuous, and hence Borel measurable.
If $g$ is continuous at $x$, then there is a neighbourhood $U_x$ of $x$ such that $g$ is bounded in $U_x$. Let $U$ be the union of $U_x$ over all $x \in I$.
Consider a connected component $(a, b)$ of $U$. Then $g$ is locally bounded on $(a, b)$ (for any compact subinterval of $(a, b)$ can be covered by finitely many sets $U_x$ with $x \in I$), and thus we can define
$$ F(x) = \int_{(a+b)/2}^x g(y) dy $$
for $x \in (a, b)$. Clearly, $F$ is differentiable at every point of continuity $x \in (a, b)$ of $g$, and $F'(x) = g(x)$. In particular, $F'(x) = g(x) = f(x)$ for all $x \in I \cap (a, b)$.
We define $F$ as above on every connected component $(a, b)$ of $U$, and we set $F(x) = 0$ for $x \notin U$. By construction, $F'(x) = f(x)$ for every $x \in I \cap U = I$, as desired.