13
$\begingroup$

In order to start an index at zero, I found N. Abbasi is quite convenient. For instance,

enter image description here

(Note that in the original code by Abbasi, one of under scores _ in Notation[] was missing.)

However, with this method, we need to define these notations for each symbol. I'd like to use any symbols with subscripts, like "a" in the above pic. with the same definition.

Any help is appreciated! Thanks in advance.

$\endgroup$
2
  • $\begingroup$ See also Starting tensor indices at 0 for a more complete discussion. $\endgroup$
    – Artes
    Mar 6, 2019 at 10:23
  • $\begingroup$ Thank you for the useful info. $\endgroup$
    – Like Tina
    Mar 7, 2019 at 9:19

1 Answer 1

20
$\begingroup$

There's no need to use the Notation package to achieve the same behavior. For example:

SetAttributes[Subscript, HoldFirst];
Subscript[a_, i_Integer?NonNegative] := a[[i+1]]

Then:

a = {"Alice", "Bob"};
Subscript[a, 0]
Subscript[a, 1]

"Alice"

"Bob"

or an image:

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot! Your answer solved this perfectly! Hope this to be convenient for many users. $\endgroup$
    – Like Tina
    Mar 6, 2019 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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