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$

1 Answer 1

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$
1
  • $\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$ Commented Jan 20, 2019 at 15:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.