I have a polynomial in $\rho$ with many parameters (I will omit the polynomial code in the Mathematica expressions below because it is too long):
$$ \rho ^3 J (\mu +1) \left[(A \delta \tau _0+B (1-\delta ) \tau _1\right]+ \rho ^2 \left[\left(A \delta \tau _0+B (1-\delta ) \tau _1\right) \left((\mu +1) V_B-J\right)+A (1-\delta ) J (\mu +1) \tau _0+B \delta J (\mu +1) \tau _1+\delta \mu ^2 \tau _0+(1-\delta ) \mu ^2 \tau _1\right]+ \rho \left[A (1-\delta ) \tau _0 \left((\mu +1) V_B-J\right)-V_B \left(A \delta \tau _0+B (1-\delta ) \tau _1\right)+B \delta \tau _1 \left((\mu +1) V_B-J\right)+(1-\delta ) \mu ^2 \tau _0+\delta \mu ^2 \tau _1\right] -A (1-\delta ) \tau _0 V_B-B \delta \tau _1 V_B $$
Notice that $B$ is both a parameter and an index for $V_B$.
Say I saved this polynomial in p
, then when I use Replace
using levelspec
, such as:
Replace[p, {δ -> 0, B -> 0}, 6]
Mathematica substitutes both $B$ in the coefficients and in the subscripts (why would anyone want this?):
$$ \rho \left(A \tau _0 \left((\mu +1) V_B-J\right)+\mu ^2 \tau _0\right)+\rho ^2 \left(A J (\mu +1) \tau _0+\mu ^2 \tau _1\right)-A \tau _0 V_0 $$
Notice now there's a $V_0$ and a $V_B$. If I don't use levelspec
, and use /.
instead, all $B$ are replaced, in all indices (which is obvisouly what I do not want).
How to avoid subscripts substitution?
polynomial code is here:
p=-A (1 - δ) Subscript[V, B] Subscript[τ, 0] - B δ Subscript[V, B] Subscript[τ, 1] + J (1 + μ) ρ^3 (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]) + ρ ((1 - δ) μ^2 Subscript[τ, 0] + A (1 - δ) (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 0] + δ μ^2 Subscript[τ, 1] + B δ (-J + (1 + μ) Subscript[V, B]) Subscript[τ, 1] - Subscript[V, B] (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ,1])) + ρ^2 (δ μ^2 Subscript[τ, 0] + A J (1 - δ) (1 + μ) Subscript[τ, 0] + (1 - δ) μ^2 Subscript[τ, 1] + B J δ (1 + μ) Subscript[τ, 1] + (-J + (1 + μ) Subscript[V, B]) (A δ Subscript[τ, 0] + B (1 - δ) Subscript[τ, 1]))