Acknowledgement: Most of this content is taken directly from the Alloy 3.0 Tutorial, although a few annotations and re-phrasings have been made.
The Alloy quantifiers are
Note that a 'formula' is something that evaluates to a boolean value, as opposed to an 'expression' which evaluates to a (relational) value. Also note that X can be any expression that yields a set, and thus need not be simply the name of a signature in the module. An example (which happens to use multiple dummies associated to the same quantifier) is
Here the expression d.contents is used to indicate the "type" of dummy o.
One can leave out the variable and the formula. Alloy will then act as though you had entered a trivially true formula. That is, the abbreviated expression quantifier X means the same thing as quantifier x:X | true. To spell it out in gory detail:
In effect, each of these boolean expressions says something about the cardinality (i.e., number of tuples in) relation X.
The basic format for a quantifier is
where the formula may includes references to the quantifier variable (i.e., dummy). An alternative notation is:
Examples:
// At least one directory has itself as a parent some d: Dir | d.parent = d
You can also opt to leave out the formula and variable.
Examples:
// no root has a parent no Root.parent //there is exactly one root one r: RootMultiple variables can be used in the same quantifier, like so:
which desugars to
Examples:
// every file has as a parent some directory all f:File | some d:Dir | f.parent = d
Multiple variables of the same type can be abbreviated as a comma-delimited list, like so:
Examples:
// no two directories have exactly the same contents no d,s:Dir | d.contents = s.contentsEditor's Note: The above should be false, as long as Dir has at least one member, because instantiating both dummies to the same member of Dir provides a counterexample. End of Note.
The above features can, of course, be combined to produce arbitrarily complex formulas.
However, be warned that nested quantifiers may cause your model to become intractable. In general, try not to stack more than two or three of them together.