## 4 Proposed Alternating Optimization Algorithm to Minimize MSE
### Algorithm Summary and Analysis  
Algorithm 1 outlines the proposed AO algorithm for the precoding matrix and IRS configuration matrix. For simplicity, we assume that each IRS unit is paired with a matched LED and PD, ensuring that every unit of the IRS is utilized. Steps 1 to 2 initialize \(\mathbf{W}^{(0)}\) and \(\mathbf{V}^{(0)}\). In Steps 3 to 10, the algorithm iteratively addresses the two convex subproblems, \(\mathcal{P}3-a\) and \(\mathcal{P}3-b\), refining and updating \(\mathbf{W}^{(r+1)}\) and \(\mathbf{V}^{(r+1)}\). This iterative process continues until the MSE difference between successive iterations falls below a predefined threshold, indicating convergence. Finally, we discretize the obtained matrix \(\mathbf{V}\) into binary variables based on (42) and (43) to derive \(\mathbf{F}\) and \(\mathbf{R}\).  
Next, we discuss the algorithmic complexity of Algorithm 1. The convergence of the proposed AO algorithm is guaranteed by the convexity of the two subproblems. Specifically, let \(\mathbf{V}^{(r)}\) and \(\mathbf{W}^{(r)}\) denote the relaxed configuration matrix and the precoding matrix at the \(r\)-th iteration, respectively. In the subsequent iteration, \(\mathbf{W}^{(r+1)}\) is obtained by solving \(\mathcal{P}3-a\), leading to the inequality \(\text{MSE}\Big{(}\mathbf{W}^{(r+1)},\mathbf{V}^{(r)}\Big{)}\leq\text{MSE} \Big{(}\mathbf{W}^{(r)},\mathbf{V}^{(r)}\Big{)}\). Similarly, solving problem \(\mathcal{P}3-b\) yields \(\mathbf{V}^{(r+1)}\), which results in the inequality \(\text{MSE}\Big{(}\mathbf{W}^{(r+1)},\mathbf{V}^{(r+1)}\Big{)}\leq\text{MSE} \Big{(}\mathbf{W}^{(r+1)},\mathbf{V}^{(r)}\Big{)}\). Consequently, after several iterations, the value of MSE converges to a non-negative value.  
The complexity of Algorithm 1 is influenced by the number of iterations required for the two subproblems and the number of matrix operations performed in each iteration. Given a precision of \(\varepsilon\), the number of iterations needed to obtain the globally optimal solution for subproblem \(\mathcal{P}3-a\) is \(\mathcal{O}\Big{(}(MK)^{2}\log(1/\varepsilon)\Big{)}\), where \(M,K\) are the dimensions of \(\mathbf{W}\). The time complexity of the interior point method for each iteration is \(\mathcal{O}\big{(}MK^{2}\big{)}\)[41]. Therefore, the overall complexity of \(\mathcal{P}3-a\) is \(\mathcal{O}\big{(}M^{3}K^{4}\log(1/\varepsilon)\big{)}\). Similarly, the overall complexity for \(\mathcal{P}3-b\) is \(\mathcal{O}\Big{(}N^{3}(MK)^{4}\log(1/\varepsilon)\Big{)}\). Consequently, the total complexity of \(\  
```
Input: channel vectors \(\mathbf{h}_{k}\), the maximum iteration number \(R_{max}\), the iteration number \(r\gets 0\), IRS unit index \(n\gets 1\), the accuracy \(\epsilon\). Output: IRS matrices \(\mathbf{F}\),\(\mathbf{R}\), precoding matrix \(\mathbf{W}\)
1 Initialize the IRS configuration auxiliary matrix \(\mathbf{V}^{(r)}\), assuming that each IRS unit is paired with a LED/PD pair;
2 Initialize the precoding matrix \(\mathbf{W}^{(r)}\);
3 while\(r\leqslant R_{max}\)do
4 repeat
5 Using the CVX toolbox to address \(\mathcal{P}3-a\);
6 Update \(\mathbf{W}^{(r+1)}\) under fixed \(\mathbf{V}^{(r)}\);
7 Using the CVX toolbox to address \(\mathcal{P}3-b\);
8 Update \(\mathbf{V}^{(r+1)}\) under fixed \(\mathbf{W}^{(r+1)}\);
9 Update \(r\gets r+1\);
10 Compute \(\Delta=\left|\text{MSE}^{(r)}-\text{MSE}^{(r-1)}\right|\);
11 until\(\Delta\leq\epsilon\);
12 repeat
13 Calculate the optimal index \(p^{*}\) by (41);
14 if\(p^{*}\
eq 0\)then
15 Calculate the paired LED coordinates \(m\) through (42);
16 Set the configuration matrix \(\mathbf{R}:r_{n,m}\gets 1\) and \(r_{n,j\
eq m}\gets 0,\forall j\in\mathcal{M}\);
17 Calculate the paired PD coordinates \(k\) through (43);
18 Set the configuration matrix \(\mathbf{F}:f_{n,k}\gets 1\) and \(f_{n,j\
eq k}\gets 0,\forall i\in\mathcal{K}\);
19 else
20 Set the \(n\)-th row of \(\mathbf{F}\) and \(\mathbf{R}\) to the zero vector;
21 Update IRS unit index \(n\gets n+1\);
22 until\(n>N\);
```  
**Algorithm 1**Proposed precoding and IRS optimization algorithm