<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> <TITLE> Boolean and reified constraints </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual060.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual054.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual062.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> <HR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE> <TR><TD><FONT SIZE=4><B><A NAME="htoc326">8.7</A></B></FONT></TD> <TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Boolean and reified constraints</B></FONT></TD> </TR></TABLE></DIV></TD> </TR></TABLE><UL> <LI><A HREF="manual061.html#toc267"> Boolean FD expressions</A> <LI><A HREF="manual061.html#toc268"> <TT>(#\)/1</TT> - constraint NOT, <TT>(#<=>)/2</TT> - constraint equivalent,<BR> <TT>(#\<=>)/2</TT> - constraint different, <TT>(##)/2</TT> - constraint XOR,<BR> <TT>(#==>)/2</TT> - constraint imply, <TT>(#\==>)/2</TT> - constraint not imply,<BR> <TT>(#/\)/2</TT> - constraint AND, <TT>(#\/\)/2</TT> - constraint NAND,<BR> <TT>(#\/)/2</TT> - constraint OR, <TT>(#\\/)/2</TT> - constraint NOR</A> <LI><A HREF="manual061.html#toc269"> <TT>fd_cardinality/2</TT>, <TT>fd_cardinality/3</TT>, <TT>fd_at_least_one/1</TT>, <TT>fd_at_most_one/1</TT>,<BR> <TT>fd_only_one/1</TT></A> </UL> <A NAME="Boolean-and-reified-constraints"></A><BR> <A NAME="toc267"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc327">8.7.1</A></B></TD> <TD WIDTH="100%" ALIGN=center><B>Boolean FD expressions</B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="Boolean-FD-expressions"></A> An boolean FD expression is a Prolog term built from integers (0 for false, 1 for true), variables (Prolog or FD variables), partial AC arithmetic constraints (section <A HREF="manual060.html#Partial-AC:-(:=)/2">8.6.2</A>), full AC arithmetic constraints (section <A HREF="manual060.html#Full-AC:-(:=:)/2">8.6.3</A>) and functors (or operators) that represent boolean functions. When a sub-expression of a boolean expression is an arithmetic constraint <I><TT>c</TT></I>, it is reified. Namely, as soon as the solver detects that <I><TT>c</TT></I> is true (i.e. <EM>entailed</EM>) the sub-expression has the value <TT>1</TT>. Similarly when the solver detects that <I><TT>c</TT></I> is false (i.e. <EM>disentailed</EM>) the sub-expression evaluates as <TT>0</TT>. While neither the entailment nor the disentailment can be detected the sub-expression is evaluated as a domain <TT>0..1</TT>. The following table details the components of an FD boolean expression:<BR> <TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1> <TR><TD ALIGN=left NOWRAP>FD Expression</TD> <TD ALIGN=left NOWRAP>Result</TD> </TR> <TR><TD ALIGN=left NOWRAP>Prolog variable</TD> <TD ALIGN=left NOWRAP>domain <TT>0..1</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP>FD variable <TT>X</TT></TD> <TD ALIGN=left NOWRAP>domain of <TT>X</TT>, <TT>X</TT> is constrained to be in <TT>0..1</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>0</TT> (integer)</TD> <TD ALIGN=left NOWRAP><TT>0</TT> (false)</TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>1</TT> (integer)</TD> <TD ALIGN=left NOWRAP><TT>1</TT> (true)</TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>#\ E</TT></TD> <TD ALIGN=left NOWRAP>not <TT>E</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #<=> E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> equivalent to <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #\<=> E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> not equivalent to <TT>E2</TT> (i.e. <TT>E1</TT> different from <TT>E2)</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 ## E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> exclusive OR <TT>E2</TT> (i.e. <TT>E1</TT> not equivalent to <TT>E2)</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #==> E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> implies <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #\==> E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> does not imply <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #/\ E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> AND <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #\/\ E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> NAND <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #\/ E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> OR <TT>E2</TT></TD> </TR> <TR><TD ALIGN=left NOWRAP><TT>E1 #\\/ E2</TT></TD> <TD ALIGN=left NOWRAP><TT>E1</TT> NOR <TT>E2</TT></TD> </TR></TABLE><BR> <TT>#<=></TT>, <TT>#\<=></TT>, <TT>##</TT>, <TT>#==></TT>, <TT>#\==></TT>, <TT>#/\</TT>, <TT>#\/\</TT>, <TT>#\/</TT> and <TT>#\\/</TT> are predefined infix operators. <TT>#\</TT> is a predefined prefix operator (section <A HREF="manual037.html#op/3:(Term-input/output)">7.14.10</A>).<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>a sub-expression <TT>E</TT> is neither a variable nor an integer (0 or 1) nor an FD boolean functor nor reified constraint</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(fd_bool_evaluable, E)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an expression is too complex</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>resource_error(too_big_fd_constraint)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>a sub-expression is an invalid reified constraint</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>an arithmetic constraint error (section <A HREF="manual060.html#FD-arithmetic-expressions">8.6.1</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <A NAME="toc268"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc328">8.7.2</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>(#\)/1</TT> - constraint NOT, <TT>(#<=>)/2</TT> - constraint equivalent,<BR> <TT>(#\<=>)/2</TT> - constraint different, <TT>(##)/2</TT> - constraint XOR,<BR> <TT>(#==>)/2</TT> - constraint imply, <TT>(#\==>)/2</TT> - constraint not imply,<BR> <TT>(#/\)/2</TT> - constraint AND, <TT>(#\/\)/2</TT> - constraint NAND,<BR> <TT>(#\/)/2</TT> - constraint OR, <TT>(#\\/)/2</TT> - constraint NOR</B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> #\(?fd_bool_evaluable)<BR> #<=>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #\<=>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> ##(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #==>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #\==>(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #/\(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #\/\(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #\/(?fd_bool_evaluable, ?fd_bool_evaluable)<BR> #\\/(?fd_bool_evaluable, ?fd_bool_evaluable)</TT></DL> <B>Description</B><BR> <BR> <TT>#\= FdBoolExpr1</TT> constraints <TT>FdBoolExpr1</TT> to be false.<BR> <BR> <TT>FdBoolExpr1 #<=> FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> to be equivalent to <TT>FdBoolExpr2</TT>.<BR> <BR> <TT>FdBoolExpr1 #\<=> FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> to be equivalent to not <TT>FdBoolExpr2</TT>.<BR> <BR> <TT>FdBoolExpr1 ## FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> XOR <TT>FdBoolExpr2</TT> to be true<BR> <BR> <TT>FdBoolExpr1 #==> FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> to imply <TT>FdBoolExpr2</TT>.<BR> <BR> <TT>FdBoolExpr1 #\==> FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> to not imply <TT>FdBoolExpr2</TT>.<BR> <BR> <TT>FdBoolExpr1 #/\ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> AND <TT>FdBoolExpr2</TT> to be true.<BR> <BR> <TT>FdBoolExpr1 #\/\ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> AND <TT>FdBoolExpr2</TT> to be false.<BR> <BR> <TT>FdBoolExpr1 #\/ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> OR <TT>FdBoolExpr2</TT> to be true.<BR> <BR> <TT>FdBoolExpr1 #\\/ FdBoolExpr2</TT> constrains <TT>FdBoolExpr1</TT> OR <TT>FdBoolExpr2</TT> to be false.<BR> <BR> <TT>FdBoolExpr1</TT> and <TT>FdBoolExpr2</TT> are boolean FD expressions (section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR> <BR> Note that <TT>#\<=></TT> (not equivalent) and <TT>##</TT> (exclusive or) are synonymous.<BR> <BR> These predicates post boolean constraints that are managed by the FD solver using a partial arc-consistency algorithm to reduce the domain of involved variables. The (dis)entailment of reified constraints is detected using either the bounds (for partial AC arithmetic constraints) or the full domain (for full AC arithmetic constraints).<BR> <BR> <TT>#<=></TT>, <TT>#\<=></TT>, <TT>##</TT>, <TT>#==></TT>, <TT>#\==></TT>, <TT>#/\</TT>, <TT>#\/\</TT>, <TT>#\/</TT> and <TT>#\\/</TT> are predefined infix operators. <TT>#\</TT> is a predefined prefix operator (section <A HREF="manual037.html#op/3:(Term-input/output)">7.14.10</A>).<BR> <BR> <B>Errors</B><BR> <BR> Refer to the syntax of boolean FD expressions for possible errors (section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR> <BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc269"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc329">8.7.3</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>fd_cardinality/2</TT>, <TT>fd_cardinality/3</TT>, <TT>fd_at_least_one/1</TT>, <TT>fd_at_most_one/1</TT>,<BR> <TT>fd_only_one/1</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="fd-cardinality/2"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> fd_cardinality(+fd_bool_evaluable_list, ?fd_variable)<BR> fd_cardinality(+integer, ?fd_variable, +integer)<BR> fd_at_least_one(+fd_bool_evaluable_list)<BR> fd_at_most_one(+fd_bool_evaluable_list)<BR> fd_only_one(+fd_bool_evaluable_list)</TT></DL> <B>Description</B><BR> <BR> <TT>fd_cardinality(List, Count)</TT> unifies <TT>Count</TT> with the number of constraints that are true in <TT>List</TT>. This is equivalent to post the constraint <TT>B<FONT SIZE=2><SUB>1</SUB></FONT> + B<FONT SIZE=2><SUB>2</SUB></FONT> + ...+ B<FONT SIZE=2><SUB><I>n</I></SUB></FONT> #= Count</TT> where each variable <TT>Bi</TT> is a new variable defined by the constraint <TT>B<FONT SIZE=2><SUB><I>i</I></SUB></FONT> #<=> C<FONT SIZE=2><SUB><I>i</I></SUB></FONT></TT> where <TT>C<FONT SIZE=2><SUB><I>i</I></SUB></FONT></TT> is the <TT>i</TT><EM>th</EM> constraint of <TT>List</TT>. Each <TT>C<FONT SIZE=2><SUB><I>i</I></SUB></FONT></TT> must be a boolean FD expression (section <A HREF="#Boolean-FD-expressions">8.7.1</A>).<BR> <BR> <TT>fd_cardinality(Lower, List, Upper)</TT> is equivalent to <TT>fd_cardinality(List, Count), Lower #=< Count, Count #=< Upper</TT><BR> <BR> <TT>fd_at_least_one(List)</TT> is equivalent to <TT>fd_cardinality(List, Count), Count #>= 1</TT>.<BR> <BR> <TT>fd_at_most_one(List)</TT> is equivalent to <TT>fd_cardinality(List, Count), Count #=< 1</TT>.<BR> <BR> <TT>fd_only_one(List)</TT> is equivalent to <TT>fd_cardinality(List, 1)</TT>.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is a partial list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>List</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, List)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Count</TT> is neither an FD variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(fd_variable, Count)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Lower</TT> is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Lower</TT> is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, Lower)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Upper</TT> is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Upper</TT> is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, Upper)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>List</TT> list is an invalid boolean expression</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>an FD boolean constraint (section <A HREF="#Boolean-FD-expressions">8.7.1</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <HR SIZE=2> Copyright (C) 1999-2002 Daniel Diaz <BR> <BR> Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. <BR> <BR> <A HREF="index.html#copyright">More about the copyright</A> <HR> <A HREF="manual060.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual054.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual062.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>