Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

Due to the traversal ordertraversal order of ReplaceAll the rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

Due to the traversal order of ReplaceAll the rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

Due to the traversal order of ReplaceAll the rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

added 108 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

TheDue to the traversal order of ReplaceAll the rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

The rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

You wish to make substitutions in all except Subscript expressions I believe. This can be done by leveraging the precedence of replacement rules, like this:

{p, Subscript[p, 1], Subscript[p, 2]} /. {x_Subscript :> x, p -> 1}
{1, Subscript[p, 1], Subscript[p, 2]}

Due to the traversal order of ReplaceAll the rule x_Subscript :> x acts first, "replacing" any expression with the head Subscript by itself. Since expressions that have already been replaced are not matched again, the second rule p -> 1 is never applied to these subexpressions.

[Edit removed during grace period]
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading