0

I'm really new with Mathematica, and I could not find a previously question similar to this one.

Is there a way that Mathematica can be made to recognize and treat a subscript letter as variable so that I could write equations like:

$\qquad a_{n} = n + 1 $

and have the evaluation of $a_{5}$ return 6.

Note: I'm actually trying to write equation for commutators like $[L_n,\, L_m] = n - m$

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574

1 Answers1

5

I would strongly recommend not using Subscript. One should think of Subscript as a typographical construct (which can be abused to use subscripting of a variable). Better is to use: L[n]

comm[L[n_], L[m_]] := n - m

Then you can call the function like this:

comm[L[15], L[8]]
7

SHuisman
  • 3,258
  • 8
  • 12
  • Yeah, I actually got a way do use subscript as variable, but the program was 10 times slower, so I gave up and used your idea.

    Thanks for answering!

    – bruno henrique Sep 07 '19 at 04:46