Solution (source code)

= Solution

On $A=\bigcup_iA_i$, interpret a constant at its common value, a function on a tuple by choosing one $A_i$ containing the tuple, and a relation similarly. Total ordering of the indices and compatibility of substructures make these definitions independent of the chosen stage. Every $A_i$ is then a substructure of $A$.

For an elementary chain, induction on formulas proves
$$
A_i\models\varphi(\bar a)\Longleftrightarrow A\models\varphi(\bar a)
\qquad(\bar a\in A_i).
$$
The atomic step follows from the induced structure, Boolean steps are immediate, and for an existential formula any witness in the union lies in a later $A_j$ containing the parameters; elementarity between $A_i$ and $A_j$ moves existence back to $A_i$. This is the <elementary chain theorem>.