Put n=tP. Formula (?) gives
g_P(2tP)
=
\#\left\{
1\leq h\leq tP
\mathrel{}\middle|\mathrel{}
\gcd(h,M)=\gcd(2tP-h,M)=1
\right\}.
For every prime p_i\mid P,
p_i\mid2tP.
Therefore,
p_i\mid2tP-h
\quad\Longleftrightarrow\quad
p_i\mid h.
The same equivalence holds for the prime 2. Only the restriction contributed by the prime 3 depends on \delta_3(t).
Suppose first that \delta_3(t)=0. Write t=3u. Then
2tP=uM,
so
\gcd(2tP-h,M)=\gcd(h,M).
Consequently, g_P(2tP) is the number of integers coprime to M in the interval
1\leq h\leq tP=\frac{uM}{2}.
The reduced residues under \delta_M occur in pairs
c
\qquad\text{and}\qquad
M-c.
There is no fixed point: M/2=3P is not coprime to M. Exactly one member of each pair lies in [1,M/2]. Hence
\#\left\{
1\leq h\leq \frac M2
\mathrel{}\middle|\mathrel{}
\gcd(h,M)=1
\right\}
=
\frac{\varphi(M)}2
=
\varphi(P).
Here \varphi(M)=2\varphi(P) because M=6P and \gcd(P,6)=1. Dividing the interval [1,uM/2] into complete periods and, when necessary, one half-period gives
g_P(2tP)
=
\frac{u\varphi(M)}2
=
u\varphi(P)
=
\frac{t\varphi(P)}3.
This is the first term of (4.7), while the character term vanishes because \chi_3(t)=0.
Suppose now that \delta_3(t)\neq0. Since P is coprime to 3, one also has \delta_3(tP)\neq0. The restrictions at the primes 2 and 3 are equivalent to
\delta_2(h)=1,
\qquad
\delta_3(h)=\delta_3(tP).
Indeed, the first condition says that h is odd. Under \delta_3, the two excluded residues are 0 and \delta_3(2tP). If \delta_3(tP)=1, the remaining residue is 1, and if \delta_3(tP)=2, the remaining residue is 2.
Let \mu denote the Möbius function. Applying Möbius inversion to the condition \gcd(h,P)=1 gives
g_P(2tP)
=
\sum_{d\mid P}\mu(d)
\#
\left\{
1\leq h\leq tP
\mathrel{}\middle|\mathrel{}
d\mid h,\
\delta_2(h)=1,\
\delta_3(h)=\delta_3(tP)
\right\}.
Write
h=d\ell,
\qquad
X_d=\frac{tP}{d}.
Every divisor d of P is coprime to 6. In particular, d is odd, so the condition under \delta_2 becomes \delta_2(\ell)=1. Moreover, tP=dX_d, and multiplication by d is invertible under \delta_3. The second condition in (?) therefore becomes
\delta_3(\ell)=\delta_3(X_d).
For every positive integer X satisfying \delta_3(X)\neq0, define
R_6(X)
=
\#
\left\{
1\leq\ell\leq X
\mathrel{}\middle|\mathrel{}
\delta_2(\ell)=1,\
\delta_3(\ell)=\delta_3(X)
\right\}.
The four possible canonical residues of X under \delta_6 give
\begin{array}{c|c|c}
\delta_6(X)
& \text{admissible residue of $\ell$ under $\delta_6$}
& R_6(X)\\
\hline
1 & 1 & \dfrac{X+5}{6}\\[4pt]
2 & 5 & \dfrac{X-2}{6}\\[4pt]
4 & 1 & \dfrac{X+2}{6}\\[4pt]
5 & 5 & \dfrac{X+1}{6}
\end{array}
and hence
R_6(X)
=
\frac X6
+\frac12\mathbf 1_{\{\delta_2(X)=1\}}
+\frac{\chi_3(X)}3.
Since P/d is odd for every d\mid P, one has
\delta_2(X_d)=\delta_2(t).
Substitution of (?) therefore gives
g_P(2tP)
=
\sum_{d\mid P}\mu(d)
\left(
\frac{tP}{6d}
+\frac12\mathbf 1_{\{\delta_2(t)=1\}}
+\frac{\chi_3(tP/d)}3
\right).
Since P>1,
\sum_{d\mid P}\mu(d)=0.
Also,
\sum_{d\mid P}\mu(d)\frac{P}{d}
=
\varphi(P),
and the multiplicativity of \chi_3 gives
\sum_{d\mid P}
\mu(d)\chi_3(tP/d)
=
\chi_3(t)
\prod_{i=1}^{r}
\bigl(\chi_3(p_i)-1\bigr).
Combining these three identities proves (4.7).