Prove that if $f_i$ is continuous on $A_i$ for each $i = 1, 2$, then $f$ is continuous on $X$. 
Let $X$ and $Y$ be metric spaces, $A_1$ and $A_2$ non-empty open
   subsets of $X$ such that $X = A_1 \cup A_2$. Let $f : X \to Y$ and let
   $f_i : A_i \to Y$ be the restriction of $f$ to $A_i$ for $i = 1, 2$.
   Prove that if $f_i$ is continuous on $A_i$ for each $i = 1, 2$, then
   $f$ is continuous on $X$.

Recall if i can show that $f^{-1}(G)$ is open in $X$ for all open set $G$ in $Y$, then i can say that $f$ is continuous on the map $X \to Y$. Indeed $f_1,f_2$ being continuous implies that $f^{-1}(G)$ is open in $A_1$ and also open in $A_2$ for all open set $G$ in $Y$. This means $f^{-1}(G)$ is open in $A_1 \cup A_2 = X$ and we are done. 
Can anyone verify my proof? Thanks
 A: The restriction of $f$ is continuous on $A_i$, then there exists a open set in $X$, say $U_i$, corresponding to an open set $G$ of $Y$ such that $f_i^{-1}(G)=U_i\cap A_i$. As $A_1\cup A_2=X$, so $(U_1\cap A_1)\cup(U_2\cap A_2)=f^{-1}(G)$, which is open in $X$. Hence inverse image of any open set in $Y$ is an open set in $X$. Hence $f$ is open in $X$.  
A: Let $U$ be open in $Y$ then $f^{-1}(U)= f^{-1}(U)\cap X=f^{-1}(U)\cap (A_1\cup A_2)=(f^{-1}(U)\cap A_1)\cup (f^{-1}(U)\cap A_2)$
Now $(f^{-1}(U)\cap A_i)\subset A_i\implies (f^{-1}(U)\cap A_i)=(f_i^{-1}(U)\cap A_i)$
and each $f_i$ is continuous on $A_i$ for $i=1,2$
Since union of open sets is open so is $f^{-1}(U)$ in $X$
A: Your proof needs an argument why the union of a set open in $A_1$ and a set open in $A_2$ is open in $X$. Just $X = A_1 \cup A_2$ is not enough for that to hold in general, you need to use $A_1$ and $A_2$ are open, which you don't (always a bad sign: you're not using one of the assumptions).
The main fact you use in this exercise: if $f: X \to Y$ is a function and $A \subset X$ then $(f|_A)^{-1}[B] = f^{-1}[B] \cap A$ for any $B \subset Y$.
