Details of gluing sheaves on a cover I am sure this is a simple question, but I am really not able to think straight at the moment and this is bugging me. I am doing Exercise 1.22 from Hartshorne. It is the classic gluing of of sheaves on a cover given the cocycle condition question. In particular, we have a space $X$ and a cover for this space $\{ U_{i} \}_{i \in I}$. Further, we are given a family of sheaves indexed by the same set $I$, $\{ \mathcal{F}_{i} \}_{i \in I}$ on each of the $U_{i}$. We are given isomorphisms
$$
\phi_{ij}: \mathcal{F}_{i}|_{U_{i} \cap U_{j}} \longrightarrow \mathcal{F}_{j}|_{U_{i} \cap U_{j}},
$$
along with the so-called cocycle condition
$$
\phi_{ik} = \phi_{ik} \circ \phi_{ij} \quad \text{on} \quad U_{i} \cap U_{j} \cap U_{k}.
$$
The task is to construct a sheaf on $X$ compatible with these local sheaves. I have gone ahead and done the obvious steps of defining a base by taking all open sets contained in one of the $U_{i}$ etc. I then defined a sheaf $\mathcal{G}$ on this base and this is well defined since if there is some $V$ in $U_{i}$ and $U_{j}$ with $i \neq j$, then via the isomorphism $\phi_{ij}$, we have
$$ \mathcal{F}_{i}(V) \stackrel{\simeq}{\longrightarrow} \mathcal{F}_{j}(V) $$
My understanding is that to make the restriction maps work, you need to invoke the cocycle condition. My issue is that I can't see exactly where. It seems that the isomorphism alone is enough. The frustrating part is that every resource I look at (and there are a lot since this is a common exercise) simply says "the restrictions are compatible because of the cocycle condition" or "this is well defined because of the cocycle condition" or something similar. Nowhere seems to explicitly lay out where the cocyle condition is invoked, and what breaks when it is not. Is someone able to shed some light on this? Other than this small step I feel like I understand the rest of it completely, but I feel like this is a vital thing to not understand. 
Thanks
 A: Personally, I find it more intuitive to define the glued-up sheaf $\mathcal F$ like this:
For every open set $V \subset X$, we define the group of sections $\mathcal F(V)$ to be a set consisting of all tuples $(s_i)_{i \in I}$, where each $s_i$ is a section in $\mathcal F_i(V \cap U_i)$, and where the $s_i$'s are required to obey the compatibility condition: $$\phi_{ij}(s_i|_{V \cap U_i \cap U_j}) = s_j |_{V \cap U_i \cap U_j} \ \ \ \ \ (\ast)$$ for all $i, j \in I$. The group addition on $\mathcal F(V)$ is the obvious one.
As far as I can tell, the $\mathcal F$ that I defined is guaranteed to be a sheaf, regardless of whether we impose the cocycle condition. It comes with a natural restriction map, making it a presheaf, and it also obeys all the gluing conditions necessary for it to be a sheaf. I don't think the cocycle condition is needed to verify any of these things.
However, it is not enough to prove that our $\mathcal F$ is a sheaf. We also need to satisfy ourselves that the restriction $\mathcal F|_{U_k}$ really is isomorphic to the $\mathcal F_k$ that we started with, for each $k \in I$. It is here that the cocycle condition is required.
It is easy to write down what the isomorphism $\psi : \mathcal F_k \overset{\cong}\to \mathcal F|_{U_k}$ ought to be. Given an open $V \subset U_k$ and given a section $s \in \mathcal F_k$, we would like to define its image under $\psi$ to be
$$ \psi(s) = (\phi_{ki}(s|_{V \cap U_i}))_{i \in I}$$
However, we need to be sure that the tuple $(\phi_{ki}(s|_{V \cap U_i}))_{i \in I}$ represents a well-defined element of $\mathcal F(V)$. In particular, we must verify that $(\phi_{ki}(s|_{V \cap U_i}))_{i \in I}$ obeys the condition $(\ast)$, which states that
$$ \phi_{ij} \circ \phi_{ki}(s|_{V \cap U_i \cap U_j}) = \phi_{kj}(s|_{V \cap U_i \cap U_j})$$
for any $i, j \in I$. This is true by virtue of the cocycle condition.
A: Although I'm late for the party, here is another way of constructing the glued sheaf, using the stalks of the sheaves $\mathcal{F}_i$.
Consider some $x\in X$. For any $i,j$ such that $x \in U_i \cap U_j$, the sheaf isomorphism $\phi_{ij}$ induces an isomorphism $\phi_{ij}^x:(\mathcal{F}_i)_x \rightarrow (\mathcal{F}_j)_x$ between the stalks at $x$ of the sheaves $\mathcal{F}_i$ and $\mathcal{F}_j$. Note that the inverse of $\phi_{ij}^x$ is $\phi_{ji}^x$.
Now, on $\coprod_{x\in U_i} (\mathcal{F}_i)_x$ define the following relation: $(s_i)_x \sim (s_j)_x \iff \phi_{ij}^x((s_i)_x) = (s_j)_x$. The conditions $\phi_{ii} = \text{id}$ and $\phi_{ik} = \phi_{jk} \circ \phi_{ij}$ imply that "$\sim$" is an equivalence relation.
Define $A_x = \coprod_{x\in U_i} (\mathcal{F}_i)_x /\sim$. The set $A_x$ can be endowed with a group structure in the obvious way. These $A_x$ will be actually the stalks of the sheaf $\mathcal{F}$.
Let us define the glued sheaf $\mathcal{F}$. If $U \subseteq X$ is open, define the sections above $U$ as being functions: $$f:U \rightarrow \coprod_{x\in U}  A_x$$ such that $f(x) \in A_x$ for any $x \in U$ and, moreover,  for every $i$ there exists (a unique) section $s \in \mathcal{F}_i(U\cap U_i)$ such that $f(x) = \widehat{s_x}$ on $U \cap U_i$. I denoted by $\widehat{s_x}$ the class of the germ $s_x$ modulo $\sim$.
The restriction maps of $\mathcal{F}$ are the usual restrictions of functions. It is straightforward to check that $\mathcal{F}$ is indeed a sheaf and $\mathcal{F}_{|U_i} \cong \mathcal{F}_i$ for any $i$.
Notice that the sheaf $\mathcal{F}$ is actually the same as the sheaf constructed by @Kenny Wong (as they should be, since $\mathcal{F}$ is unique up to an isomophism).
A: Also late for the party, and Kenny Wongs answer provides an excellent alternative construction to solve this exercise. If you want to stick with the sheaf-on-a-base approach however, you can do the following.
Let $\mathcal{B}$ be the base of open sets consisting of those open subsets of $X$ which are contained in some $U_i$. If we want to define a sheaf $F$ on $\mathcal{B}$, the first idea might be to take $B \in \mathcal{B}$ s.t. $B \subseteq U_i$ for some $i$, and then define $F(B) := \mathcal{F}_i(B)$.
The problem with this is that $B$ might be contained in two open sets of the cover, say $U_i$ and $U_j$. Then $\mathcal{F}_i(B) \cong \mathcal{F}_j(B)$, but they are different objects nevertheless, and neither is a natural choice for $F(B)$.
To get around this, we can use the axiom of choice. Let $J$ be an index set for $\mathcal{B}$, and for each $j \in J$ let $C_j = \{i \in I: B_j \subseteq U_i\}$. Thus we have associated a subset of $I$ to each $j \in J$.
By the axiom of choice, we can define a function
\begin{equation}
\alpha: J \to I
\end{equation}
such that $\alpha(j) \in C_j$ for all $j$. Thus $\alpha(j)$ is a choice of index $i$ such that $B_j \subseteq U_i$.
Now for $i \in J$ and $a = \alpha(i)$, simply define
\begin{equation}
F(B_i) := \mathcal{F}_a(B_i).
\end{equation}
We can define restriction maps as follows. Let $B_j \subseteq B_i$ and $b = \alpha(j)$. Note that $B_j \subseteq B_i \subseteq U_a$, so $B_j \subseteq U_a \cap U_b$. Consider the diagram
$\require{AMScd}$
\begin{CD}
\mathcal{F}_a(B_i)\\
@VVV\\
\mathcal{F}_a(B_j) @>{\phi_{ab,B_j}}>> \mathcal{F}_b(B_j)
\end{CD}
where the vertical map is the restriction map on $\mathcal{F}_a$, and the horizontal map is part of the sheaf isomorphism on $U_a \cap U_b$. Define the restriction on $F$ to be the composition of these two maps.
Using these definitions for $F$, the cocycle condition pops up when showing that $F$ is a sheaf on $\mathcal{B}$, and even when showing that $F$ is even a presheaf on $\mathcal{B}$: That the restriction equals the identity on $B_i$ is immediate, but if $B_k \subseteq B_j \subseteq B_i$, then the restrictions must be compatible with composition. You need the cocycle condition for this; try it out.
The situation is similar for the sheaf axiom on $\mathcal{B}$; you are basically just using the sheaf axiom for whatever $U_i$ everything is situated in, but to deal with all of the isomorphisms contained in the restriction maps for $F$, you need the cocycle condition as well.
Once you have shown that $F$ is a sheaf on $\mathcal{B}$, you can use the fact that it can be uniquely extended to a sheaf on $X$, i.e. there exists a sheaf $\mathcal{F}$ on $X$ together with natural isomorphisms $\mathcal{F}(B) \cong F(B)$ for $B \in \mathcal{B}$ that commute with the restriction maps. You can now show that there exist sheaf isomorphisms $\mathcal{F}_{|_{U_i}} \cong \mathcal{F}_i$ and that the induced automorphisms on $\mathcal{F}_{|_{U_i\cap U_j}}$ equal the identity; both of these once again require the cocycle condition.
