Functions
A function is defined by an operator of sort
Function application is denoted by square brackets:
Functions can be composed:
The application of a composed function is defined by:
Example
Uses
The function
computes the square of its argument:
Application:
Application of the squaring function composed with itself:
Functions vs. operators
The squaring function could have equally well be defined as an operator:
Either choice has advantages and disadvantages.
The advantage of the operator is that it can be specialized for subsorts. For example, we could add
The advantage of the function is that it is a term on its own that can be used without arguments. See for example the definition of the derivative in Derivatives of real functions of one variable.
Contravariance of the domain sort
In the sort declaration
the domain sort parameter is marked as
contravariant
, which means that in subsort tests, its sort hierarchy is inverted. This is best illustrated by an example, which uses
Consider an operator
Can we apply this operator to a function from integers to integers? Let's try:
The resulting term does not have a proper sort, so something went wrong. Let's try something else: a function from real numbers to integers:
This yields a proper term with a proper sort. A function from real numbers to integers is indeed also a function from rational numbers to rational numbers: it accepts any rational number as its argument (plus more, but we don't care about this), and it produces a rational number (more precisely, an integer, but we don't care about this precision).