According to the Wikipedia page on Lagrange multipliers under the section - Example 3: Entropy, it is written that:
$$f(p_1,p_2,\ldots,p_n) = -\sum_{j=1}^n p_j\log_2 p_j$$
For this to be a probability distribution the sum of the probabilities
$p_i$ at each point $x_i$ must equal 1, so our constraint is:
$$g(p_1,p_2,\ldots,p_n)=\sum_{j=1}^n p_j = 1\tag{1}$$
We use Lagrange multipliers to find the point of maximum entropy, $\vec{p}^{\,*}$ across all discrete probability distributions $\vec{p}$ on $$\{x_1,x_2, \ldots, x_n\}$$ We require that:
$$\left.\frac{\partial}{\partial \vec{p}}\Big(f+\lambda (g-1)\Big)\right|_{\vec{p}=\vec{p}^{\,*}}=0\tag{2}$$
My question is simple, why is $1$ is subtracted from the constraint $(1)$, in equation $(2)$?
Put another way, I think eqn. $(2)$ should be $$\left.\frac{\partial}{\partial \vec{p}}\Big(f+\lambda g\Big)\right|_{\vec{p}=\vec{p}^{\,*}}=0,$$
However, I know that equation $(2)$ is correct as I have a similar problem regarding entropy also. In the following expression, (eqn. $(5)$), I must maximize the entropy subject to the constraints $$\mathrm{Tr}\left[\hat \rho\right]=1\tag{3}$$ and the constraint that the expectation value of the Hamiltonian, $$\mathrm{Tr}\left[\hat \rho \hat H\right]\tag{4}$$ is $E$,
$$S'=-\mathrm{Tr}\left[\hat \rho \ln \hat \rho\right]+\lambda\left(\mathrm{Tr}\left[\hat \rho \hat H-E\right]\right)+\mu\left(\mathrm{Tr}\left[\hat \rho\right]-1\right)\tag{5}$$
I just cannot understand why $1$ is being subtracted in the third term and $E$ is subtracted in the second term. This just seems non-sensical as from eqn. $(3)$ $$\mathrm{Tr}\left[\hat \rho\right]-1=0$$ so it is like $0$ is being added in as a constraint which makes no sense whatsoever to me.
Can someone please explain the logic behind putting factors of zero into the Lagrangian?
Update in response to a comment:
Since this post is not being well received I will try to clarify further by showing a 'counter-example', then, hopefully, it will become more clear why I am getting confused:
On this page for the derivation of the Boltzmann distribution it is written (amongst other things) that,
To find the most-likely configuration, we maximize $\ln\Omega_n$ subject to constraints, $$\sum_j n_j=N,\quad \sum_j \epsilon_j n_j=U\tag{6}.$$ $\fbox{$\text{Where the statistical weight is defined as } $$\Omega_n=\frac{N!}{\prod_j n_j !}$}$
Using Lagrange's method of undetermined multipliers, $$\frac{\partial}{\partial n_j}\left[\ln \Omega_n-\alpha\sum_jn_j-\beta\sum_j\epsilon_jn_j\right]=0 \,\, \forall \, j\tag{7}$$
But according to @Connor Behan (in one of the comments below this question)
"$g-1$ is the constraint"
So, this logic implies that equation $(7)$ should actually be written as
$$\frac{\partial}{\partial n_j}\left[\ln \Omega_n-\alpha\color{red}{\left(\sum_jn_j-N\right)}-\beta\color{red}{\left(\sum_j\epsilon_jn_j-U\right)}\right]=0 \,\, \forall \, j\tag{8}$$
Which by virtue of the equations in $(6)$, the terms in the parentheses marked in red are zero. Now you may see what I meant when I asked "why do we put factors of zero in the Lagrangian"
To be pedantic, my reasoning for writing what I did in that last paragraph above is because I am simply subtracting $N$ and respectively $U$ from both sides of the respective equations in $(6)$. Hence my reason for suggesting the terms marked red in $(8)$ are zero.
So, either equation $(7)$ is correct or equation $(8)$ is correct. They can't both be correct so which one is it?
Just a side note, I know that the constant terms ($N$ and $U$) in eqn. $(8)$ will differentiate to zero anyway. But what I would like to know here is the reason for the inconsistency between equations $(7)$ and $(8)$.