Most general $A \subseteq \mathbb R$ to define derivative of $f: A \to \mathbb R$? I was looking up the definition of the derivative in several books, and what was making me uneasy was the first sentence, generally along the lines of "let $f$ be defined on...". They don't seem to be able to agree on what $f$ should be defined on. Most books say "interval"; one says "open set"; another just says "let $f$ be a real-valued function"; etc. So I decided to do a little investigation.
At the end of the day, we always define the derivative as the limit of a difference quotient (two versions), so we need to look into limits of functions. It turns out that the limit of $f$ at $a$ is only defined for $a \in (\operatorname{dom} f)'$ (we'll denote the set of cluster points of $A$ by $A'$ for convenience), because otherwise, the $0 < |x - a| < \delta$ part of the definition can be made false by choosing $\delta$ small enough to isolate $a$, thereby making the implication vacuously true, which gives non-unique limits, but we don't want that. So at this point, we know that $a$ must be a cluster point of the domain of the difference quotient.
A slight digression: It's easy to show that if $B$ is a finite set, then $A' = (A \cup B)' = (A \setminus B)'$. (That is, "adding" or "subtracting" a finite number of points doesn't affect the "stickiness" of a set.)
Let $A \subseteq \mathbb R$ and let $f: A \to \mathbb R$. For each $a \in A$, we can define a difference quotient function $q_a: A \setminus \{a\} \to \mathbb R$ by $$q_a(x) = \frac{f(x) - f(a)}{x - a}.$$
Now, (in a rather perverted pseudo-self-referential manner), we can define $$f': \{a \in A \cap A': \lim_{x \to a} q_a(x) \in \mathbb R \} \to \mathbb R \qquad \text{by} \qquad f'(a) = \lim_{x \to a} q_a(x).$$
We need $a \in A$ because $f(a)$ is needed to evaluate $q_a$, and we need $a \in A' = (A \setminus \{a\})' = (\operatorname{dom} q_a)'$ for the limit to be defined. So really, derivatives can be defined on sets that are much more general than intervals: we really only need $\operatorname{dom} f \cap (\operatorname{dom} f)' \neq \varnothing$ in order to talk about the derivative of $f$ at some point (of course, the derivative itself need not exist, but at least we can talk about it not existing).
And then I started getting worried... The function $f: \mathbb R \to \mathbb R$, defined by $$f(x) = \begin{cases} x, & x \in \mathbb Q, \\ 0, & x \notin \mathbb Q, \end{cases}$$ has no derivative anywhere. But if we restrict the domain to $\mathbb Q$, then suddenly every point is differentiable with derivative $1$? Now I'm starting to wonder if I made some stupid mistake in the development above, but I can't seem to find it.
So the question is, is the bolded statement above true?
 A: The definition you gave is the definition of derivative I learned at the university ;-)
Here are some links to papers which also use your definition of derivative:


*

*http://cs.unitbv.ro/~pascu/analysis/Derivability.pdf (page 43 – second page of pdf)

*http://math.gmu.edu/~dwalnut/teach/Math315/Summer11/5.1%20Concepts%20of%20the%20Derivative.pdf

*http://www2.math.umd.edu/~lvrmr//2009-2010-F/Classes/MATH246/CALCULUS/Derivatives.pdf (page 4 for definition of limit; page 6 for definition of derivative)
As you already said different authors give different definitions of the derivation and you will also find references with other definitions. The definition you gave is the most general one.
As you mentioned: The derivative of a function $f:A\rightarrow\mathbb{R}$ can be defined for every point of $a\in A$ for which exists at least one sequence $(a_n)$ in $A\setminus\{a\}$ with $\lim_{n\rightarrow\infty} a_n = a$.
As Leonid Kovalev already said in a comment, there are important theorems in calculus (like the mean value theorem) where the differentiable function need to be defined on an interval. That may be the reason why many authors for textbooks in calculus just define the differentiability of functions with an interval as domain.
To have a concept of differentiability for functions like $\mathbb{R}\setminus\{0\}\rightarrow \frac 1x$ too, you have to extend your definition to open subsets of $\mathbb{R}$ (because $\mathbb{R}\setminus\{0\}$ is no interval and formaly two functions differs if their domain is different). Another step of generalization leads you to the definition with limit points.
To your given example: Let $g : \mathbb{Q} \rightarrow \mathbb{R} : x \rightarrow x$. For every $x,h\in\mathbb{Q}$ we have:
$$g(x+h)=g(x)+1\cdot h$$
So every $x,h\in\mathbb{Q}$ fulfills
$$g(x+h)\approx g(x)+1\cdot h+ O(|h|^2)$$
and therefore for every $x\in\mathbb{Q}$ the derivative of $g$ at $x$ is $1$ (as you can see from the above approximiation). There is no reason why we should worry that $g$ is not defined on all $\mathbb{R}$. The approximation $g(x+h)\approx g(x)+1\cdot h+ O(|h|^2)$ is well defined (and you can think of cases where it is useful too).
Now we extend $g$ to your function $f(x) = \begin{cases} x, & x \in \mathbb Q, \\ 0, & x \notin \mathbb Q, \end{cases}$. Because there are new arguments we have to worry about, the approximation fails for every $x\in\mathbb{R}$ and therefore the extended function is not differentiable.
You have this kind of “problem” also if you just define differentiability for functions on open sets in $\mathbb{R}$. $f(x) = \begin{cases} \frac 1x & ;x\neq 0 \\ 0 & ; x=0\end{cases}$ is not differentiable everywhere but $g:\mathbb{R}\setminus\{0\}:x\mapsto \frac 1x$ is differentiable everywhere.
Or a better example from complex analysis: $f:\mathbb{R}\rightarrow\mathbb{R}:x\mapsto 1$ is differentiable but $g: \mathbb{C}\rightarrow\mathbb{R}:a+b\cdot i\mapsto\begin{cases} 1&; b=0 \\0&;b\neq 0 \end{cases}$ is not differentiable for all real numbers.
If the domain $D$ of $f$ is open in $\mathbb{R}$ you cannot change the differentiability of $f$ at points in $D$ by extending $f$ in $\mathbb{R}$. But as the above example shows you can change the differentiability of $f$ at those points by extending it to a complex function...
A: It is fairly common in real analysis literature (and even in some textbooks) to define the derivative of a function $f:A \rightarrow {\mathbb R},$ where $A \subseteq {\mathbb R},$ at all points in $A$ that are also limit points of $A$ (but at no other points). The earliest reasonably general treatment of this notion I know of is
Earle Raymond Hedrick, On derivatives over assemblages, Transactions of the American Mathematical Society 8 #3 (July 1907), 345-353. JFM 38.0419.02
A: This more general notion of a derivative does appear in certain branches of real analysis.  For instance, an important technical notion is that of an approximately differentiable function.  This notion is defined as the approximate limit of the usual differential quotient and as such is defined at any density point of the domain.  
Approximately differentiable functions arise especially in the theory of nonabsolute integration (i.e., integrals of Denjoy-Khinchin-Perron-Kurzweil-Henstock).  Russell Gordon's book is a very nice introduction to this circle of ideas.
A: One someone studies Analytic Geometry in a broader way and has studied before the concept of derivative of a function $f$, a natural question is: Why is the concept of derivative that? Derivatives are originally used to "measure" the rate of change... Why do not defining the concept of deriative as $\lim_{x\to a} \frac{d(f(x),f(a))}{d(x,a)}$? It would be a interesting generalization, we could derivate easily on metric spaces... But they are not as interesting as the usual definition... The usual definition is one of the definitions which works when working with integrals, is the one which fits in the Fundamental Theorem of Calculus... There are plenties of defintions,and each one has related a particular version of the Fundamental Theorem of Calculus. Consider the Radom-Nikodym which is one of the derivatives which work with the Lebesgue integral. Derivatives and Integral are two sides of the same coin. 
A: Consider the statement:
Let $A, B$ be subsets of the domain of $f$. If $f$ is differentiable on $A$ and on $B$, then $f$ is differentiable on $A \cup B$.
Sounds reasonable. It is true as long as we define differentiability only on open sets, but becomes wrong as soon as we allow even just endpoints (which are of course accumulation points) of intervals: Consider $f(x) =\lvert x \rvert$ and $A=(-\infty, 0]$, $B=[0, \infty)$.
Of course one can have reason to disregard this issue. But one should be aware of it.
A: I personally think it is a bad idea to define the derivative of a function at a point if no neighborhood of that point is contained in the domain. The whole point is that we want a linear approximation
$$f(a + h) = f(a) + f'(a) h + o(|h|)$$
to hold in a neighborhood of $a$ (hence for $h$ in some open ball) and if there are no such neighborhoods you aren't really talking about the derivative in a conventional sense, but in some weirder sense.
In other words, my inclination would be to restrict to open sets.
