# Overbar as counter in a loop

I want to create a table with four different counters that I want to call $$a, \bar{a}, b, \bar{b}$$. For that my obvious code is

$$\text{Table}\left[p\left[a,\bar{a},b,\bar{b}\right],\{a,0,1\},\left\{\bar{a},0,1\right\},\{b,0,1\},\left\{\bar{b},0,1\right\}\right] // \text{Grid}$$

which returns

{{p[0,0,0,0],p[0,1,0,1]},{p[0,1,1,0],p[0,1,1,1]}}   {{p[0,0,0,0],p[0,1,0,1]},{p[0,1,1,0],p[0,1,1,1]}}
{{p[1,0,0,0],p[1,0,0,1]},{p[1,0,1,0],p[1,1,1,1]}}   {{p[1,1,0,0],p[1,1,0,1]},{p[1,0,1,0],p[1,1,1,1]}}


However a quick look shows that this is not the expected result - elements in the first row are repeated. If I write

Table[p[a, c, b, d] , {a, 0, 1}, {c, 0, 1}, {b, 0, 1}, {d, 0, 1}] // Grid


instead then I get the desired output. So my question is double:

1. Why does it happen?
2. How can it be fixed? That is, can I use variables such as $$\bar{a}$$ or $$a'$$ or $$a_1$$ for loops modifying something or I am forced to used other names which do not involve these symbols?
• There is ABar character. Enter it as esc a- esc not sure about BBar though. It works for ABar – OkkesDulgerci Nov 1 '20 at 12:51
• I am introducing the overbar as a ctrl+& _. Isn't it the same then? At any rate esc b- esc produces nothing. – Minkowski Nov 1 '20 at 12:53
• If you don't have use bbar then use ebar as esc e- esc – OkkesDulgerci Nov 1 '20 at 12:59
• In order to see all special character go to Palettes->Basic Math Assis->Second option at Type Setting->All Special Symbols and Character – OkkesDulgerci Nov 1 '20 at 13:02

You could give OverBar the HoldFirst attribute so that it doesn't depend on the value of a:

SetAttributes[OverBar,HoldFirst]


Then:

t1 = Table[
p[a, OverBar[a], b, OverBar[b]],
{a, 0, 1}, {OverBar[a], 0, 1}, {b, 0, 1}, {OverBar[b], 0, 1}
];
t2 = Table[p[a, c, b, d], {a, 0, 1}, {c, 0, 1}, {b, 0, 1}, {d, 0, 1}];

t1 === t2


True

The problem is that Mathematica treats OverBar as a function, so OverBar[a] is a function of your symbol a, not an independent symbol.

I would avoid using such symbols, but if the appearance is important to you, investigate the Symbolize functionality of the Notation package.