I have
sx = Sum[Indexed[x, i], {i, 1, 10}]^2 // Expand
It expands in sum of 55 terms, from which
- $x_i^2$ - 10 terms, actual representation: $x_1^2+x_2^2+x_3^2+...$
- $2 \cdot x_i \cdot x_{i+1}$ - 9 terms, actual representation: $2 x_1 x_2 + 2 x_2 x_3 + ...$
- $2 \cdot x_i \cdot x_{i+l}, l>1$ - all the rest, actual representation: $2 x_1 x_3 + 2 x_2 x_4 + ...$
For my calculations I need to replace terms
- => $p \cdot (1-p)$
- => 0
- => $2 \cdot p^2 \cdot (1-p)^2$
I tried to perform straight-forward
sx1 = sx /. $\{x_1^2 -> 1\}$
but nothing happened at all.
What I would like to achieve: some small easy to maintain rule formula to perform such substitutions. I saw Wolfram Mathematica is very difficult with values with subscripts. Is it possible, or should I look for some another alternative?
Thanks.
And finally I found a solution for my own problem.
Unfortunately, last statement must be edited and repeated many times to correct second subscript index. Let's say, provided example is replacing terms like $x_1 \cdot x_3, \text{... } x_8 \cdot x_{10}$ with $p^2 \cdot (1-p)^2$, while to replace other term patterns a bit different expressions are necessary. I tried to use double-indexing in Table[] function, but it creates 2D array, which is not doing what is intended.
I would like to express my appreciation to all auditory of this problem, without your help I would not get to the solution. I think this solution could be made more elegant, but I do not have yet necessary knowledge to achieve it.