<!--
  - Authors:
  -   Tobias Mueller <tmueller@ps.uni-sb.de>
  -
  - Copyright:
  -   Tobias Mueller, 1998
  -
  - Last change:
  -   $Date: 1999-06-01 22:12:13 +0200 (Tue, 01 Jun 1999) $ by $Author: schulte $
  -   $Revision: 11406 $
  -
  - This file is part of Mozart, an implementation
  - of Oz 3
  -    http://www.mozart-oz.org
  -
  - See the file "LICENSE" or
  -    http://www.mozart-oz.org/LICENSE.html
  - for information on usage and redistribution
  - of this file, and for a DISCLAIMER OF ALL
  - WARRANTIES.
  -
  -->

<Chapter id="Chapter.Types_Modes_Constr"><Title/Constraints-Specific
Type Structure and Modes/

<P>
This section presents those types and modes which are specific for the
constraint extensions.

<!-- ********************************************************************** -->

<Section><Title/Type Structure/

<P>
There are two additional secondary types. 

<Para><Title/Vector/
A vector is a record with a label different from
<<'|'>> or a list. The elements of the list or the fields of the
record are called the elements of the vector.  A finite domain vector
is a vector all of whose elements are finite domain integers.

<Para><Title/Specification of Sets of Integers/

A specification of sets of integers <<Spec>> is used in cointext of
finite domain and finite set constraints. It is recursively defined as
follows.

	<Grammar.Rule>?{Spec}
	  <Grammar.Alt type=def>?{simpl_spec}</Grammar.Alt>
	  <Grammar.Alt type=or>compl(?{simpl_spec})</Grammar.Alt>

	<Grammar.Rule>?{simpl_spec}
	  <Grammar.Alt type=def>?{range_descr}</Grammar.Alt>
	  <Grammar.Alt type=or>[?{range_descr}+]</Grammar.Alt>
	  <Grammar.Alt type=or><<nil>></Grammar.Alt>

	<Grammar.Rule>?{range_descr}
	  <Grammar.Alt type=def>?{integer}</Grammar.Alt>
	  <Grammar.Alt type=or>?{integer}<<#>>?{integer}</Grammar.Alt>

	<Grammar.Rule>?{integer}
	  <Grammar.Alt type=def><<FD.inf>>,...,<<FD.sup>></Grammar.Alt>
	  <Grammar.Alt type=or><<FS.inf>>,...,<<FS.sup>></Grammar.Alt>

<P>
A specification of sets of integers denotes a set of integers which is
either the union of integer singletons <Math/i/ and integer intervals
<Math/i\#i/, or the complement <<compl(...)>> of such a set relative
to <Math/\{\mbox{\tt FD.inf},\ldots,\mbox{\tt FD.sup}\}/ &resp;
<Math/\{\mbox{\tt FS.inf},\ldots,\mbox{\tt FS.sup}\}/. Note that an empty
set is specified by <<nil>>.

<P>
In context of finite domain constraints for example, <<2#5>> denotes
the set <Math/\{2,\ldots,5\}/, the specification <<[1 10#20]>> denotes
the set <Math/\{1,10,\ldots,20\}/, and <<compl(2#5)>> denotes
<Math/\{0,1,6,\ldots,\mbox{\tt FD.sup}\}/.

<P>
The value of <<FD.inf>> and <<FS.inf>> is <Math/0/ and the value of
<<FD.sup>> and <<FS.sup>> is <Math/134217726/. These values are
implementation-dependent.

<Para><Title/Weight Specifications/ Weight specifications <<SpecW>>
occur in conjunction with set constraints (see <Ptr
to="section.fs.distribution">) and are defined as follows.

	<Grammar.Rule>?{SpecW}
	  <Grammar.Alt type=def><<nil>></Grammar.Alt>
	  <Grammar.Alt type=or>[?{ElemDescr}]+</Grammar.Alt>

	<Grammar.Rule>?{ElemDescr}
	  <Grammar.Alt type=def>?{Int}<<#>>?{Int}</Grammar.Alt>
	  <Grammar.Alt type=or><<(>>?{Int}<<#>>?{Int}<<)#>>?{Int}</Grammar.Alt>
	  <Grammar.Alt type=or><<default#>>?{Int}</Grammar.Alt>


</Section>

<!-- ********************************************************************** -->

<Section><Title/Signatures/


<SubSection class=unnumbered id="sec:type-abbrev-ps"><Title/Types/

<P>
The additional type abbreviations are listed in Figure <Ptr
to="type-abbrev-ps">.

<Figure id="type-abbrev-ps">
 <Caption>Type Abbreviations</Caption>
<Table>
 <TR/<TH/Abbreviation/<TH/Type//
 <TR/<TD/?{D}/<TD/finite domain integer//
 <TR/<TD/?{M}/<TD/finite set of integers//
 <TR/<TD/?{Xr}/<TD/records of type ?{X}//
 <TR/<TD/?{Xt}/<TD/tuples of type ?{X}//
 <TR/<TD/?{Xv}/<TD/vectors of type ?{X}//
 <TR/<TD/?{Xvv}/<TD/vectors of vectors of type ?{X}//
 <TR/<TD/?{Xrr}/<TD/records of records of type ?{X}//
</Table>
</Figure>

<!-- ********************************************************************** -->

<SubSection class=unnumbered id="modes-ps"><Title/Modes/

<P>
Given a constraint store, every variable is in exactly one of the
following three states. It is <Em/free/ if the store knows nothing
about the variable apart from equalities, <Em/determined/ if the store
knows the top-level constructor, and <Em/kinded/ if the variable is
neither free nor determined.  Variables which are either determined or
kinded are called <Em/constrained/.

<P>
The base language does not allow to constrain a variable without
determining it.  Most procedures of the base language wait until their
arguments are determined.

<Para><Title/Input Modes ?*{}, ?+{}/ 
In the constraint extension, a
variable can be constrained before it becomes determined.
Accordingly, the constraint extensions use additional input modes
?*{} and ?@{} which synchronize more weakly than ?+{}.  The
application of a procedure <<P>> waits until its inputs (?+{}, ?*{})
are determined or constrained, respectively.  If the input arguments
are well-typed, <<P>>  returns outputs of the specified types.
Ill-typed input arguments produce a runtime type error (on completion
of <<P>>).

<Para><Title/Propagators/ 
Note that it is perfectly possible that an
input argument is constrained further.  This is the case for many
propagators, which have the following typical moding.

<<<{P ?*{X} ?*{Y} ?*{Z}}>>>

Note also that modes only partially specify the synchronisation behavior
of a procedure. 

<Para><Title/Nestable Input Mode ?@{}/
The mode ?@{} slightly
weakens ?*{} to allow for nesting of propagators.  When <Math/n/
arguments of a propagator have input mode ?@{}, then this
propagator waits until <Math/n-1/ of them are constrained and then it
constrains the remaining <Math/n/th argument according to its type.

<!-- ********************************************************************** -->

<SubSection><Title/Notational Conventions/

<P>
Notational conventions are explained in context of finite domain
constraints but apply of course for finite set constraints too.

<Para><Title/Specification Input/
The signature

<<<{FD.int ?+{Spec} ??{D}}>>>

specifies that an application of <<FD.int>> waits until ?+{Spec} is
<Em/ground/, &ie;, contains no free variables.  Arguments of the
form ?+{Spec} never occur. The signature 

<<<{FD.distinct ?*{Dv}}>>>

specifies that an application of <<FD.distinct>> waits until its
argument <<Dv>> is determined and all its elements are constrained to
finite domain integers. Analogously, ?+{Iv} specifies that the
application waits until <<Iv>> and all its elements are
determined. The scheme

<<<{FD.sumCN ?+{Iv} ?*{Dvv}  ?+{A}  ?*{D}}>>> 

specifies that the application waits until ?*{Dvv} and all its
elements are determined, and until their elements are constrained to
finite domain integers. 

<Para><Title/Generic Propagators/
For some procedures like that for generic
propagators, an atom occurring as an argument denotes a relation
symbol. For example, 

<<<{FD.sum [X Y Z] '=:' D}>>>

denotes the constraint
<Math Display>X + Y + Z = D</Math>

If <Math/A/ is the atomic argument, <Math/\sim_A/ is the corresponding
arithmetic relation. For <Math/A/ the atoms <<'=:'>>, <<'>:'>>, <<'>=:'>>,
<<'<:'>>, <<'=<:'>>, and <<'\\=:'>> are allowed. The relations are <Math/=/,
<Math/>/, <Math/\geq/, <Math/</, <Math/\leq/, and <Math/\neq/, respectively.

</Section>

</Chapter>
