Thanks, Sander. My first vote!
This might be the final post. Some rigorous testing needs to be done, so if you can find an error, please respond.
The last post was in error about the correct format. Here is the way it looks now:
ReplaceOnly[expr_, var_ -> subst_] :=
Module[{e, e1, e2, var?},
var? := var^? // PowerExpand;
e := expr /. var -> var?;
e1 := e // PowerExpand;
e2 := e1 /. var? -> subst;
e2 /. ? -> 1
]
ReplaceOnly[expr_, {rules__}] :=
Module[{e, e1, e2, vars, subst, vars?},
vars := First[List @@ (Thread[{rules}, Rule])];
subst := Last[List @@ (Thread[{rules}, Rule])];
vars? := vars^? // PowerExpand;
(*Print["1 ",vars?,subst];*)
e := expr /. Thread[Rule[vars, vars?]];
(*Print["2 ",Thread[Rule[vars,vars?]]];*)
(*Print["3 ",e];*)
e1 := e // PowerExpand;
e2 := e1 /. Thread[Rule[vars?, subst]];
e2 /. ? -> 1
]
It turns out that the proposed ///. operator doesn't work because it is parsed into // /. I tried . but that is the prefix for an octal number. Suggestions for other operators ?
<<Notation`
InfixNotation[>>>,ReplaceOnly]
(*testing*)
3 x^3+x +y>>>(x->ss)
ss+3 x^3+y
3 x^3+x +y>>>{x->ss,x^3->XX,y->x}
ss+x+3 XX
Unfortunately, when using a single replacement, the rhs has to be parenthesized. This probably has something to do with precedence. Any ideas?
Attachments: