How can I define Mathematica variable/function with comma in it?

For example, defineL00,1 as a variable?

I plan to use L00,1 as a variable as 00 and 1 have different meanings. Other examples are like L01,1, L10,0, etc. The purpose to comma is to separate meanings when others see it, otherwise L001 will cause confusion. I also hope to avoid l["00",1] as a variable as the " " sign will cause confusion to users not familiar with mathematica interpreting it as string. Any symbol added to the variable that serves as a separator between 00 and 1 would be fine. For example L00;1 or L00_1. But they do not work. The purpose is to inform my user (colleagues) in a reader-friendly way.

If the question is not meaningful please ignore it or inform me.

  • $\begingroup$ Subscript[a, "00", 1] = 12 $\endgroup$ – Coolwater Jun 5 '16 at 8:32
  • 2
    $\begingroup$ It's not possible. Try Symbol["L00,1"] to see the error. $\endgroup$ – Marius Ladegård Meyer Jun 5 '16 at 9:20
  • 2
    $\begingroup$ Why do you want to do this though? Is it just for formatting? $\endgroup$ – Marius Ladegård Meyer Jun 5 '16 at 9:21
  • 1
    $\begingroup$ @kww and I have already shown you two ways to do it. $\endgroup$ – Marius Ladegård Meyer Jun 5 '16 at 9:32
  • 2
    $\begingroup$ kww, this is of course possible. But to help others give you a useful answer, can you edit your question and provide some context about how you plan on using this symbol. -1 until you edit your question. $\endgroup$ – QuantumDot Jun 5 '16 at 10:58

Here is one possibility:

MakeBoxes[l[a_, b_], form_] :=  RowBox[{"l", "[", 
  ToBoxes[PaddedForm[0, NumberPadding -> {"0", "0"}]], ",", 
  ToBoxes[b], "]"}]

l[00,1] continues to display as l[00,1].

Here is another possibility:

MakeBoxes[l[a_String, b_], form_] := 
  With[{string = "\"L" <> a <> "," <> ToString[b] <> "\""}, 
  InterpretationBox[string, l[a, b]]]

l["00",1] displays as L00,1

| improve this answer | |

As it has been pointed out in the comments made to your question, using reserved symbols in identifiers is not allowed. What you can and might want to do is bind expressions to values. The arguments of the expression can serve as indices or tags to produce the kind of differentiation you want.

Here are two examples of what I am alluding to.

a["00", 1] = 3; a["10", 0] = 42;
a["00", 1]^2 + a["10", 0]


b[0, 1][x_] := 1 + Log10[x]; b[10, 0] = 42;
b[10, 0]^b[0, 1][2] // N


| improve this answer | |

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.