Fermi level and chemical potential in doped and pure semiconductors Recently I was studying about band theory of semiconductors and I have some questions.
I found two definitions of Fermi level
$1)$ The quantum state which has a probability of occupancy of $0.5$
(from my book)
$2)$ The Fermi level of a body is the thermodynamic work required to add one electron to the body 
(from Wikipedia)
Everywhere the Fermi level of a semiconductor is talked about, its done on the basis of the $1$st definition and the Fermi-Dirac probability distribution.
My question is if the Fermi level of a semiconductor can be defined in terms of the $2$nd definition (also known as the chemical potential of the system) or does this definition fail when talking about semiconductors because in semiconductors (both doped and pure) the Fermi level lies in the band-gap and that confuses me because how can an electron in the highest occupied state in valence band (please assume at $0$K) have energy corresponding to somewhere in the band gap.
My second doubt is that in an extrinsic semiconductor, (both p-type and n-type), the extrinsic Fermi level is also defined in terms of the 1st definition everywhere.
(Please note I am assuming at $0$K)
But if we consider the $2$nd definition using the chemical potential, shouldn't the Fermi level (in a p-type doped) rise above the intrinsic Fermi level instead of being somewhere in the middle of the acceptor and the valence band?
Because in the case of doped semiconductors, no matter p-type or n-type,  we're adding dopant atoms into the system which now has more atoms, and hence more electrons in addition to that of the electrons in the valence band of the intrinsic semiconductor so we are adding more energy to the system in the process of adding those additional electrons of the dopant and it should shift the Fermi level above the middle (intrinsic level). 
But it doesn't happen since Fermi level of a p-type doped semiconductor lies far below the intrinsic level near the valence band(somewhere in the middle of the acceptor and the valence band, to be precise)   so it's sure that I'm missing something.
Why does nobody want to talk in terms of chemical potential?
I found some other posts some of which are this and this. I also went through them but I think no one actually addresses this.
Please try to answer in terms of chemical potential rather than redefining Fermi level in terms of the Fermi-Dirac probability distribution. That will be very helpful to me.
I tried a lot but couldn't get what's going. Please help me to understand this thing.
Thank you very much :)
 A: You're right that this can be a tricky point if there is a gap, and I think that a number of common definitions fail in this case. It gets even trickier at zero temperature.
Let me give an alternative definition: the chemical potential (Fermi level) $\mu$ is a normalization constant that makes the following equation true:
$$N = \int \mathrm{d}E \, g\left(E\right) \frac{1}{e^{\frac{E-\mu}{k_B T}}+1},$$
where $N$ is the number of particles in your system and $g\left(E\right)$ is the density of states.
If the system has a gap, at zero temperature, $\mu$ need not be uniquely defined. At zero temperature
$$N = \int \mathrm{d}E \, g\left(E\right) H\left(\mu-E\right),$$
where $H$ is the step function.
Since $g\left(E\right) = 0 $ for $E$ in the gap, it doesn't matter what value $H$ has in the gap. So, if $\mu$ falls somewhere in the gap, it could just as well fall anywhere else in the gap.
Note that this peculiarity only exists at zero temperature! At any other temperature, the definition will give you a well defined $\mu$. So, I wouldn't get hung up on the zero temperature case. Note that, in simple cases, the above definition will agree with the ones you listed.
A: For ordinary semiconductors there is not much of a problem. The real problem occurs with compounds where correlation is important.
For example in free atoms there is a difference between adding an electron (the electron affinity) and removing an electron (the ionization energy). Same with molecules: the HOMO (highest occupied molecular orbital) and the LUMO (lowest unoccupied molecular orbital). It plays a role in correlated oxides like NiO.
In semiconductors like silicon it does not really matter. There will always be surface states that are partially occupied. States that are in the gap of the band structure of the bulk (dangling bonds etc) that will pin the Fermi level.
And although Fermi level is only defined at 0 K, in semiconductor terminology it is also used at higher temperatures where the correct term would be chemical potential. So while doping will put the low-temperature Fermi level at a band edge, raising the temperature high enough will put it near the middle of the gap, when the concentration of thermally generated holes and electrons is comparable.
