Search code examples
wolfram-mathematicawolfram-languagemathics

How can I use variables with subscripts?


From Mathics, I tried:

Subscript[a, 0] = 1

but it gives the error:

Tag Subscript in Subscript[a, 0] is Protected.


Solution

  • This message means that what you are attempting to do doesn't make sense. Subscript is a system function that is protected from being inadvertently redefined, exactly as Plus (+) or any other built-in system function.

    According to:

    https://reference.wolfram.com/language/ref/Subscript.html

    Subscript is an object that formats as x_(y).

    You get the same error message as if you tried:

     Plus[a, 0] = 1
    

    Also note that lists in Wolfram Language and Mathics start at 1, not 0.

    Here is how to create list variable a with an element containing the value 1 at index 1:

    $ mathics
    
    Mathics 2.0.1.dev
    on CPython 3.8.8 (default, Feb 27 2021, 09:08:32) 
    using SymPy 1.7.1, mpmath 1.2.1, numpy 1.20.1, cython 0.29.22
    
    Copyright (C) 2011-2021 The Mathics Team.
    This program comes with ABSOLUTELY NO WARRANTY.
    This is free software, and you are welcome to redistribute it
    under certain conditions.
    See the documentation for the full license.
    
    Quit by evaluating Quit[] or by pressing CONTROL-D.
    
    In[1]:= a = {1}
    Out[1]= {1}
    
    In[2]:= a[[1]]
    Out[2]= 1
    

    Maybe https://www.wolfram.com/language/fast-introduction-for-programmers/en/lists/ and https://www.wolfram.com/language/fast-introduction-for-programmers/en/assignments/ are good places to start.