The following is an exercise from Calculus by Spivak.
Let $f,g:\mathbb{R}\to\mathbb{R}$ be continuous functions. Prove that if $f(x)=g(x)$ for all $x$ in a dense set $A\subset\mathbb{R}$, then $f(x)=g(x)$ for all $x\in\mathbb{R}$.
My attempt: Let $b\notin A$, and suppose $f(b)\neq g(b)$. Recall that $\lim_{x\to a}f(x)=f(a)$ if and only if for every sequence $a_n$ converging to $a$, we have $\lim_{n\to\infty}f(a_n)=f(a)$. Because $f$ and $g$ are continuous, $\lim_{x\to b}f(x)=f(b)$ and $\lim_{x\to b}=g(b)$. By density of $A$ in $\mathbb{R}$, there exists a sequence $a_n\in A$ that converges to $b$. Because $f$ is continuous, we have $\lim_{n\to\infty}f(a_n)=f(b)$. Similarly, because $g$ is continuous we have $\lim_{n\to\infty}g(a_n)=g(b)$. However, while $f(a_n)=g(a_n)$ for all $n\in\mathbb{N}$ we have $\lim_{n\to\infty}f(a_n)=f(b)\neq g(b)=\lim_{n\to\infty}g(a_n)$. This is a contradiction, thus $f(b)=g(b)$ for all $b\notin A$. My concern: I'm not sure about this line:
However, while $f(a_n)=g(a_n)$ for all $n\in\mathbb{N}$ we have $\lim_{n\to\infty}f(a_n)=f(b)\neq g(b)=\lim_{n\to\infty}g(a_n)$.
Can I even say this? Is the rest of the proof coherent?
It's easier to do it directly. I m assuming $f$ and $g$ are continuous on $\mathbb R$. Let $x\in \mathbb R$ and let $I_n=(x-1/n,x+1/n)$. And since $A$ is dense we can find $a_n\in A\cap I_n.$ Then,of course, $a_n\to x$. By assumption, $f(a_n)=g(a_n)$ and $f$ and $g$ are continuous at $x$. Therefore,
$f(x)=\lim_{t\to x} f(t)=\lim_{n\to \infty} f(a_n)=$
$\lim_{n\to \infty} g(a_n)=\lim_{t\to x} g(t)=g(x).$