When does a complex function have a square root? I would like to show that there is a holomorphic $f$ on a neighborhood of zero such that $f(z)^2=1-\cos(z)$.
In other words, I want to show that $1-\cos(z)$ has a complex square root. I know that this has something to do with whether one can define a branch of $\log(1-\cos(z))$ in a neighborhood of zero (since $z^{1/2}=e^{\frac12 (\log(1-\cos(z)))}$, but I thought this could not be possible because at zero, $1-\cos(z)=0$, and $\log(z)$ is not defined.
Can someone help me out? In general I'm missing out on some subtlety about the complex logarithm.
 A: Since Malik already gave an answer concerning your specific question about $1-\cos z$, I will just talk about the existence of logarithms and $n$-th roots in general.
Given a holomorphic function $f:\Omega\to\mathbb{C}\setminus\{0\}$, we say that a holomorphic function $g:\Omega\to\mathbb{C}\setminus\{0\}$ is a logarithm of $f$ if $f(z)=e^{g(z)}$ for $z\in\Omega$. Similarly, we say that a holomorphic function $h_n:\Omega\to\mathbb{C}\setminus\{0\}$ is an $n$-th root of $f$ if $f(z)=h_n(z)^n$ for $z\in\Omega$. The question is, when do such functions exist?
The quick answer is that for an $n$-th root to exist, we must have, for any closed curve $\gamma$ in $\Omega$,
$$ \frac{1}{2\pi i}\int_\gamma \frac{f'}{f}\ dz \in n\mathbb{Z}. $$
Furthermore, a branch of the logarithm of $f$ exists if and only if for every $n\in\mathbb{N}$, an $n$-th root of $f$ exists. The reason for this is that a logarithm of $f$ exists if and only if for every closed curve $\gamma$ in $\Omega$, 
$$ \frac{1}{2\pi i}\int_\gamma \frac{f'}{f}\ dz = 0. $$
Notice that if we have a logarithm of $f$, say $g$, then we can construct an $n$-th root of $f$ for any $n$ by letting $h_n(z):=e^{\frac{g(z)}{n}}$. For the other direction, notice that if the aforementioned integral is an element of $n\mathbb{Z}$ for every $n$, then it must be zero, and thus the logarithm of $f$ must exist.
Now, the above may seem very mysterious. Where did we get these conditions on the integral? The easiest explanation is via algebraic topology. Unfortunately, I can't draw commutative diagrams with MathJax, but the point is the existence of a logarithm of $f$ is equivalent to the existence of a lift with respect to the covering map $\exp:\mathbb{C}\to\mathbb{C}\setminus\{0\}$. Since $\mathbb{C}$ is simply connected, the induced homomorphism of fundamental groups, which we will denote $\exp_*$, is trivial. Thus, a lift (and hence a branch of the logarithm of $f$) exists if and only if $f_*(\pi_1(\Omega))<\exp_*(\pi_1(\mathbb{C}))$, which is if and only if $f_*(\pi_1(\Omega))$ is trivial, which is if and only if the winding number $n(f\circ\gamma,0)=0$ if and only if $\frac{1}{2\pi i}\int_\gamma \frac{f'}{f}\ dz=0$. 
Similarly, the existence of an $n$-th root of $f$ is equivalent to the existence of a lift with respect to the covering map $(\cdot)^n:\mathbb{C}\to\mathbb{C}\setminus\{0\}$. Now the induced homomorphism of fundamental groups, which we will denote $(\cdot)^n_*$, has image $n\mathbb{Z}$. Thus, a lift (and hence an $n$-th root of $f$) exists if and only if $f_*(\pi_1(\Omega))<(\cdot)^n_*(\pi_1(\mathbb{C}))$, which is if and only if $f_*(\pi_1(\Omega))<n\mathbb{Z}$, which is if and only if the winding number $n(f\circ\gamma,0)\in n\mathbb{Z}$ if and only if $\frac{1}{2\pi i}\int_\gamma \frac{f'}{f}\ dz\in n\mathbb{Z}$. 
Now, for the case when $f:\Omega\to\mathbb{C}$ (that is, $f$ might have zeros), then you simply restrict $f$ to the set where it is nonzero (this is still an open set) and follow the above procedure. If an $n$-th root of this restricted $f$ exists, then an $n$-th root of the original $f$ exists if and only if every zero of $f$ has order a multiple of $n$. This you can see because of the procedure laid out in the comments. Notice that this condition (along with the fact that a logarithm of $f$ exists if and only if for every $n\in\mathbb{N}$ an $n$-th root of $f$ exists) implies that a necessary condition for a logarithm of $f$ to exist is that it has no zeros in the domain in question.
I mentioned in the comments that it is possible for an $n$-th root of $f$ to exist for some $n\in\mathbb{N}$ and yet have it be the case that a logarithm for $f$ does not exist. As an example, consider the function $f(z)=z^2$ in the domain $\mathbb{C}\setminus\{0\}$. Clearly, the function $h_2(z)=z$ is a square root of $f$. However, $f$ does not have a logarithm in this domain because if $\gamma$ is some curve that winds around zero, then
$$ \frac{1}{2\pi i}\int_\gamma \frac{f'}{f}\ dz = \frac{1}{2\pi i}\int_\gamma \frac{2}{z} \ dz = 2. $$
Since this is nonzero, $f$ cannot have a logarithm in the given domain.
Added: Let $f:\Omega\to\mathbb{C}\setminus\{0\}$ be a holomorphic function. Consider the following two statements. 


*

*There exists a logarithm of $f$ in $\Omega$.

*There exists a branch of the logarithm in $f(\Omega)$.


We will show that 2 implies 1, but not conversely. To see that 2 implies 1, let $\log$ be a branch of the logarithm in $f(\Omega)$. Then define $g:=\log\circ f$. Then notice that for all $z\in\Omega$, $e^{g(z)}=e^{\log(f(z))}=f(z)$, since $f(z)\in f(\Omega)$. Thus $g$ is a logarithm of $f$. To see that the converse does not hold, simply consider the map $\exp:\mathbb{C}\to\mathbb{C}\setminus\{0\}$. This map is surjective, and it is a well-known fact (we could also use what I proved above) that there does not exist a branch of the logarithm in $\mathbb{C}\setminus\{0\}=\exp(\mathbb{C})$. However, there certainly exists a logarithm of $\exp$ in $\mathbb{C}$, namely, the identity map. Therefore 1 does not imply 2. 
A: One cheeky yet direct way is that: $1-\cos{z} = (\cos^2{z/2}+ \sin^2{z/2} )- (\cos^2{z/2}-\sin^2{z/2}) = 2 \sin^2{z/2} = (\sqrt{2}\sin{z/2})^2$
which is definitely holomorphic in a neighborhood of the origin.
A: If $g(z)=1-\cos{z}$, then $g$ can be written as
$$g(z)=z^2 h(z)$$
where $h$ is entire and $h(0) \neq 0$ (why? Hint: Taylor).
Take a small disk $D$ around $0$ such that $h \neq 0$ on $D$. Then, on $D$, $h(z)=k(z)^2$ for some function $k$ analytic on $D$.
Finally, we get
 $$g(z)=z^2 h(z) = z^2 k(z)^2 = (z k(z))^2$$ for $ z \in D$.
A: There  is a direct way to show that if an analytic function $f$ is such that the integral along any closed loop of $f'/f$ is a multiple of $2\pi i n$, then $f$ is the $n$-th power of another analytic function. The precise statement is this: Let $f\not\equiv 0$ be analytic in a domain $D$, and let $Z_f$ be the set of zeros of $f$ in $D$. Let $n\geq 2$ be an integer. If the integral of $f'/f$ along any closed path in $D\setminus Z_f$ is a multiple of $2\pi i n$, then $f$ is the $n$-th power of another analytic function in $D$. For the proof, fix $z_0\in D\setminus Z_f$, and define 
$$
h(z)=\sqrt[n]{f(z_0)}e^{\frac{1}{n}\int_{\gamma(z_0,z)}\frac{f'(w)}{f(w)}dw }, \quad z\in D\setminus Z_f ,
$$
where $\gamma(z_0,z)$ is any path in $D\setminus Z_f$ joining $z_0$ to $z$, and $\sqrt[n]{f(z_0)}$ is any $n$-th root of $f(z_0)$. This function $h$ is well-defined because if $\gamma_1(z_0,z)$ is another such path, then
$\int_{\gamma_1(z_0,z)}f'/f$ and   $\int_{\gamma(z_0,z)}f'/f$ differ by a quantity $2\pi i n k$ for some $k\in\mathbb{Z}$. Also, $h(z_0)^n=f(z_0)$.
Fix an open disk $D(z_1,r)=\{z:|z-z_1|<r\}$ contained in $D\setminus Z_f$, and a path $\gamma(z_0,z_1)$. Define for $z\in D(z_1,r)$,
$$ F(z):=\frac{1}{n}\left(\int_{\gamma(z_0,z_1)}\frac{f'}{f}+\int_{[z_1,z]}\frac{f'}{f}\right)$$
where $[z_1,z]$ is the segment with endpoints at $z_1,z$. Then $h(z)=\sqrt[n]{f(z_0)}e^{F(z)}$ on $D(z_1,r)$, and $F'(z)=\frac{f'(z)}{nf(z)}$, so that $h'(z)=\frac{h(z)f'(z)}{nf(z)}$ for $z\in D\setminus Z_f$. This implies that $[h(z)^n/f(z)]'=0$ in $D\setminus Z_f$, and so $h(z)^n/f(z)$ is constant there. Since $h(z_0)^n=f(z_0)$, that constant is $1$. Finally, if $h(z)^n=f(z)$ in $D\setminus Z_f$, $h$ is bounded near each zero of $f$, and so $h$ is analytic and has a zero at each zero of $f$. 
