This file is indexed.

/usr/share/mozart/doc/fdt/node32.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>7.2 Example: Pythagoras</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="node31.html#section.propagators.fractions">&lt;&lt; Prev</A></TD><TD><A href="node30.html">- Up -</A></TD><TD><A href="node33.html#section.propagators.squares">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.propagators.pythagoras"><H2><A name="section.propagators.pythagoras">7.2 Example: Pythagoras</A></H2><P>Not all propagators exploit coreferences in products (e.g. <IMG alt="x\cdot x + y\cdot y = z\cdot
z" src="latex143.png">). For the example of this section it will be essential to exploit such coreferences, and you will learn how to do it. </P><P>The example also illustrates the case where a propagator for a redundant constraint improves the performance of a script by decreasing the number of necessary propagation steps, but without significantly changing the search tree. </P><DIV class="unnumbered"><H3><A name="label92">Problem Specification</A></H3><P>How many triples <IMG alt="(A,B,C)" src="latex144.png"> exist such that\ <IMG alt="A^2+B^2=C^2" src="latex145.png"> and <IMG alt="A\le B\le C\le 1000" src="latex146.png">? </P></DIV><DIV class="unnumbered"><H3><A name="label93">Model</A></H3><P>The model has three variables <IMG alt="A" src="latex98.png">, <IMG alt="B" src="latex39.png">, and <IMG alt="C" src="latex31.png">. Each variable is constrained to the finite domain <IMG alt="1\#1000" src="latex147.png">. The model imposes the constraints <IMG alt="A^2+B^2=C^2" src="latex145.png"> and <IMG alt="A\le B\le C" src="latex148.png">. </P><P>The script will also create a propagator for the redundant constraint <IMG alt="2\cdot B^2\ge C^2" src="latex149.png">. </P></DIV><DIV class="unnumbered"><H3><A name="label94">Distribution Strategy</A></H3><P>We distribute on the variables <IMG alt="A" src="latex98.png">, <IMG alt="B" src="latex39.png">, <IMG alt="C" src="latex31.png"> using the standard first-fail strategy.</P><P> </P><DIV class="figure" id="progpythagoras"><HR><P><A name="progpythagoras"></A></P><P></P><DL class="anonymous"><DD class="code"><CODE><SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Square</SPAN>&nbsp;X&nbsp;S}<BR>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>times&nbsp;X&nbsp;X&nbsp;S}<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P> </P><DL class="anonymous"><DD class="code"><CODE><SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Pythagoras</SPAN>&nbsp;Root}<BR>&nbsp;&nbsp;&nbsp;[A&nbsp;B&nbsp;C]&nbsp;=&nbsp;Root<BR>&nbsp;&nbsp;&nbsp;AA&nbsp;BB&nbsp;CC<BR><SPAN class="keyword">in</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;Root&nbsp;<SPAN class="keyword">:::</SPAN>&nbsp;1<SPAN class="keyword">#</SPAN>1000<BR>&nbsp;&nbsp;&nbsp;AA&nbsp;=&nbsp;{Square&nbsp;A}<BR>&nbsp;&nbsp;&nbsp;BB&nbsp;=&nbsp;{Square&nbsp;B}<BR>&nbsp;&nbsp;&nbsp;CC&nbsp;=&nbsp;{Square&nbsp;C}<BR>&nbsp;&nbsp;&nbsp;AA&nbsp;<SPAN class="keyword">+</SPAN>&nbsp;BB&nbsp;<SPAN class="keyword">=:</SPAN>&nbsp;CC<BR>&nbsp;&nbsp;&nbsp;A&nbsp;<SPAN class="keyword">=&lt;:</SPAN>&nbsp;B<BR>&nbsp;&nbsp;&nbsp;B&nbsp;<SPAN class="keyword">=&lt;:</SPAN>&nbsp;C<BR>&nbsp;&nbsp;&nbsp;2<SPAN class="keyword">*</SPAN>BB&nbsp;<SPAN class="keyword">&gt;=:</SPAN>&nbsp;CC&nbsp;&nbsp;%&nbsp;<SPAN class="comment">redundant&nbsp;constraint<BR></SPAN>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>distribute&nbsp;ff&nbsp;Root}<BR><SPAN class="keyword">end</SPAN></CODE></DD></DL><P></P><P class="caption"><STRONG>Figure&nbsp;7.2:</STRONG> A script that enumerates Pythagoras triples.</P><HR></DIV><P> </P></DIV><DIV class="unnumbered"><H3><A name="label95">Script</A></H3><P>Given the script in <A href="node32.html#progpythagoras">Figure&nbsp;7.2</A>, we can compute the number of different triples with the statement </P><DL class="anonymous"><DD class="code"><CODE>{Browse&nbsp;{Length&nbsp;{SearchAll&nbsp;Pythagoras}}}</CODE></DD></DL><P> The script introduces a defined constraint </P><BLOCKQUOTE class="code"><CODE>{Square&nbsp;X&nbsp;S}</CODE></BLOCKQUOTE><P> saying that <CODE>S</CODE> is the square of <CODE>X</CODE>. This constraint is implemented with a propagator provided by </P><BLOCKQUOTE class="code"><CODE>{FD<SPAN class="keyword">.</SPAN>times&nbsp;X&nbsp;X&nbsp;S}</CODE></BLOCKQUOTE><P> This propagator will start propagating as soon as the store constrains <CODE>X</CODE> to a finite domain. This in contrast to the propagator created by <CODE>X<SPAN class="keyword">*</SPAN>X<SPAN class="keyword">=:</SPAN>S</CODE>, which will start work only after both <CODE>X</CODE> and <CODE>S</CODE> are constrained to finite domains in the constraint store. To define <CODE>Square</CODE> with this constraint, we would have to write </P><BLOCKQUOTE class="code"><CODE><SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">Square</SPAN>&nbsp;X&nbsp;S}<BR>&nbsp;&nbsp;&nbsp;{FD<SPAN class="keyword">.</SPAN>decl&nbsp;S}<BR>&nbsp;&nbsp;&nbsp;X<SPAN class="keyword">*</SPAN>X&nbsp;<SPAN class="keyword">=:</SPAN>&nbsp;S<BR><SPAN class="keyword">end</SPAN></CODE></BLOCKQUOTE><P></P><P>The propagator for the redundant constraint does not significantly reduce the size of the search tree. However, it reduces the number of propagation steps from about 1000000 to about 500000, which makes computation twice as fast.</P><DIV class="apropos"><P class="margin">statistics</P><P> To find out about this, pop up the <A href="../panel/index.html">Oz Panel</A> and reset the statistics. Also switch on the status message feature and pop up the emulator buffer. Now enter the statement </P><BLOCKQUOTE class="code"><CODE>{Browse&nbsp;{Length&nbsp;{SearchAll&nbsp;Pythagoras}}}</CODE></BLOCKQUOTE><P> and print the statistics after the execution of the statement has finished. This will show something like </P><BLOCKQUOTE class="code"><CODE>solutions:&nbsp;881&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variables&nbsp;created:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<BR>clones:&nbsp;&nbsp;&nbsp;&nbsp;1488&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagators&nbsp;created:&nbsp;&nbsp;&nbsp;&nbsp;7<BR>failures:&nbsp;&nbsp;608&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagator&nbsp;invocations:&nbsp;490299</CODE></BLOCKQUOTE><P> in the emulator buffer. Now remove the propagator for the redundant constraint from the definition of the script, redefine it, reset the statistics, run the statement, and print the statistics. This time you will see something like </P><BLOCKQUOTE class="code"><CODE>solutions:&nbsp;881&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Variables&nbsp;created:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3<BR>clones:&nbsp;&nbsp;&nbsp;&nbsp;1878&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagators&nbsp;created:&nbsp;&nbsp;&nbsp;&nbsp;6<BR>failures:&nbsp;&nbsp;998&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Propagator&nbsp;invocations:&nbsp;1190397</CODE></BLOCKQUOTE><P></P></DIV><P>If we drop the redundant constraint, it seems sensible to not have separate propagators for the squares but simply have one propagator created with </P><BLOCKQUOTE class="code"><CODE>A<SPAN class="keyword">*</SPAN>A&nbsp;<SPAN class="keyword">+</SPAN>&nbsp;B<SPAN class="keyword">*</SPAN>B&nbsp;<SPAN class="keyword">=:</SPAN>&nbsp;C<SPAN class="keyword">*</SPAN>C</CODE></BLOCKQUOTE><P> Unfortunately, this will dramatically increase the size of the search tree. The reason for this increase is the fact that the created propagator does not realize the coreferences in the constraint it implements, that is, it treats the two occurrences of <CODE>A</CODE>, say, as if they were independent variables.</P></DIV></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node31.html#section.propagators.fractions">&lt;&lt; Prev</A></TD><TD><A href="node30.html">- Up -</A></TD><TD><A href="node33.html#section.propagators.squares">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>