Expression (mathematics)
In mathematics, an expression is an arrangement of symbols following the context-dependent, syntactic conventions of mathematical notation. Symbols can denote numbers, variables, operations, and functions. Other symbols include punctuation marks and brackets, used for grouping where there is not a well-defined order of operations.
Expressions are commonly distinguished from formulas: expressions usually denote mathematical objects, whereas formulas are statements about mathematical objects. This is analogous to natural language, where a noun phrase refers to an object, and a whole sentence refers to a fact. For example, and are both expressions, while the inequality is a formula. However, formulas are often considered as expressions that can be evaluated to the Boolean values true or false.
To evaluate an expression means to find a numerical value equivalent to the expression. Expressions can be evaluated or simplified by replacing operations that appear in them with their result. For example, the expression simplifies to, and evaluates to
An expression is often used to define a function, by taking the variables to be arguments, or inputs, of the function, and assigning the output to be the evaluation of the resulting expression. For example, and define the function that associates to each number its square plus one. An expression with no variables would define a constant function. Usually, two expressions are considered equal or equivalent if they define the same function. Such an equality is called a "semantic equality", that is, both expressions "mean the same thing."
Elementary mathematics
Variables and evaluation
In elementary algebra, a variable in an expression is a letter that represents a number whose value may change. To evaluate an expression with a variable means to find the value of the expression when the variable is substituted with given number. Expressions can be simplified by replacing operations that appear in them with their result, or by combining like-terms. The evaluation of an expression consists of repeating simplification steps until getting eventually a single number.For example, take the expression ; it can be evaluated for in the following steps:
,
A term is a constant or the product of a constant and one or more variables. Some examples include The constant of the product is called the coefficient. Terms that are either constants or have the same variables raised to the same powers are called like terms. If there are like terms in an expression, one can simplify the expression by combining the like terms. One adds the coefficients and keeps the same variable.
Any variable can be classified as being either a free variable or a bound variable. For a given combination of values for the free variables, an expression may be evaluated, although for some combinations of values of the free variables, the value of the expression may be undefined. Thus an expression represents an operation over constants and free variables and whose output is the resulting value of the expression.
For a non-formalized language, that is, in most mathematical texts outside of mathematical logic, for an individual expression it is not always possible to identify which variables are free and bound. For example, in, depending on the context, the variable can be free and bound, or vice-versa, but they cannot both be free. Determining which value is assumed to be free depends on context and semantics.
Equivalence
An expression is often used to define a function, or denote compositions of functions, by taking the variables to be arguments, or inputs, of the function, and assigning the output to be the evaluation of the resulting expression. For example, and define the function that associates to each number its square plus one. An expression with no variables would define a constant function. In this way, two expressions are said to be equivalent if, for each combination of values for the free variables, they have the same output, i.e., they represent the same function. The equivalence between two expressions is called an identity and is sometimes denoted withFor example, in the expression the variable is bound, and the variable is free. This expression is equivalent to the simpler expression ; that is The value for is 36, which can be denoted
Well-defined expressions
The language of mathematics exhibits a kind of grammar about how expressions may be written. There are two considerations for well-definedness of mathematical expressions, syntax and semantics. Syntax is concerned with the rules used for constructing, or transforming the symbols of an expression without regard to any interpretation or meaning given to them. Expressions that are syntactically correct are called well-formed. Semantics is concerned with the meaning of these well-formed expressions. Expressions that are semantically correct are called well-defined.Well-formed
The syntax of mathematical expressions can be described somewhat informally as follows: the allowed operators must have the correct number of inputs in the correct places, the sub-expressions that make up these inputs must be well-formed themselves, have a clear order of operations, etc. Strings of symbols that conform to the rules of syntax are called well-formed, and those that are not well-formed are called, ill-formed, and do not constitute mathematical expressions.For example, in arithmetic, the expression 1 + 2 × 3 is well-formed, but
is not.
However, being well-formed is not enough to be considered well-defined. For example in arithmetic, the expression is well-formed, but it is not well-defined. Such expressions are called undefined.
Well-defined
is the study of meaning. Formal semantics is about attaching meaning to expressions. An expression that defines a unique value or meaning is said to be well-defined. Otherwise, the expression is said to be ill defined or ambiguous. In general the meaning of expressions is not limited to designating values; for instance, an expression might designate a condition, or an equation that is to be solved, or it can be viewed as an object in its own right that can be manipulated according to certain rules. Certain expressions that designate a value simultaneously express a condition that is assumed to hold, for instance those involving the operator to designate an internal direct sum.In algebra, an expression may be used to designate a value, which might depend on values assigned to variables occurring in the expression. The determination of this value depends on the semantics attached to the symbols of the expression. The choice of semantics depends on the context of the expression. The same syntactic expression 1 + 2 × 3 can have different values, depending on the order of operations implied by the context.
For real numbers, the product is unambiguous because ; hence the notation is said to be well defined. This property, also known as associativity of multiplication, guarantees the result does not depend on the sequence of multiplications; therefore, a specification of the sequence can be omitted. The subtraction operation is non-associative; despite that, there is a convention that is shorthand for, thus it is considered "well-defined". On the other hand, Division is non-associative, and in the case of, parenthesization conventions are not well established; therefore, this expression is often considered ill-defined.
Unlike with functions, notational ambiguities can be overcome by means of additional definitions. For example, in the programming language C, the operator
- for subtraction is left-to-right-associative, which means that a-b-c is defined as -c, and the operator = for assignment is right-to-left-associative, which means that a=b=c is defined as a=. In the programming language APL there is only one rule: from right to left – but parentheses first.Formal definition
The term 'expression' is part of the language of mathematics, that is to say, it is not defined within mathematics, but taken as a primitive part of the language. To attempt to define the term would not be doing mathematics, but rather, one would be engaging in a kind of metamathematics, usually mathematical logic. Within mathematical logic, mathematics is usually described as a kind of formal language, and a well-formed expression can be defined recursively as follows:The alphabet consists of:
- A set of individual constants: Symbols representing fixed objects in the domain of discourse, such as numerals, sets, truth values, etc.
- A set of individual variables: A countably infinite amount of symbols representing variables used for representing an unspecified object in the domain.
- A set of operations: Function symbols representing operations that can be performed on elements over the domain, like addition, multiplication, or set operations like union, or intersection.
- Brackets
- Any constant or variable as defined are the atomic expressions, the simplest well-formed expressions. For instance, the constant or the variable are syntactically correct expressions.
- Let be a metavariable for any n-ary operation over the domain, and let be metavariables for any WFE's.
Computer science
In computer science, an expression is a syntactic entity in a programming language that may be evaluated to determine its value or fail to terminate, in which case the expression is undefined. It is a combination of one or more constants, variables, functions, and operators that the programming language interprets and computes to produce another value. This process, for mathematical expressions, is called evaluation.In simple settings, the resulting value is usually one of various primitive types, such as string, Boolean, or numerical.
In computer algebra, formulas are viewed as expressions that can be evaluated as a Boolean, depending on the values that are given to the variables occurring in the expressions. For example takes the value false if is given a value less than 1, and the value true otherwise.
Expressions are often contrasted with statements—syntactic entities that have no value.
Except for numbers and variables, every mathematical expression may be viewed as the symbol of an operator followed by a sequence of operands. In computer algebra software, the expressions are usually represented in this way. This representation is very flexible, and many things that seem not to be mathematical expressions at first glance, may be represented and manipulated as such. For example, an equation is an expression with "=" as an operator, a matrix may be represented as an expression with "matrix" as an operator and its rows as operands.
See: Computer algebra expression