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

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. Here is an exampleHere is an example by Mr. WizardMr. Wizard, provided in the comments.)

Finally, as noted by Daniel LichtblauDaniel Lichtblau in a comment, if you do want to apply the two rules to get different expressions, do this:

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. Here is an example by Mr. Wizard, provided in the comments.)

Finally, as noted by Daniel Lichtblau in a comment, if you do want to apply the two rules to get different expressions, do this:

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. Here is an example by Mr. Wizard, provided in the comments.)

Finally, as noted by Daniel Lichtblau in a comment, if you do want to apply the two rules to get different expressions, do this:

added 134 characters in body
Source Link
march
  • 24.3k
  • 2
  • 46
  • 102

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. I'll try to find an example at some point and link to itHere is an example by Mr. Wizard, provided in the comments.)

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. I'll try to find an example at some point and link to it.)

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. Here is an example by Mr. Wizard, provided in the comments.)

added 261 characters in body
Source Link
march
  • 24.3k
  • 2
  • 46
  • 102

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. I'll try to find an example at some point and link to it.)

Be(Be careful of this one, because it can run into infinite recursions.) For completeness, note that ReplaceRepeated does not act the same as a sequence of ReplaceAlls if the list of Rules are different:

a b c //. {a -> b, c -> d, b -> c}
a b c /. {a -> b} /. {c -> d} /. {b -> c}
(* d^3 *)
(* c^2 d*)

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c.

Be careful of this one, because it can run into infinite recursions.

The first replacement just replaces a with a, but since that expression has already been changed, it is ignored after that. So the Rule a -> 1 is only applied to other parts of the expression (in this case the b), and those other parts don't depend on a, so nothing changes. Finally, b gets replaced with c. (By the way, in somewhat-advanced Mathematica programming, this fact can be taken advantage of in many clever ways. I'll try to find an example at some point and link to it.)

(Be careful of this one, because it can run into infinite recursions.) For completeness, note that ReplaceRepeated does not act the same as a sequence of ReplaceAlls if the list of Rules are different:

a b c //. {a -> b, c -> d, b -> c}
a b c /. {a -> b} /. {c -> d} /. {b -> c}
(* d^3 *)
(* c^2 d*)
Source Link
march
  • 24.3k
  • 2
  • 46
  • 102
Loading