Node:Range Expressions, Next:, Previous:Indexicals, Up:Defining Primitive Constraints



Range Expressions

A range expression has one of the following forms, where Ri denote range expressions, Ti denote integer valued term expressions, S(Ti) denotes the integer value of Ti in S, X denotes a variable, I denotes an integer, and S denotes the current store.

dom(X)
evaluates to D(X,S)
{T1,...,Tn}
evaluates to {S(T1),...,S(Tn)}. Any term expression containing a subexpression which is a variable that is not "quantified" by unionof/3 will only be evaluated when this variable has been assigned.
T1..T2
evaluates to the interval between S(T1) and S(T2).
R1/\R2
evaluates to the intersection of S(R1) and S(R2)
R1\/R2
evaluates to the union of S(R1) and S(R2)
\R2
evaluates to the complement of S(R2)
R1+R2
R1+T2
evaluates to S(R2) or S(T2) added pointwise to S(R1)
-R2
evaluates to S(R2) negated pointwise
R1-R2
R1-T2
T1-R2
evaluates to S(R2) or S(T2) subtracted pointwise from S(R1) or S(T1)
R1 mod R2
R1 mod T2
evaluates to S(R1) pointwise modulo S(R2) or S(T2)
R1 ? R2
evaluates to S(R2) if S(R1) is a non-empty set; otherwise, evaluates to the empty set. This expression is commonly used in the context (R1 ? (inf..sup) \/ R3), which evaluates to S(R3) if S(R1) is an empty set; otherwise, evaluates to inf..sup. As an optimization, R3 is not evaluated while the value of R1 is a non-empty set.
unionof(X,R1,R2)
evaluates to the union of S(Expr_1)...S(Expr_N), where each Expr_I has been formed by substituting K for X in R2, where K is the I:th element of S(R1). See N Queens, for an example of usage. N.B. If S(R1) is infinite, the evaluation of the indexical will be abandoned, and the indexical will simply suspend.
switch(T1,MapList)
evaluates to S(Expr) if S(T1) equals Key and MapList contains a pair Key-Expr. Otherwise, evaluates to the empty set.

When used in the body of an FD predicate (see Goal Expanded Constraints), a relation/3 expression expands to two indexicals, each consisting of a switch/2 expression nested inside a unionof/3 expression. Thus, the following constraints are equivalent:

     p(X, Y) +: relation(X, [1-{1},2-{1,2},3-{1,2,3}], Y).
     
     q(X, Y) +:
             X in unionof(B,dom(Y),switch(B,[1-{1,2,3},2-{2,3},3-{3}])),
             Y in unionof(B,dom(X),switch(B,[1-{1},2-{1,2},3-{1,2,3}])).