13
$\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$
10
  • 5
    $\begingroup$ Try running Select[Names["System`*"], StringLength[#] == 1 && UpperCaseQ[#] && ! StringMatchQ[ToString[FullForm[#]], "*Formal*"] &]. $\endgroup$ Jun 8, 2016 at 5:16
  • 7
    $\begingroup$ Just say no to any capital initials. $\endgroup$
    – ciao
    Jun 8, 2016 at 5:16
  • 3
    $\begingroup$ Cases[Names["System`*"], Alternatives @@ CharacterRange["A", "Z"]] $\endgroup$ Jun 8, 2016 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$ Jun 8, 2016 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$ Jun 8, 2016 at 7:07

4 Answers 4

13
$\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$
12
$\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$
11
  • 25
    $\begingroup$ It's also easy to remember: ONE D--- Never mind. $\endgroup$
    – Peltio
    Jun 8, 2016 at 5:37
  • 2
    $\begingroup$ @Peltio, don't you start. :P $\endgroup$ Jun 8, 2016 at 5:41
  • $\begingroup$ @AHB What does "type the capital alphabet" mean? I can't get this to work. $\endgroup$
    – David
    Jun 8, 2016 at 18:02
  • 3
    $\begingroup$ He's telling you to type each capital letter manually in each cell, @David. $\endgroup$ Jun 8, 2016 at 18:26
  • 1
    $\begingroup$ ( Permutations[{"E","N","I","O","K","C","D"}] //Map[StringJoin] //Map[ Select[SpellingCorrectionList@#, x|->ContainsExactly[ DeleteCases[" "]@Characters@x, Characters@# ] ]& ] //DeleteDuplicates ) $\endgroup$ Dec 23, 2022 at 10:58
8
$\begingroup$

With a fresh kernel, use

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

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

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

Hope this can help.

$\endgroup$
4
  • $\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, 2016 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, 2016 at 19:17
  • $\begingroup$ Sorry @David ,maybe I miss something yesterday.And I have a verification just now. $\endgroup$
    – yode
    Jun 8, 2016 at 23:45
  • $\begingroup$ @yode No need to be sorry. That worked. I totally appreciate your help. $\endgroup$
    – David
    Jun 9, 2016 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.