11
$\begingroup$

I'm trying to search for an answer to "What is the complete list of single capital letters that represent built-in Mathematica commands, symbols, or uses?"

For example:

C, D, E, I, N, O

Is this the complete list? I'm teaching linear algebra in the fall, and I will warn students about using variable names that start with capital letters, but I'd also like to be specific about which particular letters will cause a problem.

$\endgroup$
  • 5
    $\begingroup$ Try running Select[Names["System`*"], StringLength[#] == 1 && UpperCaseQ[#] && ! StringMatchQ[ToString[FullForm[#]], "*Formal*"] &]. $\endgroup$ – J. M. is away Jun 8 '16 at 5:16
  • 7
    $\begingroup$ Just say no to any capital initials. $\endgroup$ – ciao Jun 8 '16 at 5:16
  • 3
    $\begingroup$ Cases[Names["System`*"], Alternatives @@ CharacterRange["A", "Z"]] $\endgroup$ – Algohi Jun 8 '16 at 5:38
  • 1
    $\begingroup$ I have edited your comment, @Algohi; the trick is to enclose any snippet with a backtick within two sets of backticks. $\endgroup$ – J. M. is away Jun 8 '16 at 5:41
  • 1
    $\begingroup$ However, note, that K is the only one among standard latin capitals that is not Protected. Also, some of the one-letter formal symbols are System` symbols, but not all: compare Attributes@{\[FormalPhi], \[FormalCurlyPhi]} (see here). $\endgroup$ – István Zachar Jun 8 '16 at 7:07
10
$\begingroup$

To convert my comment into an answer: one can naively run Select[Names["System`*"], StringLength[#] == 1 &] to pick out built-in symbols that are only one character long. This will work in older versions of Mathematica, but ever since the introduction of formal symbols (which are, to be fair, in the System`​ context and are one-character expressions as well), this needs to be finessed further. Thus, we must add extra criteria to filter out the classical list of reserved capital letters (as of the current version):

Select[Names["System`*"], StringLength[#] == 1 &&
                          UpperCaseQ[#] &&
                          StringFreeQ[CharacterName[#], "Formal"] &]
   {"C", "D", "E", "I", "K", "N", "O"}

A (more expensive) alternative uses the new entity framework through WolframLanguageData[] like so:

Select[WolframLanguageData[], StringLength[CanonicalName[#]] == 1 &] // CanonicalName
   {"N", "C", "I", "O", "D", "E"}

but this misses K, which is the arbitrary index used for explicit sums and products returned as solutions by symbolic functions (akin to the use of C as an arbitrary constant). (Try e.g. RSolve[x[k + 1] == x[k] Prime[k], x, k].)

$\endgroup$
10
$\begingroup$

They are:

C D E I K N O

It's easy to know. Just open a notebook and type the capital alphabet. Those changing color to black are protected.

ans

$\endgroup$
  • 22
    $\begingroup$ It's also easy to remember: ONE D--- Never mind. $\endgroup$ – Peltio Jun 8 '16 at 5:37
  • 2
    $\begingroup$ @Peltio, don't you start. :P $\endgroup$ – J. M. is away Jun 8 '16 at 5:41
  • $\begingroup$ @AHB What does "type the capital alphabet" mean? I can't get this to work. $\endgroup$ – David Jun 8 '16 at 18:02
  • 3
    $\begingroup$ He's telling you to type each capital letter manually in each cell, @David. $\endgroup$ – J. M. is away Jun 8 '16 at 18:26
  • $\begingroup$ @J.M Aha! I get it. Thanks to both of you. $\endgroup$ – David Jun 9 '16 at 4:08
7
$\begingroup$

With a fresh kernel, use

Select[CharacterRange["A", "Z"], NameQ]

{"C", "D", "E", "I", "K", "N", "O"}

$\endgroup$
6
$\begingroup$
Quiet[Select[CharacterRange["A", "Z"], Context[#] == "System`" &]]
{C, D, E, I, K, N, O}

Hope this can help.

$\endgroup$
  • $\begingroup$ This did not work for me. I entered Select[CharacterRange["A", "Z"], UnsameQ[Context[#], $Context] &] and got things like: Context::notfound: Symbol A not found. >> and General::stop: Further output of Context::notfound will be suppressed during this calculation. >> even though I first quit the kernel. $\endgroup$ – David Jun 8 '16 at 18:00
  • $\begingroup$ In Mathematica 10.4 I needed to add ToExpression thus Select[ToExpression /@ CharacterRange["A", "Z"], UnsameQ[Context[#], $Context] &] $\endgroup$ – mikado Jun 8 '16 at 19:17
  • $\begingroup$ Sorry @David ,maybe I miss something yesterday.And I have a verification just now. $\endgroup$ – yode Jun 8 '16 at 23:45
  • $\begingroup$ @yode No need to be sorry. That worked. I totally appreciate your help. $\endgroup$ – David Jun 9 '16 at 4:05

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.