This file is indexed.

/usr/share/mozart/doc/fdt/node38.html is in mozart-doc 1.4.0-8ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>8.3 Example: Self-referential Aptitude Test</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node37.html#section.reified.photo">&lt;&lt; Prev</A></TD><TD><A href="node35.html">- Up -</A></TD><TD><A href="node39.html#section.reified.bin">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.reified.srat"><H2><A name="section.reified.srat">8.3 Example: Self-referential Aptitude Test</A></H2><P>This example illustrates three issues: expressing complex propositional formulas as reified constraints, improving performance and presentation by elimination of common subconstraints, and using the symbolic constraint posted by <CODE>FD<SPAN class="keyword">.</SPAN>element</CODE>. </P><DIV class="unnumbered"><H3><A name="label106">Problem Specification</A></H3><P>The self-referential aptitude test (which is taken from <A href="bib.html#henz.96">[Hen96]</A>) consists of 10 multiple choice questions, referred to as 1 to 10. Each question allows for 5 possible answers, referred to as a to e. For each of the 50 possible answers, a condition is specified. For each question, exactly one of the conditions associated with its possible answers must hold. A solution of the test is a function assigning to every question a letter such that the condition selected by the assigned letter holds. Here are the questions and their possible answers: </P><OL type="1"><LI><P>The first question whose answer is b is question (a)&nbsp;2; (b)&nbsp;3; (c)&nbsp;4; (d)&nbsp;5; (e)&nbsp;6.</P></LI><LI><P>The only two consecutive questions with identical answers are questions (a)&nbsp;2 and 3; (b)&nbsp;3 and 4; (c)&nbsp;4 and 5; (d)&nbsp;5 and 6; (e)&nbsp;6 and&nbsp;7.</P></LI><LI><P>The answer to this question is the same as the answer to question (a)&nbsp;1; (b)&nbsp;2; (c)&nbsp;4; (d)&nbsp;7; (e)&nbsp;6.</P></LI><LI><P>The number of questions with the answer a is (a)&nbsp;0; (b)&nbsp;1; (c)&nbsp;2; (d)&nbsp;3; (e)&nbsp;4.</P></LI><LI><P>The answer to this question is the same as the answer to question (a)&nbsp;10; (b)&nbsp;9; (c)&nbsp;8; (d)&nbsp;7; (e)&nbsp;6.</P></LI><LI><P>The number of questions with answer a equals the number of questions with answer (a)&nbsp;b; (b)&nbsp;c; (c)&nbsp;d; (d)&nbsp;e; (e)&nbsp;none of the above.</P></LI><LI><P>Alphabetically, the answer to this question and the answer to the following question are (a)&nbsp;4 apart; (b)&nbsp;3 apart; (c)&nbsp;2 apart; (d)&nbsp;1 apart; (e)&nbsp;the same.</P></LI><LI><P>The number of questions whose answers are vowels is (a)&nbsp;2; (b)&nbsp;3; (c)&nbsp;4; (d)&nbsp;5; (e)&nbsp;6.</P></LI><LI><P>The number of questions whose answer is a consonant is (a)&nbsp;a prime; (b)&nbsp;a factorial; (c) a square; (d)&nbsp;a cube; (e)&nbsp;divisible by 5.</P></LI><LI><P>The answer to this question is (a)&nbsp;a; (b)&nbsp;b; (c)&nbsp;c; (d)&nbsp;d; (e)&nbsp;e.</P></LI></OL><P> </P><P>To understand the test, verify that </P><TABLE align="center" bgcolor="#f0f0e0"><TR valign="top"><TD><P>1:c</P></TD><TD><P>2:d</P></TD><TD><P>3:e</P></TD><TD><P>4:b</P></TD><TD><P>5:e</P></TD></TR><TR valign="top"><TD><P>6:e</P></TD><TD><P>7:d</P></TD><TD><P>8:c</P></TD><TD><P>9:b</P></TD><TD><P>10:a</P></TD></TR></TABLE><P> is a correct set of answers for the test. In particular, convince yourself that for every question the remaining 4 possibilities to answer it are falsified. The script we are going to write will prove that there is no other set of correct answers. </P></DIV><DIV class="unnumbered"><H3><A name="label107">Model</A></H3><P>Our model has 0/1-variables <IMG alt="A_i" src="latex194.png">, <IMG alt="B_i" src="latex195.png">, <IMG alt="C_i" src="latex126.png">, and <IMG alt="D_i" src="latex196.png"> for <IMG alt="i\in1\#10" src="latex197.png"> such that: </P><OL type="1"><LI><P><IMG alt="A_i+B_i+C_i+D_i+E_i=1" src="latex198.png">.</P></LI><LI><P><IMG alt="A_i=1" src="latex199.png"> iff the answer to Question <IMG alt="i" src="latex115.png"> is a.</P></LI><LI><P><IMG alt="B_i=1" src="latex200.png"> iff the answer to Question <IMG alt="i" src="latex115.png"> is b.</P></LI><LI><P><IMG alt="C_i=1" src="latex201.png"> iff the answer to Question <IMG alt="i" src="latex115.png"> is c.</P></LI><LI><P><IMG alt="D_i=1" src="latex202.png"> iff the answer to Question <IMG alt="i" src="latex115.png"> is d.</P></LI><LI><P><IMG alt="E_i=1" src="latex203.png"> iff the answer to Question <IMG alt="i" src="latex115.png"> is e.</P></LI></OL><P> To obtain a compact representation of the questions, we also have variables <IMG alt="Q_i\in1\#5" src="latex204.png"> for <IMG alt="i\in1\#10" src="latex197.png"> such that </P><TABLE align="center" bgcolor="#f0f0e0"><TR valign="top"><TD><P><IMG alt="Q_i=1\leftrightarrow A_i=1" src="latex205.png"></P></TD><TD><P><IMG alt="Q_i=2\leftrightarrow B_i=1" src="latex206.png"></P></TD></TR><TR valign="top"><TD><P><IMG alt="Q_i=3\leftrightarrow C_i=1" src="latex207.png"></P></TD><TD><P><IMG alt="Q_i=4\leftrightarrow D_i=1" src="latex208.png"></P></TD></TR><TR valign="top"><TD><P><IMG alt="Q_i=5\leftrightarrow E_i=1" src="latex209.png"></P></TD></TR></TABLE><P> </P><P>The first question can now be expressed by means of five equivalences: </P><BLOCKQUOTE><P><IMG alt="\begin{array}{rcl}
A_1
&=&
B_2
\\
B_1
&=&
(B_3\land (B_2=0))
\\
C_1
&=&
(B_4\land (B_2+B_3=0))
\\
D_1
&=&
(B_5\land (B_2+B_3+B_4=0))
\\
E_1
&=&
(B_6\land (B_2+B_3+B_4+B_5=0))
\end{array}" src="latex210.png"></P></BLOCKQUOTE><P> These equivalences can be expressed by reifying the nested equality constraints. </P><P>The second question can be expressed with the following constraints: </P><BLOCKQUOTE><P><IMG alt="\begin{array}{rcl}
&
Q_1\neq Q_2,\quad
Q_7\neq Q_8,\quad
Q_8\neq Q_9,\quad
Q_9\neq Q_10
\\
&
A_2=(Q_2=Q_3),\quad
B_2=(Q_3=Q_4),\quad
C_2=(Q_4=Q_5)
\\
&
D_2=(Q_5=Q_6),\quad
E_2=(Q_6=Q_7)
\end{array}" src="latex211.png"></P></BLOCKQUOTE><P> </P><P>The third question can be expressed as follows: </P><BLOCKQUOTE><P><IMG alt="\begin{array}{rcl}
&
A_3=(Q_1=Q_3),\quad
B_3=(Q_2=Q_3),\quad
C_3=(Q_4=Q_3)
\\
&
D_3=(Q_7=Q_3),\quad
E_3=(Q_6=Q_3)
\end{array}" src="latex212.png"></P></BLOCKQUOTE><P> </P><P>The fourth question can be elegantly expressed with the constraint </P><BLOCKQUOTE><P><IMG alt="{\it element}(Q_4,\;(0,1,2,3,4)) =
\sum_{i=1}^{10}{A_i}" src="latex213.png"></P></BLOCKQUOTE><P> where the function <IMG alt="{\it element}(k,x)" src="latex214.png"> yields the <IMG alt="k" src="latex114.png">-th component of the tuple <IMG alt="x" src="latex42.png">. </P><P>We choose this formulation since Oz provides a propagator <CODE>FD<SPAN class="keyword">.</SPAN>element</CODE> for the constraint <IMG alt="{\it
element}(k,x)=y" src="latex215.png">. </P><P class="margin">reified membership constraints</P><P> The nineth question can be expressed with the following equations </P><BLOCKQUOTE><P><IMG alt="\begin{array}{rcl}
S
&=&
\sum_{i=1}^{10}{(B_i+C_i+D_i)}
\\
A_9
&=&
(S\in\{2,3,5,7\})
\\
B_9
&=&
(S\in\{1,2,6\})
\\
C_9
&=&
(S\in\{0,1,4,9\})
\\
D_9
&=&
(S\in\{0,1,8\})
\\
E_9
&=&
(S\in\{0,5,10\})
\end{array}" src="latex216.png"></P></BLOCKQUOTE><P> where <IMG alt="S" src="latex7.png"> is an existentially quantified auxiliary variable. This time we use reified membership constraints of the form <IMG alt="x\in D" src="latex16.png">.</P></DIV><DIV class="unnumbered"><H3><A name="label108">Distribution Strategy</A></H3><P>We distribute on the variables <IMG alt="Q_1,\,Q_2\,\ldots" src="latex217.png"> using the standard first-fail strategy. </P></DIV><DIV class="unnumbered"><H3><A name="label109">Script</A></H3><P></P><DIV id="progsrat"><HR><P><A name="progsrat"></A></P><DL class="anonymous"><DD class="code"><CODE><SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">SRAT</SPAN>&nbsp;Q}<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Vector</SPAN>&nbsp;V}&nbsp;&nbsp;%&nbsp;<SPAN class="comment">V&nbsp;is&nbsp;a&nbsp;0/1-vector&nbsp;of&nbsp;length&nbsp;10<BR></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>tuple&nbsp;v&nbsp;10&nbsp;0<SPAN class="keyword">#</SPAN>1&nbsp;V}&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Sum</SPAN>&nbsp;V&nbsp;S}&nbsp;&nbsp;&nbsp;%&nbsp;<SPAN class="comment">S&nbsp;is&nbsp;the&nbsp;sum&nbsp;of&nbsp;the&nbsp;components&nbsp;of&nbsp;vector&nbsp;V<BR></SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>decl&nbsp;S}&nbsp;{FD<SPAN class="keyword">.</SPAN>sum&nbsp;V&nbsp;<SPAN class="string">'=:'</SPAN>&nbsp;S}&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Assert</SPAN>&nbsp;I&nbsp;U&nbsp;V&nbsp;W&nbsp;X&nbsp;Y}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A<SPAN class="keyword">.</SPAN>I=U&nbsp;&nbsp;B<SPAN class="keyword">.</SPAN>I=V&nbsp;&nbsp;C<SPAN class="keyword">.</SPAN>I=W&nbsp;&nbsp;D<SPAN class="keyword">.</SPAN>I=X&nbsp;&nbsp;E<SPAN class="keyword">.</SPAN>I=Y&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{Vector}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;B&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{Vector}<BR>&nbsp;&nbsp;&nbsp;C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{Vector}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;D&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{Vector}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;{Vector}<BR>&nbsp;&nbsp;&nbsp;SumA&nbsp;&nbsp;&nbsp;=&nbsp;{Sum&nbsp;A}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumB&nbsp;=&nbsp;{Sum&nbsp;B}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumC&nbsp;=&nbsp;{Sum&nbsp;C}&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;SumD&nbsp;&nbsp;&nbsp;=&nbsp;{Sum&nbsp;D}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumE&nbsp;=&nbsp;{Sum&nbsp;E}<BR>&nbsp;&nbsp;&nbsp;SumAE&nbsp;&nbsp;=&nbsp;{Sum&nbsp;[SumA&nbsp;SumE]}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumBCD&nbsp;=&nbsp;{Sum&nbsp;[SumB&nbsp;SumC&nbsp;SumD]}<BR><SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>tuple&nbsp;q&nbsp;10&nbsp;1<SPAN class="keyword">#</SPAN>5&nbsp;Q}<BR>&nbsp;&nbsp;&nbsp;{For&nbsp;1&nbsp;10&nbsp;1<BR>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>&nbsp;I}&nbsp;{Assert&nbsp;I&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">=:</SPAN>1&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">=:</SPAN>2&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">=:</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">=:</SPAN>4&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>I<SPAN class="keyword">=:</SPAN>5}&nbsp;<SPAN class="keyword">end</SPAN>}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">1<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;1&nbsp;B<SPAN class="keyword">.</SPAN>2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>conj&nbsp;B<SPAN class="keyword">.</SPAN>3&nbsp;(B<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">=:</SPAN>0)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>conj&nbsp;B<SPAN class="keyword">.</SPAN>4&nbsp;(B<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>3<SPAN class="keyword">=:</SPAN>0)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>conj&nbsp;B<SPAN class="keyword">.</SPAN>5&nbsp;(B<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>3<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>4<SPAN class="keyword">=:</SPAN>0)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>conj&nbsp;B<SPAN class="keyword">.</SPAN>6&nbsp;(B<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>3<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>4<SPAN class="keyword">+</SPAN>B<SPAN class="keyword">.</SPAN>5<SPAN class="keyword">=:</SPAN>0)}}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">2<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;2&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>3<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>4&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>4<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>5<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>6&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>6<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>7}<BR>&nbsp;&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>1<SPAN class="keyword">\=:</SPAN>Q<SPAN class="keyword">.</SPAN>2&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>7<SPAN class="keyword">\=:</SPAN>Q<SPAN class="keyword">.</SPAN>8&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>8<SPAN class="keyword">\=:</SPAN>Q<SPAN class="keyword">.</SPAN>9&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>9<SPAN class="keyword">\=:</SPAN>Q<SPAN class="keyword">.</SPAN>10<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">3<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>1<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>2<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>4<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>7<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>6<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>3}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">4<BR></SPAN>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>element&nbsp;Q<SPAN class="keyword">.</SPAN>4&nbsp;[0&nbsp;1&nbsp;2&nbsp;3&nbsp;4]&nbsp;SumA}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">5<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>10<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>9<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>8<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>7<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5&nbsp;&nbsp;Q<SPAN class="keyword">.</SPAN>6<SPAN class="keyword">=:</SPAN>Q<SPAN class="keyword">.</SPAN>5}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">6<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;6&nbsp;&nbsp;SumA<SPAN class="keyword">=:</SPAN>SumB&nbsp;&nbsp;SumA<SPAN class="keyword">=:</SPAN>SumC&nbsp;&nbsp;SumA<SPAN class="keyword">=:</SPAN>SumD&nbsp;&nbsp;SumA<SPAN class="keyword">=:</SPAN>SumE&nbsp;&nbsp;_}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">7<BR></SPAN>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>element&nbsp;Q<SPAN class="keyword">.</SPAN>7&nbsp;[4&nbsp;3&nbsp;2&nbsp;1&nbsp;0]&nbsp;{FD<SPAN class="keyword">.</SPAN>decl}={FD<SPAN class="keyword">.</SPAN>distance&nbsp;Q<SPAN class="keyword">.</SPAN>7&nbsp;Q<SPAN class="keyword">.</SPAN>8&nbsp;<SPAN class="string">'=:'</SPAN>}}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">8<BR></SPAN>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>element&nbsp;Q<SPAN class="keyword">.</SPAN>8&nbsp;[2&nbsp;3&nbsp;4&nbsp;5&nbsp;6]&nbsp;SumAE}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">9<BR></SPAN>&nbsp;&nbsp;&nbsp;{Assert&nbsp;9&nbsp;SumBCD<SPAN class="keyword">::</SPAN>[2&nbsp;3&nbsp;5&nbsp;7]&nbsp;&nbsp;SumBCD<SPAN class="keyword">::</SPAN>[1&nbsp;2&nbsp;6]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumBCD<SPAN class="keyword">::</SPAN>[0&nbsp;1&nbsp;4&nbsp;9]&nbsp;&nbsp;SumBCD<SPAN class="keyword">::</SPAN>[0&nbsp;1&nbsp;8]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SumBCD<SPAN class="keyword">::</SPAN>[0&nbsp;5&nbsp;10]}<BR>&nbsp;&nbsp;&nbsp;%%&nbsp;<SPAN class="comment">10<BR></SPAN>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>distribute&nbsp;ff&nbsp;Q}<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P class="caption"><STRONG>Figure&nbsp;8.2:</STRONG> A script for the self-referential aptitude test.</P><HR></DIV><P> </P><DIV class="apropos"><P class="margin">elimination of common subconstraints</P><P> The script in <A href="node38.html#progsrat">Figure&nbsp;8.2</A> implements the indexed variables <IMG alt="A_i" src="latex194.png">, <IMG alt="B_i" src="latex195.png">, <IMG alt="C_i" src="latex126.png">, <IMG alt="D_i" src="latex196.png">, <IMG alt="E_i" src="latex218.png">, and <IMG alt="Q_i" src="latex219.png"> as tuples with 10 components each. The three procedures <CODE>Vector</CODE>, <CODE>Sum</CODE>, and <CODE>Assert</CODE> make it more convenient to state the constraints. For each sum occurring in the questions an auxiliary variable is introduced so that the corresponding summation constraint needs to be posted only once. This elimination of common subconstraints provides for a compact formulation of the script and also improves its performance. </P></DIV><P>The procedure <CODE>{FD<SPAN class="keyword">.</SPAN>element&nbsp;</CODE><I>K</I><CODE>&nbsp;</CODE><I>V</I><CODE>&nbsp;</CODE><I>X</I><CODE>}</CODE> posts a propagator for the constraint saying that <I>X</I> is the <I>K</I>-th component of the vector <I>V</I>. </P><P>Note the use of <CODE>FD<SPAN class="keyword">.</SPAN>decl</CODE> in the definition of the procedure <CODE>Sum</CODE> and in the representation of the seventh question. Telling an initial domain constraint for the respective variables is necessary so that the propagators depending on these variables can start their work. </P></DIV><DIV class="unnumbered"><H3><A name="label110">Exercises</A></H3><DIV class="exercise" id="reified.ex.d"><P><B>Exercise&nbsp;8.4</B> (<A href="answers.html#label185">See solution</A>)</P><BLOCKQUOTE><P>The script in <A href="node38.html#progsrat">Figure&nbsp;8.2</A> uses the statement </P><BLOCKQUOTE class="code"><CODE>{FD<SPAN class="keyword">.</SPAN>element&nbsp;Q<SPAN class="keyword">.</SPAN>7&nbsp;[4&nbsp;3&nbsp;2&nbsp;1&nbsp;0]&nbsp;&nbsp;<BR>&nbsp;{FD<SPAN class="keyword">.</SPAN>decl}={FD<SPAN class="keyword">.</SPAN>distance&nbsp;Q<SPAN class="keyword">.</SPAN>7&nbsp;Q<SPAN class="keyword">.</SPAN>8&nbsp;<SPAN class="string">'=:'</SPAN>}}</CODE></BLOCKQUOTE><P> to post the constraints for the seventh question. It avoids one auxiliary variable by nesting two equated procedure applications. Give an equivalent statement in which the auxiliary variable is introduced and the nested procedure applications are unfolded.</P></BLOCKQUOTE></DIV></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node37.html#section.reified.photo">&lt;&lt; Prev</A></TD><TD><A href="node35.html">- Up -</A></TD><TD><A href="node39.html#section.reified.bin">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian&nbsp;Schulte</A> and&nbsp;<A href="http://www.ps.uni-sb.de/~smolka/">Gert&nbsp;Smolka</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>