Holomorphic function has primitive Let $\mathcal{A}$ be the family of open disks and open squares in the complex plane. Let $f:D_1 \cup D_2 \to \mathbb{C}$ be a holomorphic function where $D_1, D_2 \in \mathcal{A}$. Prove that $f$ has a primitive in $D_1 \cup D_2$. The problem here is that all the theorems we were taught that guarantee the existence of primitive require at least an open and connected set. But $D_1 \cup D_2$ is not connected unless $D_1 \cap D_2 \neq \emptyset$.
Now the proof I came up with (but I'm not really sure about) is the following:

*

*If $D_1 \cap D_2 \neq \emptyset$ then $D_1 \cup D_2$ is open, connected and star-shaped. Since $f$ is holomorphic we know that it has a primitive (this is a known theorem)


*If $D_1 \cap D_2 = \emptyset$ then $f|_{D_1}$ is holomorphic and $D_1$ is open connected and star-shaped so $f$ has a primitive on $D_1$. The same holds on $D_2$ and we can construct a primitive on $D_1 \cup D_2$ by "combining" the primitives on $D_1$ and $D_2$.
Is this correct? If not, how can I prove it? Thank you.
 A: Here is a writeup of the discussion in the comments.

*

*$D_1 \cap D_2 = \emptyset$. Let $F_1: D_1 \to \mathbb{C}$, $F_2: D_2 \to \mathbb{C}$ be the two given primitives of $f$. Claim: A primitive of $f$ on $D_1 \cup D_2$ is

$$F(z) = \cases{F_1(z) & $z \in D_1$ \\F_2(z) & $z \in D_2$ }.$$
Proof: $F$ is well-defined since $D_1 \cap D_2 = \emptyset$. Let $z \in D_1 \cup D_2$. $z \in D_1$ without loss of generality. We compute $F'(z)$: Since $D_1$ is open, there is some $\varepsilon > 0$ such that $B_{z}(\varepsilon) \subset D_1$. Then $\forall w \in B_z(\varepsilon)$, $F(w) = F_1(w)$. Therefore $F'(z) = F_1'(z) = f(z)$. Similarly for $D_2$.


*$D_1 \cap D_2$. In this case $D_1 \cup D_2$ is simply connected so it should come as no surprise that $f$ has an antiderivative. Let $F_1, F_2$ be as above. On the connected open set $D_1 \cap D_2$, $F_1'(z) = F_2'(z)$. Therefore $F_1(z) - F_2(z) = C$ throughout $D_1 \cap D_2$. Claim: A primitive of $f$ on $D_1 \cup D_2$ is

$$F(z) = \cases{F_1(z) - C & $z \in D_1$ \\F_2(z) & $z \in D_2$ }.$$
Proof: $F$ is well defined by the previous argument. Just like before, at any point of $D_1 \cup D_2$, we can restrict $F$ to a small enough ball that $F$ is equal to one of the branches. Then $F'(z) = f(z)$ as required.
