Suppose I have have two kinds of variables $X_{\alpha_j}, X_{\beta_k}$ in the form of Subscript[x,Subscript[α,j]]
and Subscript[x,Subscript[β,k]]
. These two variables are embedded in a long expression for which I want to replace their symbols. Assume that I have already applied Expand
to such an expression so that the terms in question are nicely isolated.
Question: How can one write an association rule, that takes in Subscript[x,Subscript[α,j]]
and Subscript[x,Subscript[β,k]]
, and replaces them such that it satisfies all three of the following at the same time:
(1) $X_{\alpha_j} \mapsto \mu_{\alpha_j}$ and $X_{\beta_k} \mapsto \mu_{\beta_k}$; so the result should have the form Subscript[μ,Subscript[α,j]]
and Subscript[μ,Subscript[β,k]]
, respectively.
(2) $X_{\alpha_j} X_{\beta_k} \mapsto c_{\alpha_j, \beta_k} + \mu_{\alpha_j} \mu_{\beta_k}$ (and also the same map when the terms are commuted; so $X_{\beta_k} X_{\alpha_j}$ yields the same result; so the result (and its commuted form) should have the form Plus[Times[Subscript[μ,Subscript[α,j]],Subscript[μ,Subscript[β,k]]],Subscript[c,Subscript[α,j],Subscript[β,k]]]
(3) $X_{\alpha_j}^2 \mapsto \sigma_{\alpha_j}^2 + \mu_{\alpha_j}^2$ and $X_{\beta_k}^2 \mapsto \sigma_{\beta_k}^2 + \mu_{\beta_k}^2$; so the result should have the form Plus[Power[Subscript[μ,Subscript[α,j]],2],Power[Subscript[σ,Subscript[α,j]],2]]
, and Plus[Power[Subscript[μ,Subscript[β,k]],2],Power[Subscript[σ,Subscript[β,k]],2]]
, respectively.
Remark: As one may can already guess from the notations being used, I'm simply taking a sequence of random variables $X_{\alpha_j}, X_{\beta_k}$, after taking expectations, rewriting them into their conventional mean, variance and covariances. I assume the expressions in question only involve up to the usual second moments, and hence expressions like $X_{\alpha_j}^3$ or $X_{\alpha_j} X_{\beta_k}^2$ are not of a concern.