4. As shown in Figure 4, the diameter $AB = d$ of semicircle $O$. $M$ and $N$ are the midpoints of $OA$ and $OB$, respectively, and point $P$ is on the semicircle. Draw $MC \parallel PN$ and $ND \parallel PM$, with points $C$ and $D$ both on the semicircle. Then $PC^2 + PD^2 + CM^2 + DN^2 =$ $\qquad$
4. $\frac{5}{8} d^{2}$.

Obviously, $O M=O N$.
As shown in Figure 9, take the midpoint $K$ of $P C$, and connect $O K$, then we have
$O K \perp P C$.
Since $O K$ is the midline of trapezoid CMNP, we have
$$
C M / / O K / / P N \text {. }
$$

Therefore, $M C \perp P C$.
Similarly, $N D \perp P D$.
Connect $P O$, since $P O$ is the median of $\triangle P M N$, then we have
$$
\begin{array}{l}
P C^{2}+P D^{2}+C M^{2}+D N^{2} \\
=\left(P C^{2}+C M^{2}\right)+\left(P D^{2}+D N^{2}\right) \\
=P M^{2}+P N^{2}=2 P O^{2}+2 O M^{2} \\
=2\left(\frac{1}{2} d\right)^{2}+2\left(\frac{1}{4} d\right)^{2}=\frac{5}{8} d^{2}
\end{array}
$$