2
$\begingroup$

Mathematica does not seem to treat variables as a unit. Consider the following:

rule = a -> Function[{x}, OverBar[a][x]]
test = a[x] /. rule;
test /. rule

It seems to apply the rule again on the last line, which of course is not what I want (in the sense that a and OverBar[a] are supposed to be different things). I tried to use the Notation package but was rather unsuccessful. Is there a way to make this work?

$\endgroup$
5
$\begingroup$

You want to replace a with Overbar[a], but only if it isn't already inside Overbar. So make Overbar[a]->Overbar[a] your first replacement rule, and it will be protected from further replacements:

rules = {OverBar[a] -> OverBar[a], a -> OverBar[a]};
test = a[x] /. rules
(* OverBar[a] *)

test /. rules
(* Overbar[a] *)
$\endgroup$
  • $\begingroup$ Very nice thank you. It seems that putting the Overbar[a]->Overbar[a] replacement last actually also work. I cannot understand what happens internally, however? $\endgroup$ – Patrick.B Jan 20 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.