[proofplan]
We prove the result by expanding trace and matrix multiplication entrywise. The only algebraic input is commutativity of $R$, which lets us interchange the two scalar factors appearing in each product. First we prove the cyclic identity $\operatorname{tr}(XY)=\operatorname{tr}(YX)$ for arbitrary matrices $X,Y \in R^{n \times n}$, then apply it to $X=P^{-1}A$ and $Y=P$. Finally, the inverse relation $PP^{-1}=I_n$ reduces $APP^{-1}$ to $A$.
[/proofplan]
custom_env
admin
[step:Prove cyclicity of trace for two square matrices over $R$]Let $X=(x_{ij})_{1 \leq i,j \leq n} \in R^{n \times n}$ and $Y=(y_{ij})_{1 \leq i,j \leq n} \in R^{n \times n}$. By the definitions of matrix multiplication and trace,
\begin{align*}
\operatorname{tr}(XY)=\sum_{i=1}^{n}(XY)_{ii}=\sum_{i=1}^{n}\sum_{j=1}^{n}x_{ij}y_{ji}.
\end{align*}
Since $R$ is commutative, $x_{ij}y_{ji}=y_{ji}x_{ij}$ for every $i,j \in \{1,\dots,n\}$. Reindexing the finite sum by exchanging the names of $i$ and $j$ gives
\begin{align*}
\sum_{i=1}^{n}\sum_{j=1}^{n}x_{ij}y_{ji}=\sum_{j=1}^{n}\sum_{i=1}^{n}y_{ji}x_{ij}=\sum_{j=1}^{n}(YX)_{jj}=\operatorname{tr}(YX).
\end{align*}
Thus $\operatorname{tr}(XY)=\operatorname{tr}(YX)$.[/step]
custom_env
admin
[guided]Let $X=(x_{ij})_{1 \leq i,j \leq n}$ and $Y=(y_{ij})_{1 \leq i,j \leq n}$ be arbitrary matrices in $R^{n \times n}$. We want to show that the trace does not see the order of the two factors in a product. Expanding the diagonal entries of $XY$ using the definition of matrix multiplication gives
\begin{align*}
(XY)_{ii}=\sum_{j=1}^{n}x_{ij}y_{ji}
\end{align*}
for each $i \in \{1,\dots,n\}$. Therefore the trace of $XY$ is
\begin{align*}
\operatorname{tr}(XY)=\sum_{i=1}^{n}(XY)_{ii}=\sum_{i=1}^{n}\sum_{j=1}^{n}x_{ij}y_{ji}.
\end{align*}
The key point is exactly where commutativity of $R$ is used. For each pair of indices $i,j$, the entries $x_{ij}$ and $y_{ji}$ are elements of the commutative ring $R$, so
\begin{align*}
x_{ij}y_{ji}=y_{ji}x_{ij}.
\end{align*}
Substituting this into the finite double sum gives
\begin{align*}
\operatorname{tr}(XY)=\sum_{i=1}^{n}\sum_{j=1}^{n}y_{ji}x_{ij}.
\end{align*}
Because the sum is finite, we may exchange the order of summation and rename the outer index as the diagonal index of $YX$:
\begin{align*}
\sum_{i=1}^{n}\sum_{j=1}^{n}y_{ji}x_{ij}=\sum_{j=1}^{n}\sum_{i=1}^{n}y_{ji}x_{ij}.
\end{align*}
For each fixed $j$, the inner sum is precisely the $j$th diagonal entry of $YX$:
\begin{align*}
(YX)_{jj}=\sum_{i=1}^{n}y_{ji}x_{ij}.
\end{align*}
Hence
\begin{align*}
\operatorname{tr}(XY)=\sum_{j=1}^{n}(YX)_{jj}=\operatorname{tr}(YX).
\end{align*}
This proves the cyclic identity $\operatorname{tr}(XY)=\operatorname{tr}(YX)$ for two square matrices over the commutative ring $R$.[/guided]
custom_env
admin
[step:Apply cyclicity to move $P$ past $P^{-1}A$]
Define $Q \in R^{n \times n}$ by $Q=P^{-1}$. Since $A,Q,P \in R^{n \times n}$, the product $QA \in R^{n \times n}$ is defined. Applying the cyclicity identity from the previous step with $X=QA$ and $Y=P$ gives
\begin{align*}
\operatorname{tr}(P^{-1}AP)=\operatorname{tr}((QA)P)=\operatorname{tr}(P(QA)).
\end{align*}
By associativity of matrix multiplication,
\begin{align*}
P(QA)=(PQ)A.
\end{align*}
[/step]
custom_env
admin
[step:Use invertibility of $P$ to reduce the product to $A$]
Since $Q=P^{-1}$ is the inverse of $P$, it satisfies $PQ=I_n$ and $QP=I_n$, where $I_n \in R^{n \times n}$ is the identity matrix. Therefore
\begin{align*}
P(QA)=(PQ)A=I_nA=A.
\end{align*}
Combining this with the equality from the previous step yields
\begin{align*}
\operatorname{tr}(P^{-1}AP)=\operatorname{tr}(A).
\end{align*}
This is the desired similarity invariance of the trace.
[/step]