Fold
ReplaceAll
using A custom ordering function to sort rules
sorted by a custom ordering function:
order[a_Rule, b_Rule] := (a /. b) =!= a;
expr = A^3 B^4/b + A^3 B^4 C X/d;
rules = {A^3 B^4 -> Γ, X -> ρ, A^3 B^4 C -> Δ}
{A^3 B^4 -> Γ, X -> ρ, A^3 B^4 C -> Δ}
Sort[rules, order]
{A^3 B^4 C -> Δ, X -> ρ, A^3 B^4 -> Γ}
Using ReplaceAll
with original or sorted rules does not give the desired result:
expr /. rules
Γ/b + (C X Γ)/d
expr /. Sort[rules, order]
Γ/b + (X Δ)/d
We get the desired result by Fold
ing ReplaceAll
over the sorted rules:
Fold[# /. #2 &Fold[ReplaceAll, expr, Sort[rules, order]]
Γ/b + (Δ ρ)/d
or using ReplaceRepeated
with the sorted rules:
expr //. Sort[rules, order]
Γ/b + (Δ ρ)/d
Carl's approach is the cleanest as it does not require any additional processing:
Simplify[expr, rules /. Rule -> Equal]
Γ/b + (Δ ρ)/d