3
$\begingroup$

I made a summary of the rules for formation of types for simple 1-position expressions, as I understand them.

Here it is in textual form:

  • A symbol, say, α, is a discrete entity, represented by a unique string of characters
  • A type is created from a symbol, or from another type, with the operator [] (column Type, downwards in the table)
  • In the other "direction" (upwards in the table, column Head), the head of a type is an operation of reading a label, in the form of a symbol, from an expression. Despite being "in the other direction", it is not a dual of creating a type, as creating a type returns an expression, and reading a head returns a symbol.
  • So, for example: the head of x[][] is x[], the head of x[] is x, etc.. On the other direction, adding [] to x creates a type x[], to x[] creates a type x[][], and so on.
  • The head of a symbol without brackets x is the symbol Symbol, common head of all symbols without brackets
  • The head of Symbol is also just Symbol itself, so, in a way, Symbol is the "root" symbol of the "hierarchy"
  • Being a "root", a type is exceptionally created from Symbol by also specifying its identifying string: Symbol["name"], which is the symbol name.

Here is a table representation:

Expression Head ↑ Type ↓
Symbol Symbol α
α Symbol α[]
α[] α α[][]
α[][] α[] α[][][]

Are these rules correct?

$\endgroup$

1 Answer 1

3
$\begingroup$

I don't think your table is necessarily incorrect, but I don't think it's the best way to think about it. In Mathematica, everything is an expression (see the linked tutorial for more details). Every1 expression is one of two things:

  • Atomic: Things like numbers, symbols, etc. AtomQ[expr] returns True, and the head is not necessarily "part" of the expression: Head[x] is Symbol, Head[1] is Integer, etc.
    • Symbols have a name and context, retrievable by SymbolName and Context, respectively. A symbol can be created from its textual representation using Symbol or ToExpression, where the latter also works for all other types, e.g. integers. The "exceptional" behavior of creating new symbols using Symbol is more of a convenient "overload" of the symbol Symbol rather than a deeper property in my mind. For example, Rational[3/4] will return 3/4, which has head Rational (but Integer[3] is not 3).
  • Composite: Everything else. The form is head[arg1,…], where each of head, arg1,… can themselves be any expression (of course, there can also be no arguments). AtomQ[head[…]] returns False, Head[head[…]] returns head2.

Side note: I don't really know what you mean with "type" but it is not commonly used when talking about Mathematica.

1There are some subtleties regarding stuff like System`Private`SetNoEntry, but ignore that for now

2If the expression is not evaluated further

$\endgroup$
0

Your Answer

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

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