Skip to content


There is no dedicated syntax for aggregations. Instead, there is a higher-order primitive operation similar to the reduce function of functional languages. That operation is used to define various aggregations in the Standard Library. The underlying primitive operation should not be invoked directly, and is not documented here.

A few examples of aggregations:

sum[salary]Sum all salaries.
sum[p in employee: salary[p]]Sum employee salaries.
Σ[salary[p] | p ∈ employee]Sum employee salaries (again).
Σ[employee.salary]Wrong: duplicates eliminated.
d in dept: Σ[salary[p] | p ∈ member[d]]Sum salaries by department.
d in dept: Σ[d.member.salary]Wrong: duplicates eliminated.
count[employee]Count number of employees.
d in dept: count[d.member]Count number of employees by department.
d, v: dept(d) and count[d.member](v)Aggregations can be used in formulas.
max[age[p] | p ∈ person]Max age of all persons.
max[age[p] for p in person]Max age of all persons (again).
max[t.member.age] | t ∈ teamMax age by team.
max[Σ[salary[p] for p in member[t]]] for t in teamMax sum of salaries by team.
argmax[Σ[salary[p] for p in member[t]] for t in team]Team with max sum of salaries.
argmin[Σ[salary[p] for p in member[t]] for t in team]Team with min sum of salaries.
t: max[age[p] for p in member[t]]Max age by team (again).

Next: Variable Scope

Was this doc helpful?