What is the formal definition of a mathematical expression? I am interested in what the definition of a mathematical expression is. For example $x_1 + x_2$ is a different expression than $x_2 + x_1$, even though they both evaluate to the same function on the reals. Has anyone rigorously defined what a mathematical or algebraic expression is, so as to distinguish expressions like $x_1 + x_2$ from $x_2 + x_1$?
 A: Expression is a grammatical term in the mathematical language. It can be formally defined when it's needed for formal treatment, but normally one keeps it open so that new constructions can be added. One then first defines variables and numeric constants, and then recursively build up expressions: an expression can be a variable, a numeric constant, an expression between parentheses, an expression followed by an operation and then another expression, and so on.
You can see examples in this Wikipedia article.
A: *

*Variables are expressions

*If $f$ is an $n$-ary function and $a_1,\ldots, a_n$ are expressions, then $f(a_1,\ldots, a_n)$ is an expression

Notes:

*

*The second point  includes constants if we consider $0$-ary functions.

*For some (in particular, 2-ary) functions, we have special notations, such as $x_1+x_2$ for the sum-of-two-numbers function applied to $x_1$ and $x_2$

*If we introduce indexed variables (as we informally did above), that can be considered as a special notation of a function of the index as well

