Chapter 11. Computation as Action

Clearly, a computation (such as the evaluation of a function expression) is a certain form of action, either a cognitive action in the case of a human performer or a computational action in the case of a computer as performer. However, mathematics abstracts away from the procedural semantics of computations and assumes a purely declarative semantics for functions (based on their extensions).

KerML has chosen a procedural semantics for the evaluation of a function expression,

11.1. Functions

Functions are Behaviors with one out parameter designated as the result parameter. Functions classify evaluations, which are kinds of performances that produce results as values of the result parameter. Like all Behaviors, Functions can change things, often referred to as "side effects". A pure Function is one that has no side effects and always produces the same results given the same input values, similarly to a function in the mathematical sense.

Viewing functions as action types corresponds to the procedural concept of user-defined functions in programming languages. However, in KerML each function evaluation, even the evaluation of the addition function in 1+1, is viewed as an action (i.e., an occurrence in time and space) with a start time and an end time as well as a number of spatial feature values (e.g., their innerSpaceDimension, whatever that is in the case of an evaluation action).

It seems too much of a good thing to impose this semantics on all forms of expressions. It would be preferable to have a declarative semantics at least for built-in operators.

The body of a Function declaration may contain a result expression at the end, as in the following example:

function Average {
  in scores[1..*] : Rational;
  return : Rational;
  // result expression
  sum(scores) / size(scores)
}

The result of the result expression is implicitly bound to the result parameter of the containing Function. Alternatively, a result expression can be explicitly bound to the result parameter like so:

function Average { 
  in scores[1..*] : Rational;
  return : Rational = sum(scores) / size(scores);
}

The KerML library Performances includes the predefined Function Evaluation, which is the most general Function in the sense that every other Function is a subtype of it. A Kernel-layer Function declaration made with the keyword "function" like the following one:

function MyFun;

is equivalent to the following Core-layer classifier declaration made with the help of the predefined Function Evaluation:

classifier MyFun specializes Evaluation;

Predicates

Predicates are functions whose result is a single Boolean value (that is, true or false). A predicate determines whether the values of its input parameters meet particular conditions at the time of its evaluation, resulting in true if they do, and false otherwise. Predicates classify Boolean evaluations, which are specialized evaluations giving a Boolean result. [7.4.8.1]