TITLE: Why does the condition of a function being differentiable always require an open domain?
QUESTION [26 upvotes]: Going through Spivak's Calculus on Manifolds and in his definition of a differentiable function from a subset $A$ of $\mathbb{R}^n$ to $\mathbb{R}^m$, $f$ is said to be differentiable if it can be extended to a differentiable function on an open set containing $A$. 
Why is this? So we dont have to worry about taking limits at boundary points? Why is that even a problem? If thats not the problem, what is wrong with defining $f$ to be differentiable on $A$ if it is differentiable at each point in $A$?

REPLY [5 votes]: Short answer: the requirement of the domain set to be open is not needed to define differentiability. A longer answer follows.
Topological spaces and normed spaces
Let $V$ and $W$ be normed spaces over $\mathbb{R}$. The norms induce the metric topologies on $V$ and $W$, and so $V$ and $W$ are also topological spaces.
Let $E \subset V$. Then $E$ is a topological space which carries the subspace topology inherited from $V$, called a topological subspace of $V$. It is important to note that $E$ is a topological space in itself, and therefore you can never fall off from $E$. To be precise, every open neighborhood of a point $a \in E$ is a subset of $E$. These open neighborhoods are exactly the intersections of open sets of $V$ with $E$, by the definition of a subspace topology. Since $E \subset V$, it can be tempting for intuition to view it from the outside as being embedded in $V$. However, a better intuition is obtained by imagining living in $E$; there is no way out of $E$ by neighborhoods.
The domain need not be open
A function $f : E \to W$ is differentiable at $p \in E$, if there exists a linear function $(D_p f) : V \to W$ such that 
$$
\frac{f(x) - (f(p) + (D_p f)(x - p))}{\lVert x - p \rVert}
$$
has a limit at $p$ equal to zero. Recall that a limit in a topological space is defined using open neighborhoods, so that again there is no way to somehow fall off from $E$. 
We conclude that the definition of differentiability does not require $E$ to be an open set in $V$. 
What if $E = \{0\}$, say? Then - by the definition of a limit - every element of $W$ is vacuously a limit. In particular, zero is a limit, and therefore $f$ is differentiable on $E$. The derivative at a singular set is whatever you want it to be. 
Footnote 1: To avoid confusion, note that $E$ is an open set in $E$, by the definition of subspace topology. This is not the same as $E$ being open in $V$.
Footnote 2: A limit in a singular set shows that the limit is not always unique even in Hausdorff topological spaces.
Footnote 3: The same discussion holds for other forms of differentiation, such as directional derivatives.
An interesting example
This example is adapted from this question. Let $f : \mathbb{R} \to \mathbb{R}$ be differentiable at $0$. Let $E = \{0\} \cup \{1 / n\}_{n \in \mathbb{N}^{>0}}$. Then $(f|E)$ is differentiable at $0$, and $f'(0) = (f|E)'(0)$. Every point in $E$, except $0$, is isolated. The $0$ is an accumulation point.
Another example
Let $f : \mathbb{R}^n \to \mathbb{R}^m$ be differentiable. Then $(f|\mathbb{Q}^n)$ is differentiable, and $f'(x) = (f|\mathbb{Q}^n)'(x)$, for all $x \in \mathbb{Q}^n$. 
An open domain is sufficient for locality
Why would anyone require the domain set $E$ to be open? One answer is locality.
Let $\mathbb{R}$ be equipped with any norm. Since all norms in a finite-dimensional vector space are equivalent, this norm generates the Euclidean topology. Let $E = \{x \in \mathbb{R} : x \geq 0\}$, and $f : \mathbb{R} \to \mathbb{R}$ be such that
$$
f(x) = 
\begin{cases}
1, & x \in E, \\
0, & x \in X \setminus E.
\end{cases}
$$
Then $(f|E)$ is differentiable, and $(f|(X \setminus E))$ is differentiable, but $f$ is not differentiable, or even continuous. To be able to state that $f$ is differentiable - a synthesis of localized analyses - we need a theorem which allows to glue differentiable functions together to form a differentiable function, under some conditions. 
A sufficient condition for such locality is for the domains of the functions to be open, and the functions to agree on value on the overlaps. However, this condition is not necessary for locality. Consider a constant function $f$, and its restrictions to $E$ and $(X \setminus E) \cup \{0\}$. The sets $E$ and $(X \setminus E) \cup \{0\}$ are both non-open sets, $(f|E)$ and $(f|((X \setminus E) \cup \{0\}))$ are differentiable, and $f$ is differentiable.
Footnote 4: The gluing lemma for differentiable functions is in analogue to the gluing (pasting) lemma for continuous functions.
Open questions
Is locality the only reason for some requiring the domain to be an open set? What is a necessary and sufficient condition for the domains sets for the gluing lemma to hold for differentiable functions?