1<!-- BEGIN LICENSE BLOCK
2   - Version: CMPL 1.1
3   -
4   - The contents of this file are subject to the Cisco-style Mozilla Public
5   - License Version 1.1 (the "License"); you may not use this file except
6   - in compliance with the License.  You may obtain a copy of the License
7   - at www.eclipse-clp.org/license.
8   - 
9   - Software distributed under the License is distributed on an "AS IS"
10   - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11   - the License for the specific language governing rights and limitations
12   - under the License. 
13   - 
14   - The Original Code is  The ECLiPSe Constraint Logic Programming System. 
15   - The Initial Developer of the Original Code is  Cisco Systems, Inc. 
16   - Portions created by the Initial Developer are
17   - Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18   - 
19   - Contributor(s): 
20   - 
21   - END LICENSE BLOCK -->
22<html>
23<head>
24<title>Compile Time Transforms in IC</title>
25<style type="text/CSS">
26BODY { background-color:ivory }
27PRE  { padding-left:10 }
28CODE { background-color:lightgrey }
29</style>
30</head>
31
32<body>
33<h1>Compile Time Transforms in IC</h1>
34<ol>
35<li>Factor out all blatantly non-linear sub-expressions, replacing
36them with a place-holder temporary variable.</li>
37  <ul>
38  <li>Non-linear sub-expressions are divisions <code>'/'/2</code>,
39  embedded reified constraint terms eg.<code>*=/2</code> and all
40  functions except <code>eval/1</code>.</li>
41
42  <li>Products <code>*/2</code> are <em>not</em> factored out.</li>
43
44  <li>Recursively transform all factored sub-expressions.</li>
45  </ul>
46</li>
47
48<li>If the remaining expression is linear, then transform it into a
49specialised propagator.
50  <ul>
51  <li><code>X =:= Y</code> becomes nothing, but the valiables are
52  unifed <code>X = Y</code> at compile time</li>
53  </ul>
54</li>
55
56<li>If the remaining expression is <em>not</em> linear, then delay
57processing until run-time.</li>
58
59</ol>
60<h2>Examples</h2>
61
62<h3>Compile time linear</h3>
63
64<code>X =:= 3 * A + 4 * B</code> becomes <code>ic_lin_eq/3</code><br>
65
66<code>X =:= 1 + 3 * A</code> becomes <code>ic_2v_eq/6</code><br>
67
68<code>X =:= 3 * A</code> becomes <code>ic_1v_eq/4</code><br>
69
70<h3>Compile time maybe linear</h3>
71
72<code>X =:= A + eval(E)</code> becomes <code>X =:= A + E</code> and is
73re-processed at run-time. Note the removal of the <code>eval/1</code>
74wrapper.<br>
75
76<code>X =:= A + B*C</code> becomes <code>X =:= A + B*C</code> (ie is
77left allone sice it contains variable products)<br>
78
79<h3>Compile time linear after factoring</h3>
80
81<code>X =:= 1 + A + 2*B + sin(C + 3*D)</code> becomes
82<code>ic_lin_eq(T2 =:= C + 3*D)</code>, <code>T1 iis sin(T2)</code>,
83<code>ic_lin_eq(X =:= 1 + A + 2*B + T1)</code>
84
85<h3>Compile time maybe linear after factoring</h3>
86
87<code>X =:= 1 + A*sin(C + 3*D)</code> becomes <code>ic_lin_eq(T2 =:= C
88+ 3*D)</code>, <code>T1 iis sin(T2)</code>, <code>X =:= 1 +
89A*T1</code>. Note that what is left of the original constraint will
90be re-processed at run-time.
91
92<h3>Compile time clearly non-linear</h3>
93
94<code>X =:= sin(Y)</code> becomes <code>X iis sin(Y)</code>.  Note
95there will be a temporary form where <code>X =:= T1</code> and
96<code>T1 iis sin(Y)</code>, but <code>X =:= T1</code> will be
97collapsed to nothing and the variables <code>X</code> and
98<code>T1</code> will be unified at compile time, resulting in <code>X
99iis sin(Y)</code>
100
101</body>
102<address>
103<a href="mailto:ajs2@ilford.icparc.ic.ac.uk">ajs2</a>
104</address>
105</html>
106