Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an expression with subscripted variables. I would like to replace all those terms with other symbols. For example,

$P_1 + P_2^3 \rightarrow P1 + P2^3$

I used the following code but it doesn't work

X = Subscript[P, 1] + Subscript[P, 3]^2 - I*Subscript[P, 5]
X /. {Subscript[P, n_] -> Pn}

If I replace Subscript[P, n_] with P[n] then it works (e.g. $P_1$ will be replaced with P[1]) but I don't want the bracket. I want P1 instead. Is there any way to solve this?

share|improve this question
up vote 9 down vote accepted

Instead of Pn use Symbol["P"<>ToString[n]]

share|improve this answer
X /. Subscript[x_, y_] :> Symbol[StringJoin@(ToString /@ {x, y})]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.