Listing elements starting from 0

Two possible options:

option 1

ClearAll[v]
Needs["Notation`"]
len = 5;
v = RandomReal[{0, 1}, len];

And now add notation to shift the indes

Notation[NotationTemplateTag[
     Subscript[v, i_]] \[DoubleLongLeftRightArrow] 
           NotationTemplateTag[v[[(i_) + 1]]]]

The above looks like this in the notebook

Mathematica graphics

And now use the subscripted version for the zero index:

{Subscript[v, 0], v[[1]]}
  (* {0.313776, 0.313776} *)

Hence the Do loop from zero

Mathematica graphics

Option 2

For each list v defined a v0 function

ClearAll[v]
v0[i_] := v[[i + 1]]

And when you want zero index, use v0 instead of v

len = 5;
v = RandomReal[{0, 1}, len];
Do[Print@v0[i], {i, 0, len - 1}]

I myself would not use either of these, since they confuse the code. I would just use Mathematica with 1 index as is and change the looping to account for this. But you can decide if these will work for you or not.


This is comparable to Option 1 from Nasser, but a bit simpler to implement. Try redefining the Subscript symbol to a function, i.e.

Subscript[a_,b_]:=a[[b+1]];
c=Range[10];

Enter c then "ctrl -" for the subscript shortcut then your index number. Execute to return the zero indexed list value. This get's the same simple input syntax as Nasser's answer without the extra package loading.


As another work around, you can create a function

idx[i_]:=i+1

and then say

v[[idx[0]]]

This is similar to indirect addressing.

Also, if it's not important to be able to treat the objects as arrays, you can simply do something like

v[0] = something

where the single [bracket] sets a DownValue.