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?
  • 1
    $\begingroup$ There is ABar character. Enter it as esc a- esc not sure about BBar though. It works for ABar $\endgroup$ – OkkesDulgerci Nov 1 '20 at 12:51
  • $\begingroup$ I am introducing the overbar as a ctrl+& _. Isn't it the same then? At any rate esc b- esc produces nothing. $\endgroup$ – Minkowski Nov 1 '20 at 12:53
  • $\begingroup$ If you don't have use bbar then use ebar as esc e- esc $\endgroup$ – OkkesDulgerci Nov 1 '20 at 12:59
  • 1
    $\begingroup$ In order to see all special character go to Palettes->Basic Math Assis->Second option at Type Setting->All Special Symbols and Character $\endgroup$ – 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:



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



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.


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.