fixed a small bug in eval ehrhart
[polylib.git] / doc / codeDoc / html / Lattice_8c-source.html
blobd7c559a2afa7ad89ebd41e107483064275e88fdd
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Lattice.c Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.2.15 -->
7 <center>
8 <a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center>
9 <hr><h1>Lattice.c</h1><a href="Lattice_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
10 00002 <font class="preprocessor">#include &lt;polylib/polylib.h&gt;</font>
11 00003
12 00004
13 <a name="l00005"></a><a class="code" href="structfactor.html">00005</a> <font class="keyword">typedef</font> <font class="keyword">struct </font>{
14 <a name="l00006"></a><a class="code" href="structfactor.html#m0">00006</a> <font class="keywordtype">int</font> count;
15 <a name="l00007"></a><a class="code" href="structfactor.html#m1">00007</a> <font class="keywordtype">int</font> *fac;
16 00008 } <a class="code" href="structfactor.html">factor</a>;
17 00009
18 00010 <font class="keyword">static</font> <a class="code" href="structfactor.html">factor</a> <a class="code" href="Lattice_8c.html#a0">allfactors</a> (<font class="keywordtype">int</font> num);
19 00011
20 00012 <font class="comment">/* </font>
21 00013 <font class="comment"> * Print the contents of a list of Lattices 'Head' </font>
22 00014 <font class="comment"> */</font>
23 <a name="l00015"></a><a class="code" href="Lattice_8c.html#a1">00015</a> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a1">PrintLatticeUnion</a>(FILE *fp, <font class="keywordtype">char</font> *format, LatticeUnion *Head) {
24 00016
25 00017 LatticeUnion *temp;
26 00018
27 00019 <font class="keywordflow">for</font>(temp = Head; temp != NULL; temp = temp-&gt;next)
28 00020 <a class="code" href="matrix_8c.html#a2">Matrix_Print</a>(fp,format,(Matrix *)temp-&gt;M);
29 00021 <font class="keywordflow">return</font>;
30 00022 } <font class="comment">/* PrintLatticeUnion */</font>
31 00023
32 00024 <font class="comment">/* </font>
33 00025 <font class="comment"> * Free the memory allocated to a list of lattices 'Head' </font>
34 00026 <font class="comment"> */</font>
35 <a name="l00027"></a><a class="code" href="Lattice_8c.html#a2">00027</a> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a2">LatticeUnion_Free</a>(LatticeUnion *Head) {
36 00028
37 00029 LatticeUnion *temp;
38 00030
39 00031 <font class="keywordflow">while</font> (Head != NULL) {
40 00032 temp = Head;
41 00033 Head = temp-&gt;next;
42 00034 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp-&gt;M);
43 00035 free(temp);
44 00036 }
45 00037 <font class="keywordflow">return</font>;
46 00038 } <font class="comment">/* LatticeUnion_Free */</font>
47 00039
48 00040 <font class="comment">/* </font>
49 00041 <font class="comment"> * Allocate a heads for a list of Lattices</font>
50 00042 <font class="comment"> */</font>
51 <a name="l00043"></a><a class="code" href="Lattice_8c.html#a3">00043</a> LatticeUnion *<a class="code" href="Lattice_8c.html#a3">LatticeUnion_Alloc</a>(<font class="keywordtype">void</font>) {
52 00044
53 00045 LatticeUnion *temp;
54 00046
55 00047 temp = (LatticeUnion *)malloc(<font class="keyword">sizeof</font>(LatticeUnion));
56 00048 temp-&gt;M=NULL;
57 00049 temp-&gt;next=NULL;
58 00050 <font class="keywordflow">return</font> temp;
59 00051 } <font class="comment">/* LatticeUnion_Alloc */</font>
60 00052
61 00053 <font class="comment">/*</font>
62 00054 <font class="comment"> * Given two Lattices 'A' and 'B', return True if they have the same affine </font>
63 00055 <font class="comment"> * part (the last column) otherwise return 'False'. </font>
64 00056 <font class="comment"> */</font>
65 <a name="l00057"></a><a class="code" href="Lattice_8c.html#a4">00057</a> Bool <a class="code" href="Lattice_8c.html#a4">sameAffinepart</a> (Lattice *A, Lattice *B) {
66 00058
67 00059 <font class="keywordtype">int</font> i;
68 00060
69 00061 <font class="preprocessor">#ifdef DOMDEBUG</font>
70 00062 <font class="preprocessor"></font> FILE *fp;
71 00063 fp = fopen(<font class="stringliteral">"_debug"</font>,<font class="stringliteral">"a"</font>);
72 00064 fprintf(fp,<font class="stringliteral">"\nEntered SAMEAFFINEPART \n"</font>);
73 00065 fclose(fp);
74 00066 <font class="preprocessor">#endif</font>
75 00067 <font class="preprocessor"></font>
76 00068 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows; i ++)
77 00069 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(A-&gt;p[i][A-&gt;NbColumns-1],B-&gt;p[i][B-&gt;NbColumns-1]))
78 00070 <font class="keywordflow">return</font> False;
79 00071 <font class="keywordflow">return</font> True;
80 00072 } <font class="comment">/* sameAffinepart */</font>
81 00073
82 00074 <font class="comment">/*</font>
83 00075 <font class="comment"> * Return an empty lattice of dimension 'dimension-1'. An empty lattice is </font>
84 00076 <font class="comment"> * represented as [[0 0 ... 0] .... [0 ... 0][0 0.....0 1]]. </font>
85 00077 <font class="comment"> */</font>
86 <a name="l00078"></a><a class="code" href="Lattice_8c.html#a5">00078</a> Lattice *<a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(<font class="keywordtype">int</font> dimension) {
87 00079
88 00080 Lattice *result;
89 00081 <font class="keywordtype">int</font> i,j;
90 00082
91 00083 <font class="preprocessor">#ifdef DOMDEBUG</font>
92 00084 <font class="preprocessor"></font> FILE *fp;
93 00085 fp = fopen (<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
94 00086 fprintf (fp, <font class="stringliteral">"\nEntered NULLATTICE \n"</font>);
95 00087 fclose (fp);
96 00088 <font class="preprocessor">#endif</font>
97 00089 <font class="preprocessor"></font>
98 00090 result = (Lattice *) <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(dimension, dimension);
99 00091 <font class="keywordflow">for</font> (i = 0; i &lt; dimension; i ++)
100 00092 <font class="keywordflow">for</font> (j = 0; j &lt; dimension; j ++)
101 00093 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(result-&gt;p[i][j],0);
102 00094 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(result-&gt;p[i-1][i-1],1);
103 00095 <font class="keywordflow">return</font> result;
104 00096 } <font class="comment">/* EmptyLattice */</font>
105 00097
106 00098 <font class="comment">/*</font>
107 00099 <font class="comment"> * Return True if Lattice 'A' is empty, otherwise return False. </font>
108 00100 <font class="comment"> */</font>
109 <a name="l00101"></a><a class="code" href="Lattice_8c.html#a6">00101</a> Bool <a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a> (Lattice *A) {
110 00102
111 00103 <font class="keywordtype">int</font> i,j;
112 00104
113 00105 <font class="preprocessor">#ifdef DOMDEBUG</font>
114 00106 <font class="preprocessor"></font> FILE *fp;
115 00107 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
116 00108 fprintf(fp,<font class="stringliteral">"\nEntered ISNULLATTICE \n"</font>);
117 00109 fclose(fp);
118 00110 <font class="preprocessor">#endif</font>
119 00111 <font class="preprocessor"></font>
120 00112 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows-1; i ++)
121 00113 <font class="keywordflow">for</font> (j = 0; j &lt; A-&gt;NbColumns-1; j ++)
122 00114 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;p[i][j])) {
123 00115 <font class="keywordflow">return</font> False;
124 00116 }
125 00117 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a>(A-&gt;p[i][A-&gt;NbColumns-1])) {
126 00118 <font class="keywordflow">return</font> True ;
127 00119 }
128 00120 <font class="keywordflow">return</font> False ;
129 00121 } <font class="comment">/* isEmptyLaattice */</font>
130 00122
131 00123 <font class="comment">/*</font>
132 00124 <font class="comment"> * Given a Lattice 'A', check whether it is linear or not, i.e. whether the </font>
133 00125 <font class="comment"> * affine part is NULL or not. If affine part is empty, it returns True other-</font>
134 00126 <font class="comment"> * wise it returns False.</font>
135 00127 <font class="comment"> */</font>
136 <a name="l00128"></a><a class="code" href="Lattice_8c.html#a7">00128</a> Bool <a class="code" href="Lattice_8c.html#a7">isLinear</a>(Lattice *A) {
137 00129
138 00130 <font class="keywordtype">int</font> i;
139 00131
140 00132 <font class="preprocessor">#ifdef DOMDEBUG</font>
141 00133 <font class="preprocessor"></font> FILE *fp;
142 00134 fp = fopen (<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
143 00135 fprintf (fp, <font class="stringliteral">"\nEntered ISLINEAR \n"</font>);
144 00136 fclose (fp);
145 00137 <font class="preprocessor">#endif</font>
146 00138 <font class="preprocessor"></font>
147 00139 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows-1; i ++)
148 00140 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;p[i][A-&gt;NbColumns-1])) {
149 00141 <font class="keywordflow">return</font> False;
150 00142 }
151 00143 <font class="keywordflow">return</font> True;
152 00144 } <font class="comment">/* isLinear */</font>
153 00145
154 00146 <font class="comment">/* </font>
155 00147 <font class="comment"> * Return the affine Hermite normal form of the affine lattice 'A'. The unique </font>
156 00148 <font class="comment"> * affine Hermite form if a lattice is stored in 'H' and the unimodular matrix </font>
157 00149 <font class="comment"> * corresponding to 'A = H*U' is stored in the matrix 'U'. </font>
158 00150 <font class="comment"> * Algorithm : </font>
159 00151 <font class="comment"> * 1) Check if the Lattice is Linear or not.</font>
160 00152 <font class="comment"> * 2) If it is not Linear, then Homogenise the Lattice.</font>
161 00153 <font class="comment"> * 3) Call Hermite.</font>
162 00154 <font class="comment"> * 4) If the Lattice was Homogenised, the HNF H must be </font>
163 00155 <font class="comment"> * Dehomogenised and also corresponding changes must</font>
164 00156 <font class="comment"> * be made to the Unimodular Matrix U.</font>
165 00157 <font class="comment"> * 5) Return.</font>
166 00158 <font class="comment"> */</font>
167 <a name="l00159"></a><a class="code" href="Lattice_8c.html#a8">00159</a> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a8">AffineHermite</a> (Lattice *A, Lattice **H, Matrix **U) {
168 00160
169 00161 Lattice *temp;
170 00162 Bool flag = True;
171 00163
172 00164 <font class="preprocessor">#ifdef DOMDEBUG</font>
173 00165 <font class="preprocessor"></font> FILE *fp;
174 00166 fp = fopen (<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
175 00167 fprintf (fp, <font class="stringliteral">"\nEntered AFFINEHERMITE \n"</font>);
176 00168 fclose (fp);
177 00169 <font class="preprocessor">#endif</font>
178 00170 <font class="preprocessor"></font>
179 00171 <font class="keywordflow">if</font> (<a class="code" href="Lattice_8c.html#a7">isLinear</a>(A) == False)
180 00172 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a>(A,True);
181 00173 <font class="keywordflow">else</font> {
182 00174 flag = False ;
183 00175 temp = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(A);
184 00176 }
185 00177 <a class="code" href="NormalForms_8c.html#a16">Hermite</a>((Matrix *)temp,(Matrix **) H, U);
186 00178 <font class="keywordflow">if</font> (flag == True) {
187 00179 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) temp);
188 00180 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a>(H[0],False);
189 00181 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) H[0]);
190 00182 H[0] = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(temp);
191 00183 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) temp);
192 00184 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a>(U[0],False);
193 00185 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) U[0]);
194 00186 U[0] = (Matrix *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(temp);
195 00187 }
196 00188 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) temp);
197 00189 <font class="keywordflow">return</font>;
198 00190 } <font class="comment">/* AffineHermite */</font>
199 00191
200 00192 <font class="comment">/*</font>
201 00193 <font class="comment"> * Given a Polylib matrix 'A' that rerepresents an affine function, return the</font>
202 00194 <font class="comment"> * affine Smith normal form 'Delta' of 'A' and unimodular matrices 'U' and 'V'</font>
203 00195 <font class="comment"> * such that 'A = U*Delta*V'. </font>
204 00196 <font class="comment"> * Algorithm:</font>
205 00197 <font class="comment"> * (1) Homogenise the Lattice.</font>
206 00198 <font class="comment"> * (2) Call Smith</font>
207 00199 <font class="comment"> * (3) The Smith Normal Form Delta must be Dehomogenised and also </font>
208 00200 <font class="comment"> * corresponding changes must be made to the Unimodular Matrices </font>
209 00201 <font class="comment"> * U and V.</font>
210 00202 <font class="comment"> * 4) Bring Delta into AffineSmith Form.</font>
211 00203 <font class="comment"> */</font>
212 <a name="l00204"></a><a class="code" href="Lattice_8c.html#a9">00204</a> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a9">AffineSmith</a>(Lattice *A, Lattice **U, Lattice **V, Lattice **Diag) {
213 00205
214 00206 Lattice *temp;
215 00207 Lattice *Uinv;
216 00208 <font class="keywordtype">int</font> i,j;
217 00209 <a class="code" href="arithmetique_8h.html#a93">Value</a> sum, tmp, quo, rem;
218 00210
219 00211 <font class="preprocessor">#ifdef DOMDEBUG</font>
220 00212 <font class="preprocessor"></font> FILE *fp;
221 00213 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
222 00214 fprintf(fp,<font class="stringliteral">"\nEntered AFFINESMITH \n"</font>);
223 00215 fclose(fp);
224 00216 <font class="preprocessor">#endif</font>
225 00217 <font class="preprocessor"></font>
226 00218 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(sum); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
227 00219 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(quo); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(rem);
228 00220 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a>(A,True);
229 00221 <a class="code" href="NormalForms_8c.html#a15">Smith</a>((Matrix *)temp, (Matrix **)U, (Matrix **)V, (Matrix **)Diag);
230 00222 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)temp);
231 00223
232 00224 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a> (*U, False);
233 00225 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) *U);
234 00226 *U = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> ((Matrix *)temp);
235 00227 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)temp);
236 00228
237 00229 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a> (*V, False);
238 00230 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)*V);
239 00231 *V = (Lattice *) <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> ((Matrix *)temp);
240 00232 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)temp);
241 00233
242 00234 temp = <a class="code" href="Lattice_8c.html#a10">Homogenise</a> (*Diag, False);
243 00235 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)*Diag);
244 00236 *Diag = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> ((Matrix *)temp);
245 00237 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)temp);
246 00238
247 00239 temp = (Lattice *) <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> ((Matrix *) *U);
248 00240 Uinv = (Lattice *) <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a> (U[0]-&gt;NbRows, U[0]-&gt;NbColumns);
249 00241 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>( (Matrix *) temp, (Matrix *) Uinv);
250 00242 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) temp);
251 00243
252 00244 <font class="keywordflow">for</font> (i = 0; i &lt; U[0]-&gt;NbRows-1; i ++) {
253 00245 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(sum,0);
254 00246 <font class="keywordflow">for</font>(j = 0; j &lt; U[0]-&gt;NbColumns-1; j ++) {
255 00247 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,Uinv-&gt;p[i][j],U[0]-&gt;p[j][U[0]-&gt;NbColumns-1]);
256 00248 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(sum,sum,tmp);
257 00249 }
258 00250 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Diag[0]-&gt;p[i][j],sum);
259 00251 }
260 00252 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) Uinv);
261 00253 <font class="keywordflow">for</font>(i = 0; i &lt; U[0]-&gt;NbRows-1; i ++)
262 00254 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(U[0]-&gt;p[i][U[0]-&gt;NbColumns-1],0);
263 00255 <font class="keywordflow">for</font>(i = 0; i &lt; Diag[0]-&gt;NbRows-1; i ++) {
264 00256 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(quo,Diag[0]-&gt;p[i][Diag[0]-&gt;NbColumns-1],Diag[0]-&gt;p[i][i]);
265 00257 <a class="code" href="arithmetique_8h.html#a52">value_modulus</a>(rem,Diag[0]-&gt;p[i][Diag[0]-&gt;NbColumns-1],Diag[0]-&gt;p[i][i]);
266 00258
267 00259 fprintf(stdout,<font class="stringliteral">" pourcent "</font>);
268 00260 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stdout,<a class="code" href="arithmetique_8h.html#a5">VALUE_FMT</a>,rem);
269 00261 fprintf(stdout,<font class="stringliteral">" quotient "</font>);
270 00262 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stdout,<a class="code" href="arithmetique_8h.html#a5">VALUE_FMT</a>,quo);
271 00263 fprintf(stdout,<font class="stringliteral">" \n"</font>);
272 00264
273 00265 <font class="comment">/* Apparently the % operator is strange when sign are different */</font>
274 00266 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a64">value_neg_p</a>(rem)) {
275 00267 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(rem,rem,Diag[0]-&gt;p[i][i]);
276 00268 <a class="code" href="arithmetique_8h.html#a50">value_decrement</a>(quo,quo);
277 00269 };
278 00270 fprintf(stdout,<font class="stringliteral">"apres pourcent "</font>);
279 00271 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stdout,<a class="code" href="arithmetique_8h.html#a5">VALUE_FMT</a>,rem);
280 00272 fprintf(stdout,<font class="stringliteral">" quotient "</font>);
281 00273 <a class="code" href="arithmetique_8h.html#a16">value_print</a>(stdout,<a class="code" href="arithmetique_8h.html#a5">VALUE_FMT</a>,quo);
282 00274 fprintf(stdout,<font class="stringliteral">" \n"</font>);
283 00275 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>( Diag[0]-&gt;p[i][Diag[0]-&gt;NbColumns-1],rem);
284 00276 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(V[0]-&gt;p[i][V[0]-&gt;NbColumns-1],quo);
285 00277 }
286 00278 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(sum); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
287 00279 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(quo); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(rem);
288 00280 <font class="keywordflow">return</font>;
289 00281 } <font class="comment">/* AffineSmith */</font>
290 00282
291 00283 <font class="comment">/*</font>
292 00284 <font class="comment"> * Given a lattice 'A' and a boolean variable 'Forward', homogenise the lattice</font>
293 00285 <font class="comment"> * if 'Forward' is True, otherwise if 'Forward' is False, dehomogenise the </font>
294 00286 <font class="comment"> * lattice 'A'. </font>
295 00287 <font class="comment"> * Algorithm: </font>
296 00288 <font class="comment"> * (1) If Forward == True</font>
297 00289 <font class="comment"> * Put the last row first. </font>
298 00290 <font class="comment"> * Put the last columns first. </font>
299 00291 <font class="comment"> * (2) Else </font>
300 00292 <font class="comment"> * Put the first row last. </font>
301 00293 <font class="comment"> * Put the first column last.</font>
302 00294 <font class="comment"> * (3) Return the result. </font>
303 00295 <font class="comment"> */</font>
304 <a name="l00296"></a><a class="code" href="Lattice_8c.html#a10">00296</a> Lattice *<a class="code" href="Lattice_8c.html#a10">Homogenise</a>(Lattice *A, Bool Forward) {
305 00297
306 00298 Lattice *result;
307 00299
308 00300 <font class="preprocessor">#ifdef DOMDEBUG</font>
309 00301 <font class="preprocessor"></font> FILE *fp;
310 00302 fp = fopen(<font class="stringliteral">"_debug"</font>,<font class="stringliteral">"a"</font>);
311 00303 fprintf(fp,<font class="stringliteral">"\nEntered HOMOGENISE \n"</font>);
312 00304 fclose(fp);
313 00305 <font class="preprocessor">#endif</font>
314 00306 <font class="preprocessor"></font>
315 00307 result = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(A);
316 00308 <font class="keywordflow">if</font> (Forward == True ) {
317 00309 <a class="code" href="Matop_8c.html#a10">PutColumnFirst</a>((Matrix *)result, A-&gt;NbColumns-1);
318 00310 <a class="code" href="Matop_8c.html#a9">PutRowFirst</a>((Matrix *)result, result-&gt;NbRows-1);
319 00311 }
320 00312 <font class="keywordflow">else</font> {
321 00313 <a class="code" href="Matop_8c.html#a11">PutColumnLast</a>((Matrix *)result,0);
322 00314 <a class="code" href="Matop_8c.html#a8">PutRowLast</a>((Matrix *)result,0);
323 00315 }
324 00316 <font class="keywordflow">return</font> result;
325 00317 } <font class="comment">/* Homogenise */</font>
326 00318
327 00319 <font class="comment">/*</font>
328 00320 <font class="comment"> * Given two lattices 'A' and 'B', verify if lattice 'A' is included in 'B' or</font>
329 00321 <font class="comment"> * not. If 'A' is included in 'B' the 'A' intersection 'B', will be 'A'. So, </font>
330 00322 <font class="comment"> * compute 'A' intersection 'B' and check if it is the same as 'A'. </font>
331 00323 <font class="comment"> */</font>
332 <a name="l00324"></a><a class="code" href="Lattice_8c.html#a11">00324</a> Bool <a class="code" href="Lattice_8c.html#a11">LatticeIncludes</a>(Lattice *A, Lattice *B) {
333 00325
334 00326 Lattice *temp, *UA, *HA;
335 00327 Bool flag = False;
336 00328
337 00329 <font class="preprocessor">#ifdef DOMDEBUG</font>
338 00330 <font class="preprocessor"></font> FILE *fp;
339 00331 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
340 00332 fprintf(fp,<font class="stringliteral">"\nEntered LATTICE INCLUDES \n"</font>);
341 00333 fclose(fp);
342 00334 <font class="preprocessor">#endif</font>
343 00335 <font class="preprocessor"></font>
344 00336 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(A,&amp;HA,&amp;UA);
345 00337 temp = <a class="code" href="Lattice_8c.html#a16">LatticeIntersection</a>(B,HA);
346 00338 <font class="keywordflow">if</font> (<a class="code" href="Lattice_8c.html#a12">sameLattice</a>(temp, HA) == True)
347 00339 flag = True;
348 00340
349 00341 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)temp);
350 00342 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)UA);
351 00343 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)HA);
352 00344 <font class="keywordflow">return</font> flag;
353 00345 } <font class="comment">/* LatticeIncludes */</font>
354 00346
355 00347 <font class="comment">/*</font>
356 00348 <font class="comment"> * Given two lattices 'A' and 'B', verify if 'A' and 'B' are the same lattice.</font>
357 00349 <font class="comment"> * Algorithm: </font>
358 00350 <font class="comment"> * The Affine Hermite form of two full dimensional matrices are </font>
359 00351 <font class="comment"> * unique. So, take the Affine Hermite form of both 'A' and 'B' and compare the</font>
360 00352 <font class="comment"> * matrices. If they are equal, the function returns True, else it returns </font>
361 00353 <font class="comment"> * False. </font>
362 00354 <font class="comment"> */</font>
363 <a name="l00355"></a><a class="code" href="Lattice_8c.html#a12">00355</a> Bool <a class="code" href="Lattice_8c.html#a12">sameLattice</a>(Lattice *A, Lattice *B) {
364 00356
365 00357 Lattice *HA, *HB, *UA, *UB;
366 00358 <font class="keywordtype">int</font> i,j;
367 00359 Bool result = True;
368 00360
369 00361 <font class="preprocessor">#ifdef DOMDEBUG</font>
370 00362 <font class="preprocessor"></font> FILE *fp;
371 00363 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
372 00364 fprintf(fp,<font class="stringliteral">"\nEntered SAME LATTICE \n"</font>);
373 00365 fclose(fp);
374 00366 <font class="preprocessor">#endif</font>
375 00367 <font class="preprocessor"></font>
376 00368 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(A, &amp;HA, &amp;UA);
377 00369 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(B, &amp;HB, &amp;UB);
378 00370
379 00371 <font class="keywordflow">for</font> (i = 0 ; i &lt; A-&gt;NbRows; i ++)
380 00372 <font class="keywordflow">for</font> (j = 0; j &lt; A-&gt;NbColumns; j ++)
381 00373 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(HA-&gt;p[i][j],HB-&gt;p[i][j])) {
382 00374 result = False;
383 00375 <font class="keywordflow">break</font>;
384 00376 }
385 00377
386 00378 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) HA);
387 00379 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) HB);
388 00380 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) UA);
389 00381 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) UB);
390 00382
391 00383 <font class="keywordflow">return</font> result;
392 00384 } <font class="comment">/* sameLattice */</font>
393 00385
394 00386 <font class="comment">/*</font>
395 00387 <font class="comment"> * Given a matrix 'A' and an integer 'dimension', do the following: </font>
396 00388 <font class="comment"> * If dimension &lt; A-&gt;dimension), output a (dimension * dimension) submatrix of </font>
397 00389 <font class="comment"> * A. Otherwise the output matrix is [A 0][0 ID]. The order if the identity </font>
398 00390 <font class="comment"> * matrix is (dimension - A-&gt;dimension). The input matrix is not necessarily </font>
399 00391 <font class="comment"> * a Polylib matrix but the output is a polylib matrix. </font>
400 00392 <font class="comment"> */</font>
401 <a name="l00393"></a><a class="code" href="Lattice_8c.html#a13">00393</a> Lattice *<a class="code" href="Lattice_8c.html#a13">ChangeLatticeDimension</a>(Lattice *A, <font class="keywordtype">int</font> dimension) {
402 00394
403 00395 <font class="keywordtype">int</font> i, j;
404 00396 Lattice *Result ;
405 00397
406 00398 Result = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(dimension, dimension);
407 00399 <font class="keywordflow">if</font>(dimension &lt;= A-&gt;NbRows) {
408 00400 <font class="keywordflow">for</font> (i = 0; i &lt; dimension; i ++)
409 00401 <font class="keywordflow">for</font> (j = 0; j &lt; dimension; j ++)
410 00402 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Result-&gt;p[i][j],A-&gt;p[i][j]);
411 00403 <font class="keywordflow">return</font> Result;
412 00404 }
413 00405 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows; i ++)
414 00406 <font class="keywordflow">for</font> (j = 0; j &lt; A-&gt;NbRows; j ++)
415 00407 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Result-&gt;p[i][j],A-&gt;p[i][j]);
416 00408
417 00409 <font class="keywordflow">for</font> (i = A-&gt;NbRows; i &lt; dimension; i ++)
418 00410 <font class="keywordflow">for</font> (j = 0; j &lt; dimension; j ++) {
419 00411 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Result-&gt;p[i][j],0);
420 00412 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Result-&gt;p[j][i],0);
421 00413 }
422 00414 <font class="keywordflow">for</font> (i = A-&gt;NbRows; i &lt; dimension; i ++)
423 00415 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Result-&gt;p[i][i],1);
424 00416 <font class="keywordflow">return</font> Result;
425 00417 } <font class="comment">/* ChangeLatticeDimension */</font>
426 00418
427 00419 <font class="comment">/* </font>
428 00420 <font class="comment"> * Given an affine lattice 'A', return a matrix of the linear part of the </font>
429 00421 <font class="comment"> * lattice. </font>
430 00422 <font class="comment"> */</font>
431 <a name="l00423"></a><a class="code" href="Lattice_8c.html#a14">00423</a> Lattice *<a class="code" href="Lattice_8c.html#a14">ExtractLinearPart</a>(Lattice *A) {
432 00424
433 00425 Lattice *Result;
434 00426 <font class="keywordtype">int</font> i, j;
435 00427 Result = (Lattice *) <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(A-&gt;NbRows-1, A-&gt;NbColumns-1);
436 00428 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows-1; i ++)
437 00429 <font class="keywordflow">for</font> (j = 0; j &lt; A-&gt;NbColumns-1; j ++)
438 00430 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Result-&gt;p[i][j],A-&gt;p[i][j]);
439 00431 <font class="keywordflow">return</font> Result;
440 00432 } <font class="comment">/* ExtractLinearPart */</font>
441 00433
442 00434 <font class="keyword">static</font> Matrix *<a class="code" href="Lattice_8c.html#a17">MakeDioEqforInter</a>(Matrix *A, Matrix *B);
443 00435
444 00436 <font class="comment">/*</font>
445 00437 <font class="comment"> * Given two lattices 'A' and 'B', return the intersection of the two lattcies.</font>
446 00438 <font class="comment"> * The dimension of 'A' and 'B' should be the same. </font>
447 00439 <font class="comment"> * Algorithm:</font>
448 00440 <font class="comment"> * (1) Verify if the lattcies 'A' and 'B' have the same affine part. </font>
449 00441 <font class="comment"> * If they have same affine part, then only their Linear parts </font>
450 00442 <font class="comment"> * need to be intersected. If they don't have the same affine</font>
451 00443 <font class="comment"> * part then the affine part has to be taken into consideration. </font>
452 00444 <font class="comment"> * For this, homogenise the lattices to get their Hermite Forms</font>
453 00445 <font class="comment"> * and then find their intersection.</font>
454 00446 <font class="comment"> *</font>
455 00447 <font class="comment"> * (2) Step(2) involves, solving the Diophantine Equations in order </font>
456 00448 <font class="comment"> * to extract the intersection of the Lattices. The Diophantine</font>
457 00449 <font class="comment"> * equations are formed taking into consideration whether the </font>
458 00450 <font class="comment"> * affine part has to be included or not. </font>
459 00451 <font class="comment"> *</font>
460 00452 <font class="comment"> * (3) Solve the Diophantine equations. </font>
461 00453 <font class="comment"> *</font>
462 00454 <font class="comment"> * (4) Extract the necessary information from the result. </font>
463 00455 <font class="comment"> * </font>
464 00456 <font class="comment"> * (5) If the lattices have different affine parts and they were </font>
465 00457 <font class="comment"> * homogenised, the result is dehomogenised. </font>
466 00458 <font class="comment"> */</font>
467 <a name="l00459"></a><a class="code" href="Lattice_8c.html#a16">00459</a> Lattice *<a class="code" href="Lattice_8c.html#a16">LatticeIntersection</a>(Lattice *X, Lattice *Y) {
468 00460
469 00461 <font class="keywordtype">int</font> i, j, exist;
470 00462 Lattice *result = NULL, *U = NULL ;
471 00463 Lattice *A = NULL, *B = NULL, *H = NULL;
472 00464 Matrix *fordio;
473 00465 Vector *X1 = NULL;
474 00466
475 00467 <font class="preprocessor">#ifdef DOMDEBUG</font>
476 00468 <font class="preprocessor"></font> FILE *fp;
477 00469 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
478 00470 fprintf(fp,<font class="stringliteral">"\nEntered LATTICEINTERSECTION \n"</font>);
479 00471 fclose(fp);
480 00472 <font class="preprocessor">#endif</font>
481 00473 <font class="preprocessor"></font>
482 00474 <font class="keywordflow">if</font> (X-&gt;NbRows != X-&gt;NbColumns) {
483 00475 fprintf(stderr, <font class="stringliteral">"\nIn LatticeIntersection : The Input Matrix X is a not a well defined Lattice\n"</font>);
484 00476 <font class="keywordflow">return</font> <a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(X-&gt;NbRows);
485 00477 }
486 00478
487 00479 <font class="keywordflow">if</font> (Y-&gt;NbRows != Y-&gt;NbColumns) {
488 00480 fprintf (stderr, <font class="stringliteral">"\nIn LatticeIntersection : The Input Matrix Y is a not a well defined Lattice\n"</font>);
489 00481 <font class="keywordflow">return</font> <a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(X-&gt;NbRows);
490 00482 }
491 00483
492 00484 <font class="keywordflow">if</font> (Y-&gt;NbRows != X-&gt;NbRows) {
493 00485 fprintf (stderr, <font class="stringliteral">"\nIn LatticeIntersection : The Input Lattices X and Y are of incompatible dimensions\n"</font>);
494 00486 <font class="keywordflow">return</font> <a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(X-&gt;NbRows);
495 00487 }
496 00488
497 00489 <font class="keywordflow">if</font> (<a class="code" href="Matop_8c.html#a7">isinHnf</a>(X))
498 00490 A = (Lattice *) <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(X);
499 00491 <font class="keywordflow">else</font> {
500 00492 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(X, &amp;H, &amp;U);
501 00493 A = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> (H);
502 00494 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) H);
503 00495 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) U);
504 00496 }
505 00497
506 00498 <font class="keywordflow">if</font> (<a class="code" href="Matop_8c.html#a7">isinHnf</a>(Y))
507 00499 B = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(Y);
508 00500 <font class="keywordflow">else</font> {
509 00501 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(Y, &amp;H, &amp;U);
510 00502 B = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a> (H);
511 00503 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) H);
512 00504 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) U);
513 00505 }
514 00506
515 00507 <font class="keywordflow">if</font> ((<a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a>(A)) || (<a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a> (B))) {
516 00508 result = <a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(X-&gt;NbRows);
517 00509 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) A);
518 00510 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *) B);
519 00511 <font class="keywordflow">return</font> result;
520 00512 }
521 00513 fordio = <a class="code" href="Lattice_8c.html#a17">MakeDioEqforInter</a> (A, B);
522 00514 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (A);
523 00515 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (B);
524 00516 exist = <a class="code" href="SolveDio_8c.html#a1">SolveDiophantine</a>(fordio,(Matrix **) &amp;U, &amp;X1);
525 00517 <font class="keywordflow">if</font> (exist &lt; 0) { <font class="comment">/* Intersection is NULL */</font>
526 00518 result = (<a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(X-&gt;NbRows));
527 00519 <font class="keywordflow">return</font> result;
528 00520 }
529 00521
530 00522 result = (Lattice *)<a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(X-&gt;NbRows, X-&gt;NbColumns);
531 00523 <font class="keywordflow">for</font> (i = 0; i &lt; result-&gt;NbRows-1; i ++)
532 00524 <font class="keywordflow">for</font> (j = 0; j &lt; result-&gt;NbColumns-1; j ++)
533 00525 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(result-&gt;p[i][j],U-&gt;p[i][j]);
534 00526
535 00527 <font class="keywordflow">for</font> (i = 0; i &lt; result-&gt;NbRows-1; i ++)
536 00528 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(result-&gt;p[i][result-&gt;NbColumns-1],X1-&gt;p[i]);
537 00529 <font class="keywordflow">for</font> (i = 0; i &lt; result-&gt;NbColumns-1; i ++)
538 00530 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(result-&gt;p[result-&gt;NbRows-1][i],0);
539 00531 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(result-&gt;p[result-&gt;NbRows-1][result-&gt;NbColumns-1],1);
540 00532
541 00533 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) U);
542 00534 <a class="code" href="vector_8c.html#a6">Vector_Free</a>(X1);
543 00535 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(fordio);
544 00536
545 00537 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(result,&amp;H,&amp;U);
546 00538 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)result);
547 00539 result = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(H);
548 00540
549 00541 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) H);
550 00542 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *) U);
551 00543
552 00544 <font class="comment">/* Check whether the Lattice is NULL or not */</font>
553 00545
554 00546 <font class="keywordflow">if</font> (<a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a> (result)) {
555 00547 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> ((Matrix *)result);
556 00548 <font class="keywordflow">return</font> (<a class="code" href="Lattice_8c.html#a5">EmptyLattice</a> (X-&gt;NbRows));
557 00549 }
558 00550 <font class="keywordflow">return</font> result;
559 00551 } <font class="comment">/* LatticeIntersection */</font>
560 00552
561 <a name="l00553"></a><a class="code" href="Lattice_8c.html#a17">00553</a> <font class="keyword">static</font> Matrix * <a class="code" href="Lattice_8c.html#a17">MakeDioEqforInter</a> (Lattice *A, Lattice *B) {
562 00554
563 00555 Matrix *Dio ;
564 00556 <font class="keywordtype">int</font> i,j;
565 00557
566 00558 <font class="preprocessor">#ifdef DOMDEBUG</font>
567 00559 <font class="preprocessor"></font> FILE *fp;
568 00560 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
569 00561 fprintf(fp,<font class="stringliteral">"\nEntered MAKEDIOEQFORINTER \n"</font>);
570 00562 fclose(fp);
571 00563 <font class="preprocessor">#endif</font>
572 00564 <font class="preprocessor"></font>
573 00565 Dio = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(2*(A-&gt;NbRows-1) + 1, 3 * (A-&gt;NbColumns-1)+1);
574 00566
575 00567 <font class="keywordflow">for</font> (i = 0; i &lt; Dio-&gt;NbRows; i ++)
576 00568 <font class="keywordflow">for</font> (j = 0; j &lt; Dio-&gt;NbColumns; j ++)
577 00569 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[i][j],0);
578 00570
579 00571 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows-1; i++) {
580 00572 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[i][i],1);
581 00573 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[i+A-&gt;NbRows-1][i],1);
582 00574 }
583 00575 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRows-1 ; i ++)
584 00576 <font class="keywordflow">for</font> (j = 0; j &lt; A-&gt;NbRows-1; j ++) {
585 00577 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Dio-&gt;p[i][j+A-&gt;NbRows-1],A-&gt;p[i][j]);
586 00578 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Dio-&gt;p[i+(A-&gt;NbRows-1)][j+2*(A-&gt;NbRows-1)],B-&gt;p[i][j]);
587 00579 }
588 00580
589 00581 <font class="comment">/* Adding the affine part */</font>
590 00582
591 00583 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbColumns-1; i++) {
592 00584 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Dio-&gt;p[i][Dio-&gt;NbColumns-1],A-&gt;p[i][A-&gt;NbColumns-1]);
593 00585 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Dio-&gt;p[i+A-&gt;NbRows-1][Dio-&gt;NbColumns-1],B-&gt;p[i][A-&gt;NbColumns-1]) ;
594 00586 }
595 00587 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[Dio-&gt;NbRows-1][Dio-&gt;NbColumns-1],1);
596 00588 <font class="keywordflow">return</font> Dio;
597 00589 } <font class="comment">/* MakeDioEqforInter */</font>
598 00590
599 00591 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a18">AddLattice</a>(LatticeUnion *,Matrix *, Matrix *, <font class="keywordtype">int</font> , <font class="keywordtype">int</font>);
600 00592 LatticeUnion *<a class="code" href="Lattice_8c.html#a22">SplitLattice</a>(Matrix *, Matrix *, Matrix *);
601 00593
602 00594
603 00595
604 00596 <font class="comment">/*</font>
605 00597 <font class="comment"> * The function is transforming a lattice X in a union of lattices based on a starting lattice Y.</font>
606 00598 <font class="comment"> * Note1: If the intersection of X and Y lattices is empty the result is identic with the first argument (X) because no operation can be made.</font>
607 00599 <font class="comment"> *Note2: The function is availabe only for simple Lattices and not for a union of Lattices.</font>
608 00600 <font class="comment"></font>
609 00601 <font class="comment"> * Step 1: Find Intersection = LatticeIntersection (A, B).</font>
610 00602 <font class="comment"> * Step 2: Extract the Linear Parts of the Lattices A and Intersection.</font>
611 00603 <font class="comment"> * (while dealing with Basis we only deal with the Linear Parts)</font>
612 00604 <font class="comment"> * Step 3: Let M1 = Basis of A and M2 = Basis of B.</font>
613 00605 <font class="comment"> * Let B1 and B2 be the Basis of A and B respectively, </font>
614 00606 <font class="comment"> * corresponding to the above Theorem.</font>
615 00607 <font class="comment"> * Then we Have B1 = M1 * U1 {a unimodular Matrix }</font>
616 00608 <font class="comment"> * and B2 = M2 * U2. M1 and M2 we know, they are the linear </font>
617 00609 <font class="comment"> * parts we obtained in Step 2. Our Task is now to find U1 and</font>
618 00610 <font class="comment"> * U2. </font>
619 00611 <font class="comment"> * We know that B1 * Delta = B2.</font>
620 00612 <font class="comment"> * i.e. M1 * U1 * Delta = M2 * U2</font>
621 00613 <font class="comment"> * or U1*Delta*U2Inverse = M1Inverse * M2.</font>
622 00614 <font class="comment"> * and Delta is the Diagonal Matrix which satisifies the </font>
623 00615 <font class="comment"> * above properties (in the Theorem).</font>
624 00616 <font class="comment"> * So Delta is nothing but the Smith Normal Form of </font>
625 00617 <font class="comment"> * M1Inverse * M2.</font>
626 00618 <font class="comment"> * So, first we have to find M1Inverse.</font>
627 00619 <font class="comment"> * </font>
628 00620 <font class="comment"> * This Step, involves finding the Inverse of the Matrix M1.</font>
629 00621 <font class="comment"> * We find the Inverse using the Polylib function </font>
630 00622 <font class="comment"> * Matrix_Inverse. There is a catch here, the result of this</font>
631 00623 <font class="comment"> * function is an integral matrix, not necessarily the exact</font>
632 00624 <font class="comment"> * Inverse (since M1 need not be Unimodular), but a multiple</font>
633 00625 <font class="comment"> * of the actual inverse. The number by which we have to divide</font>
634 00626 <font class="comment"> * the matrix, is not obtained here as the input matrix is not</font>
635 00627 <font class="comment"> * a Polylib matrix { We input only the Linear part }. Later I</font>
636 00628 <font class="comment"> * give a way for finding that number.</font>
637 00629 <font class="comment"> *</font>
638 00630 <font class="comment"> * M1Inverse = Matrix_Inverse ( M1 );</font>
639 00631 <font class="comment"> * </font>
640 00632 <font class="comment"> * Step 4 : MtProduct = Matrix_Product (M1Inverse, M2);</font>
641 00633 <font class="comment"> * Step 5 : SmithNormalFrom (MtProduct, Delta, U, V);</font>
642 00634 <font class="comment"> * U1 = U and U2Inverse = V.</font>
643 00635 <font class="comment"> * Step 6 : Find U2 = Matrix_Inverse (U2inverse). Here there is no prob</font>
644 00636 <font class="comment"> * as U1 and its inverse are unimodular.</font>
645 00637 <font class="comment"> * </font>
646 00638 <font class="comment"> * Step 7 : Compute B1 = M1 * U1;</font>
647 00639 <font class="comment"> * Step 8 : Compute B2 = M2 * U2;</font>
648 00640 <font class="comment"> * Step 9 : Earlier when we computed M1Inverse, we knew that it was not</font>
649 00641 <font class="comment"> * the exact inverse but a multiple of it. Now we find the </font>
650 00642 <font class="comment"> * number, such that ( M1Inverse / number ) would give us the </font>
651 00643 <font class="comment"> * exact inverse of M1.</font>
652 00644 <font class="comment"> * We know that B1 * Delta = B2.</font>
653 00645 <font class="comment"> * Let k = B2[0][0] / B1[0][0].</font>
654 00646 <font class="comment"> * Let number = Delta[0][0]/k;</font>
655 00647 <font class="comment"> * This 'number' is the number we want.</font>
656 00648 <font class="comment"> * We Divide the matrix Delta by this number, to get the actual</font>
657 00649 <font class="comment"> * Delta such that B1 * Delta = B2.</font>
658 00650 <font class="comment"> * Step 10 : Call Split Lattice (B1, B2, Delta ).</font>
659 00651 <font class="comment"> * This function returns the Union of Lattices in such a way </font>
660 00652 <font class="comment"> * that B2 is at the Head of this List.</font>
661 00653 <font class="comment"> *</font>
662 00654 <font class="comment"> *If the intersection between X and Y is empty then the result is NULL.</font>
663 00655 <font class="comment"> */</font>
664 00656
665 00657
666 <a name="l00658"></a><a class="code" href="Lattice_8c.html#a20">00658</a> LatticeUnion *<a class="code" href="Lattice_8c.html#a20">Lattice2LatticeUnion</a>(Lattice *X,Lattice *Y)
667 00659 {
668 00660 Lattice *B1 = NULL, *B2 = NULL, *newB1 = NULL, *newB2 = NULL, *Intersection=NULL;
669 00661 Matrix *U = NULL,*M1 = NULL, *M2 = NULL, *M1Inverse = NULL,*MtProduct = NULL;
670 00662 Matrix *Vinv, *V , *temp, *DiagMatrix ;
671 00663
672 00664 LatticeUnion *Head = NULL, *tempHead = NULL;
673 00665 <font class="keywordtype">int</font> i;
674 00666 <a class="code" href="arithmetique_8h.html#a93">Value</a> k;
675 00667
676 00668
677 00669 Intersection = <a class="code" href="Lattice_8c.html#a16">LatticeIntersection</a>(X,Y);
678 00670 <font class="keywordflow">if</font> (<a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a>(Intersection) == True) {
679 00671 fprintf(stderr,<font class="stringliteral">"\nIn Lattice2LatticeUnion : The Input Lattices X and Y does not have any common part\n"</font>);
680 00672 <font class="keywordflow">return</font> NULL;
681 00673 }
682 00674
683 00675 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(k);
684 00676 M1 = (Matrix *)<a class="code" href="Lattice_8c.html#a14">ExtractLinearPart</a>(X);
685 00677 M2 = (Matrix *)<a class="code" href="Lattice_8c.html#a14">ExtractLinearPart</a>(Intersection);
686 00678
687 00679 M1Inverse = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(M1-&gt;NbRows,M1-&gt;NbColumns);
688 00680 temp = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(M1);
689 00681 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>(temp,M1Inverse);
690 00682 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp);
691 00683
692 00684 MtProduct = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(M1-&gt;NbRows, M1-&gt;NbColumns);
693 00685 <a class="code" href="matrix_8c.html#a12">Matrix_Product</a>(M1Inverse,M2,MtProduct) ;
694 00686 <a class="code" href="NormalForms_8c.html#a15">Smith</a>(MtProduct, &amp;U, &amp;Vinv, &amp;DiagMatrix);
695 00687 V = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(Vinv-&gt;NbRows,Vinv-&gt;NbColumns);
696 00688 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>(Vinv, V);
697 00689 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Vinv);
698 00690 B1 = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(M1-&gt;NbRows, U-&gt;NbColumns);
699 00691 B2 = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(M2-&gt;NbRows, V-&gt;NbColumns);
700 00692 <a class="code" href="matrix_8c.html#a12">Matrix_Product</a>(M1, U, B1);
701 00693 <a class="code" href="matrix_8c.html#a12">Matrix_Product</a>(M2, V, B2);
702 00694 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(M1);
703 00695 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(M2);
704 00696 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(k,B2-&gt;p[0][0],B1-&gt;p[0][0]);
705 00697 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(k,DiagMatrix-&gt;p[0][0],k);
706 00698 <font class="keywordflow">for</font> (i = 0; i &lt; DiagMatrix-&gt;NbRows; i++)
707 00699 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(DiagMatrix-&gt;p[i][i],DiagMatrix-&gt;p[i][i],k);
708 00700 newB1 = <a class="code" href="Lattice_8c.html#a13">ChangeLatticeDimension</a>(B1, B1-&gt;NbRows + 1);
709 00701 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(B1);
710 00702 newB2 = <a class="code" href="Lattice_8c.html#a13">ChangeLatticeDimension</a>(B2, B2-&gt;NbRows +1);
711 00703 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(B2);
712 00704 <font class="keywordflow">for</font>(i = 0; i &lt; newB1-&gt;NbRows - 1;i ++)
713 00705 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(newB2-&gt;p[i][newB1-&gt;NbRows-1],Intersection-&gt;p[i][X-&gt;NbRows-1]);
714 00706 Head = <a class="code" href="Lattice_8c.html#a22">SplitLattice</a>(newB1,newB2,DiagMatrix);
715 00707 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(newB1);
716 00708 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(DiagMatrix);
717 00709 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(k);
718 00710 <font class="keywordflow">return</font> Head;
719 00711 }
720 00712
721 00713
722 00714 <font class="comment"></font>
723 00715 <font class="comment">/**</font>
724 00716 <font class="comment"></font>
725 00717 <font class="comment">*** Method : </font>
726 00718 <font class="comment">*** </font>
727 00719 <font class="comment">**/</font>
728 00720 <font class="comment">/* </font>
729 00721 <font class="comment"> * Return the Union of lattices that constitute the difference the lattices </font>
730 00722 <font class="comment"> * 'A' and 'B'. The dimensions of 'A' and 'B' should be the same. </font>
731 00723 <font class="comment"> * Note :</font>
732 00724 <font class="comment"> * Inorder to Find the Difference of Lattices, we make use of</font>
733 00725 <font class="comment"> * the following facts.</font>
734 00726 <font class="comment"> * </font>
735 00727 <font class="comment"> * Theorem : Given Two Lattices L1 and L2, (L2 subset of L1) there exists a</font>
736 00728 <font class="comment"> * Basis B = {b1, b2,..bn} of L1 and integers {a1, a2...,an} such </font>
737 00729 <font class="comment"> * that a1 divides a2, a2 divides a3 and so on and {a1b1, a2b2 ,...,</font>
738 00730 <font class="comment"> * .., anbn} is a Basis of L2. So given this theorem we can express </font>
739 00731 <font class="comment"> * the Lattice L1 in terms of Union of Lattices Involving L2, such </font>
740 00732 <font class="comment"> * that Lattice L1 = B1 = Union of (B2 + i1b1 + i2b2 + .. inbn) such</font>
741 00733 <font class="comment"> * that 0 &lt;= i1 &lt; a1; 0 &lt;= i2 &lt; a2; ....... 0 &lt;= in &lt; an. We also</font>
742 00734 <font class="comment"> * know that A/B = A/(A Intersection B) and that (A Intersection B) </font>
743 00735 <font class="comment"> * is a subset of A. So, Making use of these two facts, we find the </font>
744 00736 <font class="comment"> * A/B. We Split The Lattice A in terms of Lattice (A Int B). From </font>
745 00737 <font class="comment"> * this Union of Lattices Delete the Lattice (A Int B).</font>
746 00738 <font class="comment"> *</font>
747 00739 <font class="comment"> * Algorithm : </font>
748 00740 <font class="comment"> *</font>
749 00741 <font class="comment"> * Step 1: Find Intersection = LatticeIntersection (A, B).</font>
750 00742 <font class="comment"> * Step 2: Extract the Linear Parts of the Lattices A and Intersection.</font>
751 00743 <font class="comment"> * (while dealing with Basis we only deal with the Linear Parts)</font>
752 00744 <font class="comment"> * Step 3: Let M1 = Basis of A and M2 = Basis of B.</font>
753 00745 <font class="comment"> * Let B1 and B2 be the Basis of A and B respectively, </font>
754 00746 <font class="comment"> * corresponding to the above Theorem.</font>
755 00747 <font class="comment"> * Then we Have B1 = M1 * U1 {a unimodular Matrix }</font>
756 00748 <font class="comment"> * and B2 = M2 * U2. M1 and M2 we know, they are the linear </font>
757 00749 <font class="comment"> * parts we obtained in Step 2. Our Task is now to find U1 and</font>
758 00750 <font class="comment"> * U2. </font>
759 00751 <font class="comment"> * We know that B1 * Delta = B2.</font>
760 00752 <font class="comment"> * i.e. M1 * U1 * Delta = M2 * U2</font>
761 00753 <font class="comment"> * or U1*Delta*U2Inverse = M1Inverse * M2.</font>
762 00754 <font class="comment"> * and Delta is the Diagonal Matrix which satisifies the </font>
763 00755 <font class="comment"> * above properties (in the Theorem).</font>
764 00756 <font class="comment"> * So Delta is nothing but the Smith Normal Form of </font>
765 00757 <font class="comment"> * M1Inverse * M2.</font>
766 00758 <font class="comment"> * So, first we have to find M1Inverse.</font>
767 00759 <font class="comment"> * </font>
768 00760 <font class="comment"> * This Step, involves finding the Inverse of the Matrix M1.</font>
769 00761 <font class="comment"> * We find the Inverse using the Polylib function </font>
770 00762 <font class="comment"> * Matrix_Inverse. There is a catch here, the result of this</font>
771 00763 <font class="comment"> * function is an integral matrix, not necessarily the exact</font>
772 00764 <font class="comment"> * Inverse (since M1 need not be Unimodular), but a multiple</font>
773 00765 <font class="comment"> * of the actual inverse. The number by which we have to divide</font>
774 00766 <font class="comment"> * the matrix, is not obtained here as the input matrix is not</font>
775 00767 <font class="comment"> * a Polylib matrix { We input only the Linear part }. Later I</font>
776 00768 <font class="comment"> * give a way for finding that number.</font>
777 00769 <font class="comment"> *</font>
778 00770 <font class="comment"> * M1Inverse = Matrix_Inverse ( M1 );</font>
779 00771 <font class="comment"> * </font>
780 00772 <font class="comment"> * Step 4 : MtProduct = Matrix_Product (M1Inverse, M2);</font>
781 00773 <font class="comment"> * Step 5 : SmithNormalFrom (MtProduct, Delta, U, V);</font>
782 00774 <font class="comment"> * U1 = U and U2Inverse = V.</font>
783 00775 <font class="comment"> * Step 6 : Find U2 = Matrix_Inverse (U2inverse). Here there is no prob</font>
784 00776 <font class="comment"> * as U1 and its inverse are unimodular.</font>
785 00777 <font class="comment"> * </font>
786 00778 <font class="comment"> * Step 7 : Compute B1 = M1 * U1;</font>
787 00779 <font class="comment"> * Step 8 : Compute B2 = M2 * U2;</font>
788 00780 <font class="comment"> * Step 9 : Earlier when we computed M1Inverse, we knew that it was not</font>
789 00781 <font class="comment"> * the exact inverse but a multiple of it. Now we find the </font>
790 00782 <font class="comment"> * number, such that ( M1Inverse / number ) would give us the </font>
791 00783 <font class="comment"> * exact inverse of M1.</font>
792 00784 <font class="comment"> * We know that B1 * Delta = B2.</font>
793 00785 <font class="comment"> * Let k = B2[0][0] / B1[0][0].</font>
794 00786 <font class="comment"> * Let number = Delta[0][0]/k;</font>
795 00787 <font class="comment"> * This 'number' is the number we want.</font>
796 00788 <font class="comment"> * We Divide the matrix Delta by this number, to get the actual</font>
797 00789 <font class="comment"> * Delta such that B1 * Delta = B2.</font>
798 00790 <font class="comment"> * Step 10 : Call Split Lattice (B1, B2, Delta ).</font>
799 00791 <font class="comment"> * This function returns the Union of Lattices in such a way </font>
800 00792 <font class="comment"> * that B2 is at the Head of this List.</font>
801 00793 <font class="comment"> * Step 11 : To Remove B2 From the list of the Union of Lattices.</font>
802 00794 <font class="comment"> * Head = Head-&gt;next;</font>
803 00795 <font class="comment"> * Step 12 : Free the Memory that is now not needed and return Head.</font>
804 00796 <font class="comment"> *</font>
805 00797 <font class="comment"> */</font>
806 <a name="l00798"></a><a class="code" href="Lattice_8c.html#a21">00798</a> LatticeUnion *<a class="code" href="Lattice_8c.html#a21">LatticeDifference</a>(Lattice *A,Lattice *B) {
807 00799
808 00800 Lattice *Intersection = NULL;
809 00801 LatticeUnion *Head = NULL, *tempHead = NULL;
810 00802 Matrix *H , *U1 , *X, *Y ;
811 00803
812 00804 <font class="preprocessor">#ifdef DOMDEBUG</font>
813 00805 <font class="preprocessor"></font> FILE *fp;
814 00806 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
815 00807 fprintf(fp,<font class="stringliteral">"\nEntered LATTICEDIFFERENCE \n"</font>);
816 00808 fclose(fp);
817 00809 <font class="preprocessor">#endif</font>
818 00810 <font class="preprocessor"></font>
819 00811 <font class="keywordflow">if</font> (A-&gt;NbRows != A-&gt;NbColumns) {
820 00812 fprintf(stderr,<font class="stringliteral">"\nIn LatticeDifference : The Input Matrix A is not a proper Lattice \n"</font>);
821 00813 <font class="keywordflow">return</font> NULL;
822 00814 }
823 00815
824 00816 <font class="keywordflow">if</font> (B-&gt;NbRows != B-&gt;NbColumns) {
825 00817 fprintf(stderr,<font class="stringliteral">"\nIn LatticeDifference : The Input Matrix B is not a proper Lattice \n"</font>);
826 00818 <font class="keywordflow">return</font> NULL;
827 00819 }
828 00820
829 00821 <font class="keywordflow">if</font> (A-&gt;NbRows != B-&gt;NbRows) {
830 00822 fprintf(stderr,<font class="stringliteral">"\nIn Lattice Difference : The Input Lattices A and B have "</font>);
831 00823 fprintf(stderr,<font class="stringliteral">"incompatible dimensions \n"</font>);
832 00824 <font class="keywordflow">return</font> NULL;
833 00825 }
834 00826
835 00827 <font class="keywordflow">if</font> (<a class="code" href="Matop_8c.html#a7">isinHnf</a> (A) != True) {
836 00828 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(A,&amp;H,&amp;U1);
837 00829 X = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(H);
838 00830 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(U1);
839 00831 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(H);
840 00832 }
841 00833 <font class="keywordflow">else</font>
842 00834 X = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(A);
843 00835
844 00836 <font class="keywordflow">if</font> (<a class="code" href="Matop_8c.html#a7">isinHnf</a>(B) != True) {
845 00837 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(B,&amp;H,&amp;U1);
846 00838 Y = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(H);
847 00839 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(H);
848 00840 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(U1);
849 00841 }
850 00842 <font class="keywordflow">else</font>
851 00843 Y = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(B);
852 00844 <font class="keywordflow">if</font> (<a class="code" href="Lattice_8c.html#a6">isEmptyLattice</a>(X)) {
853 00845 <font class="keywordflow">return</font> NULL;
854 00846 }
855 00847
856 00848 Head=<a class="code" href="Lattice_8c.html#a20">Lattice2LatticeUnion</a>(X,Y);
857 00849
858 00850 <font class="comment">/* If the spliting operation can't be done the result is X. */</font>
859 00851
860 00852 <font class="keywordflow">if</font> (Head == NULL) {
861 00853 Head = (LatticeUnion *)malloc(<font class="keyword">sizeof</font>(LatticeUnion));
862 00854 Head-&gt;M = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(X);
863 00855 Head-&gt;next = NULL;
864 00856 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(X);
865 00857 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Y);
866 00858 <font class="keywordflow">return</font> Head;
867 00859 }
868 00860
869 00861 tempHead = Head;
870 00862 Head = Head-&gt;next;
871 00863 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (tempHead-&gt;M);
872 00864 tempHead-&gt;next = NULL;
873 00865 free(tempHead);
874 00866
875 00867 <font class="keywordflow">if</font> ((Head != NULL))
876 00868 Head = <a class="code" href="Lattice_8c.html#a36">LatticeSimplify</a> (Head);
877 00869 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (X);
878 00870 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (Y);
879 00871
880 00872 <font class="keywordflow">return</font> Head;
881 00873 } <font class="comment">/* LatticeDifference */</font>
882 00874
883 00875
884 00876 <font class="comment">/*</font>
885 00877 <font class="comment"> * Given a Lattice 'B1' and a Lattice 'B2' and a Diagonal Matrix 'C' such that</font>
886 00878 <font class="comment"> * 'B2' is a subset of 'B1' and C[0][0] divides C[1][1], C[1][1] divides C[2]</font>
887 00879 <font class="comment"> * [2] and so on, output the list of matrices whose union is B1. The function</font>
888 00880 <font class="comment"> * expresses the Lattice B1 in terms of B2 Unions of B1 = Union of {B2 + i0b0 +</font>
889 00881 <font class="comment"> * i1b1 + .... + inbn} where 0 &lt;= i0 &lt; C[0][0]; 0 &lt;= i1 &lt; C[1][1] and so on and</font>
890 00882 <font class="comment"> * {b0 ... bn} are the columns of Lattice B1. The list is so formed that the </font>
891 00883 <font class="comment"> * Lattice B2 is the Head of the list. </font>
892 00884 <font class="comment"> */</font>
893 <a name="l00885"></a><a class="code" href="Lattice_8c.html#a22">00885</a> LatticeUnion *<a class="code" href="Lattice_8c.html#a22">SplitLattice</a>(Lattice *B1, Lattice *B2, Matrix *C) {
894 00886
895 00887 <font class="keywordtype">int</font> i;
896 00888
897 00889 LatticeUnion *Head = NULL;
898 00890 Head = (LatticeUnion *)malloc(<font class="keyword">sizeof</font>(LatticeUnion));
899 00891 Head-&gt;M = (Lattice *)B2;
900 00892 Head-&gt;next = NULL;
901 00893 <font class="keywordflow">for</font> (i = 0; i &lt; C-&gt;NbRows ; i++)
902 00894 <a class="code" href="Lattice_8c.html#a18">AddLattice</a>(Head,B1,B2,<a class="code" href="arithmetique_8h.html#a7">VALUE_TO_INT</a>(C-&gt;p[i][i]),i);
903 00895 <font class="keywordflow">return</font> Head;
904 00896 } <font class="comment">/* SplitLattice */</font>
905 00897
906 00898 <font class="comment">/*</font>
907 00899 <font class="comment"> * Given lattices 'B1' and 'B2', an integer 'NumofTimes', a column number </font>
908 00900 <font class="comment"> * 'Colnumber' and a pointer to a list of lattices, the function does the </font>
909 00901 <font class="comment"> * following :-</font>
910 00902 <font class="comment"> * For every lattice in the list, it adds a set of lattices such that the </font>
911 00903 <font class="comment"> * affine part of the new lattices is greater than the original lattice by 0 to</font>
912 00904 <font class="comment"> * NumofTimes-1 * {the (ColumnNumber)-th column of B1}. </font>
913 00905 <font class="comment"> * Note : </font>
914 00906 <font class="comment"> * Three pointers are defined to point at various points of the list. They are:</font>
915 00907 <font class="comment"> * Head -&gt; It always points to the head of the list. </font>
916 00908 <font class="comment"> * tail -&gt; It always points to the last element in the list. </font>
917 00909 <font class="comment"> * marker -&gt; It points to the element, which is the last element of the Input </font>
918 00910 <font class="comment"> * list.</font>
919 00911 <font class="comment"> */</font>
920 <a name="l00912"></a><a class="code" href="Lattice_8c.html#a18">00912</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a18">AddLattice</a> (LatticeUnion *Head, Matrix *B1, Matrix *B2, <font class="keywordtype">int</font> NumofTimes, <font class="keywordtype">int</font> Colnumber) {
921 00913
922 00914 LatticeUnion *temp, *tail, *marker;
923 00915 <font class="keywordtype">int</font> i,j;
924 00916 <a class="code" href="arithmetique_8h.html#a93">Value</a> tmp;
925 00917
926 00918 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
927 00919 tail = Head;
928 00920 <font class="keywordflow">while</font> (tail-&gt;next != NULL)
929 00921 tail = tail-&gt;next;
930 00922 marker = tail;
931 00923
932 00924 <font class="keywordflow">for</font>(temp = Head; temp != NULL; temp=temp-&gt;next) {
933 00925 <font class="keywordflow">for</font> (i = 1; i &lt; NumofTimes; i++) {
934 00926 Lattice *tempMatrix, *H, *U;
935 00927
936 00928 tempMatrix = (Lattice *)<a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(temp-&gt;M);
937 00929 <font class="keywordflow">for</font> (j = 0; j &lt; B2-&gt;NbRows; j++) {
938 00930 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(tmp,i);
939 00931 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,tmp,B1-&gt;p[j][Colnumber]);
940 00932 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(tempMatrix-&gt;p[j][B2-&gt;NbColumns-1],tempMatrix-&gt;p[j][B2-&gt;NbColumns-1],tmp);
941 00933 }
942 00934 tail-&gt;next = (LatticeUnion *)malloc(<font class="keyword">sizeof</font>(LatticeUnion));
943 00935 <a class="code" href="Lattice_8c.html#a8">AffineHermite</a>(tempMatrix,&amp;H,&amp;U);
944 00936 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>((Matrix *)tempMatrix);
945 00937 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(U);
946 00938 tail-&gt;next-&gt;M = H;
947 00939 tail-&gt;next-&gt;next=NULL;
948 00940 tail = tail-&gt;next;
949 00941 }
950 00942 <font class="keywordflow">if</font> (temp == marker)
951 00943 <font class="keywordflow">break</font>;
952 00944 }
953 00945 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
954 00946 <font class="keywordflow">return</font>;
955 00947 } <font class="comment">/* AddLattice */</font>
956 00948
957 00949 <font class="comment">/* </font>
958 00950 <font class="comment"> * Given a polyhedron 'A', store the Hermite basis 'B' and return the true </font>
959 00951 <font class="comment"> * dimension of the polyhedron 'A'. </font>
960 00952 <font class="comment"> * Algorithm : </font>
961 00953 <font class="comment"> *</font>
962 00954 <font class="comment"> * 1) First we find all the vertices of the Polyhedron A.</font>
963 00955 <font class="comment"> * Now suppose the vertices are [v1, v2...vn], then </font>
964 00956 <font class="comment"> * a particular set of vectors governing the space of A are </font>
965 00957 <font class="comment"> * given by [v1-v2, v1-v3, ... v1-vn] (let us say V).</font>
966 00958 <font class="comment"> * So we initially calculate these vectors.</font>
967 00959 <font class="comment"> * 2) Then there are the rays and lines which contribute to the</font>
968 00960 <font class="comment"> * space in which A is going to lie.</font>
969 00961 <font class="comment"> * So we append to the rays and lines. So now we get a matrix</font>
970 00962 <font class="comment"> * {These are the rows} [ V ] [l1] [l2]...[lk] </font>
971 00963 <font class="comment"> * where l1 to lk are either rays or lines of the Polyhedron A.</font>
972 00964 <font class="comment"> * 3) The above matrix is the set of vectors which determine</font>
973 00965 <font class="comment"> * the space in which A is going to lie.</font>
974 00966 <font class="comment"> * Using this matrix we find a Basis which is such that</font>
975 00967 <font class="comment"> * the first 'm' columns of it determine the space of A. </font>
976 00968 <font class="comment"> * 4) But we also have to ensure that in the last 'n-m' </font>
977 00969 <font class="comment"> * coordinates the Polyhedron is '0', this is done by</font>
978 00970 <font class="comment"> * taking the image by B(inv) of A and finding the remaining</font>
979 00971 <font class="comment"> * equalities, and composing it with the matrix B, so as</font>
980 00972 <font class="comment"> * to get a new matrix which is the actual Hermite Basis of</font>
981 00973 <font class="comment"> * the Polyhedron.</font>
982 00974 <font class="comment"> */</font>
983 <a name="l00975"></a><a class="code" href="Lattice_8c.html#a23">00975</a> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a23">FindHermiteBasisofDomain</a>(Polyhedron *A, Matrix **B) {
984 00976
985 00977 <font class="keywordtype">int</font> i, j;
986 00978 Matrix *temp,*temp1, *tempinv, *Newmat ;
987 00979 Matrix *vert, *rays, *result;
988 00980 Polyhedron *Image;
989 00981 <font class="keywordtype">int</font> rank, equcount ;
990 00982 <font class="keywordtype">int</font> noofvertices = 0, noofrays = 0;
991 00983 <font class="keywordtype">int</font> vercount , raycount;
992 00984 <a class="code" href="arithmetique_8h.html#a93">Value</a> lcm, fact;
993 00985
994 00986 <font class="preprocessor">#ifdef DOMDEBUG</font>
995 00987 <font class="preprocessor"></font> FILE *fp;
996 00988 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
997 00989 fprintf(fp,<font class="stringliteral">"\nEntered FINDHERMITEBASISOFDOMAIN \n"</font>);
998 00990 fclose(fp);
999 00991 <font class="preprocessor">#endif</font>
1000 00992 <font class="preprocessor"></font>
1001 00993 <font class="comment">/* Checking is empty */</font>
1002 00994 <font class="keywordflow">if</font> (emptyQ(A)) {
1003 00995 B[0] = <a class="code" href="Matop_8c.html#a1">Identity</a>(A-&gt;Dimension+1);
1004 00996 <font class="keywordflow">return</font>(-1);
1005 00997 }
1006 00998
1007 00999 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(lcm); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(fact);
1008 01000 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(lcm,1);
1009 01001
1010 01002 <font class="comment">/* Finding the Vertices */</font>
1011 01003 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;NbRays; i++)
1012 01004 <font class="keywordflow">if</font> ((<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;Ray[i][0])) &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;Ray[i][A-&gt;Dimension+1]))
1013 01005 noofvertices++;
1014 01006 <font class="keywordflow">else</font>
1015 01007 noofrays ++;
1016 01008
1017 01009 vert = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(noofvertices,A-&gt;Dimension+1);
1018 01010 rays = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(noofrays,A-&gt;Dimension);
1019 01011 vercount = 0;
1020 01012 raycount = 0;
1021 01013
1022 01014 <font class="keywordflow">for</font>(i = 0; i &lt; A-&gt;NbRays; i++) {
1023 01015 <font class="keywordflow">if</font> ((<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;Ray[i][0])) &amp;&amp; <a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(A-&gt;Ray[i][A-&gt;Dimension+1])) {
1024 01016 <font class="keywordflow">for</font>(j = 1; j &lt; A-&gt;Dimension+2; j++)
1025 01017 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(vert-&gt;p[vercount][j-1],A-&gt;Ray[i][j]);
1026 01018 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(lcm,*<a class="code" href="Matop_8c.html#a0">Lcm</a>(lcm,A-&gt;Ray[i][j-1]));
1027 01019 vercount++;
1028 01020 }
1029 01021 <font class="keywordflow">else</font> {
1030 01022 <font class="keywordflow">for</font> (j = 1; j &lt; A-&gt;Dimension+1; j++)
1031 01023 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(rays-&gt;p[raycount][j-1],A-&gt;Ray[i][j]);
1032 01024 raycount++;
1033 01025 }
1034 01026 }
1035 01027
1036 01028 <font class="comment">/* Multiplying the rows by the lcm */</font>
1037 01029 <font class="keywordflow">for</font>(i = 0; i &lt; vert-&gt;NbRows; i ++) {
1038 01030 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(fact,lcm,vert-&gt;p[i][vert-&gt;NbColumns-1]);
1039 01031 <font class="keywordflow">for</font> (j = 0; j &lt; vert-&gt;NbColumns-1; j++)
1040 01032 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(vert-&gt;p[i][j],vert-&gt;p[i][j],fact);
1041 01033 }
1042 01034
1043 01035 <font class="comment">/* Drop the Last Columns */</font>
1044 01036 temp = <a class="code" href="Matop_8c.html#a15">RemoveColumn</a>(vert,vert-&gt;NbColumns-1);
1045 01037 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(vert);
1046 01038
1047 01039 <font class="comment">/* Getting the Vectors */</font>
1048 01040 vert = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(temp-&gt;NbRows-1, temp-&gt;NbColumns);
1049 01041 <font class="keywordflow">for</font> (i = 1; i &lt; temp-&gt;NbRows; i++)
1050 01042 <font class="keywordflow">for</font> (j = 0; j &lt; temp-&gt;NbColumns ; j++)
1051 01043 <a class="code" href="arithmetique_8h.html#a48">value_substract</a>(vert-&gt;p[i-1][j],temp-&gt;p[0][j],temp-&gt;p[i][j]);
1052 01044
1053 01045 <font class="comment">/* Add the Rays and Lines */</font>
1054 01046 <font class="comment">/* Combined Matrix */</font>
1055 01047 result = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(vert-&gt;NbRows+rays-&gt;NbRows, vert-&gt;NbColumns);
1056 01048 <font class="keywordflow">for</font> (i = 0; i &lt; vert-&gt;NbRows; i++)
1057 01049 <font class="keywordflow">for</font> (j = 0 ;j &lt; result-&gt;NbColumns ; j++)
1058 01050 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(result-&gt;p[i][j],vert-&gt;p[i][j]);
1059 01051
1060 01052 <font class="keywordflow">for</font> (; i&lt;result-&gt;NbRows; i++)
1061 01053 <font class="keywordflow">for</font> (j = 0; j &lt; result-&gt;NbColumns; j++)
1062 01054 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(result-&gt;p[i][j],rays-&gt;p[i-vert-&gt;NbRows][j]);
1063 01055
1064 01056 <font class="comment">// printf("\nIn FHB:-\n");</font>
1065 01057 <font class="comment">// Matrix_Print(stdout,P_VALUE_FMT, result);</font>
1066 01058
1067 01059 rank = <a class="code" href="Matop_8c.html#a16">findHermiteBasis</a>(result, &amp;temp);
1068 01060 temp1 = <a class="code" href="Lattice_8c.html#a13">ChangeLatticeDimension</a>(temp,temp-&gt;NbRows+1);
1069 01061
1070 01062 <font class="comment">// printf("\nThe rank of the Domain is %d\n", rank);</font>
1071 01063 <font class="comment">// Matrix_Print(stdout,P_VALUE_FMT,temp1);</font>
1072 01064 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp);
1073 01065
1074 01066 <font class="comment">/* Adding the Affine Part to take care of the Equalities */</font>
1075 01067 temp = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(temp1);
1076 01068 tempinv = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(temp-&gt;NbRows,temp-&gt;NbColumns);
1077 01069 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>(temp,tempinv);
1078 01070 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp);
1079 01071 Image = <a class="code" href="polyhedron_8c.html#a53">DomainImage</a>(A,tempinv,MAXNOOFRAYS);
1080 01072 Newmat = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(temp1-&gt;NbRows,temp1-&gt;NbColumns);
1081 01073 <font class="keywordflow">for</font>(i = 0; i &lt; rank ; i++)
1082 01074 <font class="keywordflow">for</font>(j = 0; j &lt; Newmat-&gt;NbColumns ; j++)
1083 01075 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Newmat-&gt;p[i][j],0);
1084 01076 <font class="keywordflow">for</font>(i = 0; i &lt; rank; i++)
1085 01077 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Newmat-&gt;p[i][i],1);
1086 01078 equcount = 0;
1087 01079 <font class="keywordflow">for</font> (i = 0; i &lt; Image-&gt;NbConstraints; i ++)
1088 01080 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(Image-&gt;Constraint[i][0])) {
1089 01081 <font class="keywordflow">for</font> (j = 1; j&lt;Image-&gt;Dimension+2; j ++)
1090 01082 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Newmat-&gt;p[rank+equcount][j-1],Image-&gt;Constraint[i][j]);
1091 01083 ++equcount ;
1092 01084 }
1093 01085 <font class="keywordflow">for</font> (i = 0; i &lt; Newmat-&gt;NbColumns-1; i++)
1094 01086 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Newmat-&gt;p[Newmat-&gt;NbRows-1][i],0);
1095 01087 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Newmat-&gt;p[Newmat-&gt;NbRows-1][Newmat-&gt;NbColumns-1],1);
1096 01088 temp = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(Newmat-&gt;NbRows, Newmat-&gt;NbColumns);
1097 01089 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>(Newmat,temp);
1098 01090 B[0] = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(temp1-&gt;NbRows,temp-&gt;NbColumns);
1099 01091
1100 01092 <font class="comment">// Matrix_Print (stdout,P_VALUE_FMT,temp);</font>
1101 01093
1102 01094 <a class="code" href="matrix_8c.html#a12">Matrix_Product</a>(temp1,temp,B[0]);
1103 01095 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(lcm);
1104 01096 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(fact);
1105 01097 <font class="keywordflow">return</font> rank;
1106 01098 } <font class="comment">/* FindHermiteBasisofDomain */</font>
1107 01099
1108 01100 <font class="comment">/*</font>
1109 01101 <font class="comment"> * Return the image of a lattice 'A' by the invertible, affine, rational </font>
1110 01102 <font class="comment"> * function 'M'. </font>
1111 01103 <font class="comment"> */</font>
1112 <a name="l01104"></a><a class="code" href="Lattice_8c.html#a24">01104</a> Lattice *<a class="code" href="Lattice_8c.html#a24">LatticeImage</a>(Lattice *A, Matrix *M) {
1113 01105
1114 01106 Lattice *Img, *temp, *Minv;
1115 01107
1116 01108 <font class="preprocessor">#ifdef DOMDEBUG</font>
1117 01109 <font class="preprocessor"></font> FILE *fp;
1118 01110 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
1119 01111 fprintf(fp, <font class="stringliteral">"\nEntered LATTICEIMAGE \n"</font>);
1120 01112 fclose(fp);
1121 01113 <font class="preprocessor">#endif</font>
1122 01114 <font class="preprocessor"></font>
1123 01115 <font class="keywordflow">if</font> ((A-&gt;NbRows != M-&gt;NbRows) || (M-&gt;NbRows != M-&gt;NbColumns))
1124 01116 <font class="keywordflow">return</font> (<a class="code" href="Lattice_8c.html#a5">EmptyLattice</a> (A-&gt;NbRows));
1125 01117
1126 01118 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a69">value_one_p</a>(M-&gt;p[M-&gt;NbRows-1][M-&gt;NbColumns-1])) {
1127 01119 Img = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a> ( M-&gt;NbRows, A-&gt;NbColumns );
1128 01120 <a class="code" href="matrix_8c.html#a12">Matrix_Product</a> (M,A,Img);
1129 01121 <font class="keywordflow">return</font> Img;
1130 01122 }
1131 01123 temp = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(M);
1132 01124 Minv = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(temp-&gt;NbColumns, temp-&gt;NbRows);
1133 01125 <a class="code" href="matrix_8c.html#a13">Matrix_Inverse</a>(temp, Minv);
1134 01126 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp);
1135 01127
1136 01128 Img = <a class="code" href="Lattice_8c.html#a25">LatticePreimage</a>(A, Minv);
1137 01129 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (Minv);
1138 01130 <font class="keywordflow">return</font> Img;
1139 01131 } <font class="comment">/* LatticeImage */</font>
1140 01132
1141 01133 <font class="comment">/* </font>
1142 01134 <font class="comment"> * Return the preimage of a lattice 'L' by an affine, rational function 'G'.</font>
1143 01135 <font class="comment"> * Algorithm: </font>
1144 01136 <font class="comment"> * (1) Prepare Diophantine equation :</font>
1145 01137 <font class="comment"> * [Gl -Ll][x y] = [Ga -La]{"l-linear, a-affine"}</font>
1146 01138 <font class="comment"> * (2) Solve the Diophantine equations.</font>
1147 01139 <font class="comment"> * (3) If there is solution to the Diophantine eq., extract the </font>
1148 01140 <font class="comment"> * general solution and the particular solution of x and that </font>
1149 01141 <font class="comment"> * forms the preimage of 'L' by 'G'. </font>
1150 01142 <font class="comment"> */</font>
1151 <a name="l01143"></a><a class="code" href="Lattice_8c.html#a25">01143</a> Lattice *<a class="code" href="Lattice_8c.html#a25">LatticePreimage</a>(Lattice *L, Matrix *G) {
1152 01144
1153 01145 Matrix *Dio, *U ;
1154 01146 Lattice *Result;
1155 01147 Vector *X;
1156 01148 <font class="keywordtype">int</font> i,j;
1157 01149 <font class="keywordtype">int</font> rank;
1158 01150 <a class="code" href="arithmetique_8h.html#a93">Value</a> divisor, tmp;
1159 01151
1160 01152 <font class="preprocessor">#ifdef DOMDEBUG</font>
1161 01153 <font class="preprocessor"></font> FILE *fp;
1162 01154 fp = fopen(<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
1163 01155 fprintf(fp,<font class="stringliteral">"\nEntered LATTICEPREIMAGE \n"</font>);
1164 01156 fclose(fp);
1165 01157 <font class="preprocessor">#endif</font>
1166 01158 <font class="preprocessor"></font>
1167 01159 <font class="comment">/* Check for the validity of the function */</font>
1168 01160 <font class="keywordflow">if</font> (G-&gt;NbRows != L-&gt;NbRows) {
1169 01161 fprintf (stderr, <font class="stringliteral">"\nIn LatticePreimage: Incompatible types of Lattice and the function\n"</font>);
1170 01162 <font class="keywordflow">return</font> (<a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(G-&gt;NbColumns));
1171 01163 }
1172 01164
1173 01165 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(divisor); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
1174 01166
1175 01167 <font class="comment">/* Making Diophantine Equations [g -L] */</font>
1176 01168 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(divisor,G-&gt;p[G-&gt;NbRows-1][G-&gt;NbColumns-1]);
1177 01169 Dio = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a>(G-&gt;NbRows, G-&gt;NbColumns+L-&gt;NbColumns-1);
1178 01170 <font class="keywordflow">for</font> (i = 0; i &lt; G-&gt;NbRows-1; i++)
1179 01171 <font class="keywordflow">for</font> (j = 0; j &lt; G-&gt;NbColumns-1; j++)
1180 01172 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Dio-&gt;p[i][j],G-&gt;p[i][j]);
1181 01173
1182 01174 <font class="keywordflow">for</font> (i = 0;i &lt; G-&gt;NbRows-1; i++)
1183 01175 <font class="keywordflow">for</font> (j = 0; j &lt; L-&gt;NbColumns-1; j++) {
1184 01176 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,divisor,L-&gt;p[i][j]);
1185 01177 <a class="code" href="arithmetique_8h.html#a54">value_oppose</a>(Dio-&gt;p[i][j+G-&gt;NbColumns-1],tmp);
1186 01178 }
1187 01179
1188 01180 <font class="keywordflow">for</font> (i = 0; i &lt; Dio-&gt;NbRows-1; i++) {
1189 01181 <a class="code" href="arithmetique_8h.html#a47">value_multiply</a>(tmp,divisor,L-&gt;p[i][L-&gt;NbColumns-1]);
1190 01182 <a class="code" href="arithmetique_8h.html#a48">value_substract</a>(tmp,G-&gt;p[i][G-&gt;NbColumns-1],tmp);
1191 01183 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Dio-&gt;p[i][Dio-&gt;NbColumns-1],tmp);
1192 01184 }
1193 01185 <font class="keywordflow">for</font> (i = 0; i &lt; Dio-&gt;NbColumns-1; i++)
1194 01186 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[Dio-&gt;NbRows-1][i],0);
1195 01187
1196 01188 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Dio-&gt;p[Dio-&gt;NbRows-1][Dio-&gt;NbColumns-1],1);
1197 01189 rank = <a class="code" href="SolveDio_8c.html#a1">SolveDiophantine</a>(Dio, &amp;U, &amp;X);
1198 01190
1199 01191 <font class="keywordflow">if</font> (rank == -1)
1200 01192 Result = <a class="code" href="Lattice_8c.html#a5">EmptyLattice</a>(G-&gt;NbColumns);
1201 01193 <font class="keywordflow">else</font> {
1202 01194 Result = <a class="code" href="matrix_8c.html#a0">Matrix_Alloc</a> (G-&gt;NbColumns, G-&gt;NbColumns);
1203 01195 <font class="keywordflow">for</font> (i = 0; i &lt; Result-&gt;NbRows-1; i++)
1204 01196 <font class="keywordflow">for</font> (j = 0; j &lt; Result-&gt;NbColumns-1; j++)
1205 01197 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Result-&gt;p[i][j],U-&gt;p[i][j]);
1206 01198
1207 01199 <font class="keywordflow">for</font> (i = 0; i &lt; Result-&gt;NbRows-1; i ++)
1208 01200 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(Result-&gt;p[i][Result-&gt;NbColumns-1],X-&gt;p[i]);
1209 01201 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (U);
1210 01202 <a class="code" href="vector_8c.html#a6">Vector_Free</a> (X);
1211 01203 <font class="keywordflow">for</font> (i = 0; i &lt; Result-&gt;NbColumns-1; i ++)
1212 01204 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Result-&gt;p[Result-&gt;NbRows-1][i],0);
1213 01205 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(Result-&gt;p[i][i],1);
1214 01206 }
1215 01207 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(Dio);
1216 01208 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(divisor);
1217 01209 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
1218 01210 <font class="keywordflow">return</font> Result;
1219 01211 } <font class="comment">/* LatticePreimage */</font>
1220 01212
1221 01213 <font class="comment">/*</font>
1222 01214 <font class="comment"> * Return True if the matrix 'm' is a valid lattice, otherwise return False. </font>
1223 01215 <font class="comment"> * Note: A valid lattice has the last row as [0 0 0 ... 1]. </font>
1224 01216 <font class="comment"> */</font>
1225 <a name="l01217"></a><a class="code" href="Lattice_8c.html#a26">01217</a> Bool <a class="code" href="Lattice_8c.html#a26">IsLattice</a>(Matrix *m) {
1226 01218
1227 01219 <font class="keywordtype">int</font> i;
1228 01220
1229 01221 <font class="preprocessor">#ifdef DOMDEBUG</font>
1230 01222 <font class="preprocessor"></font> FILE *fp;
1231 01223 fp = fopen (<font class="stringliteral">"_debug"</font>, <font class="stringliteral">"a"</font>);
1232 01224 fprintf (fp, <font class="stringliteral">"\nEntered ISLATTICE \n"</font>);
1233 01225 fclose (fp);
1234 01226 <font class="preprocessor">#endif</font>
1235 01227 <font class="preprocessor"></font>
1236 01228 <font class="comment">/* Is it necessary to check if the lattice</font>
1237 01229 <font class="comment"> is fulldimensional or not here only? */</font>
1238 01230
1239 01231 <font class="keywordflow">if</font> (m-&gt;NbRows != m-&gt;NbColumns)
1240 01232 <font class="keywordflow">return</font> False;
1241 01233
1242 01234 <font class="keywordflow">for</font> (i = 0; i &lt; m-&gt;NbColumns-1; i++)
1243 01235 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a68">value_notzero_p</a>(m-&gt;p[m-&gt;NbRows-1][i]))
1244 01236 <font class="keywordflow">return</font> False ;
1245 01237 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a70">value_notone_p</a>(m-&gt;p[i][i]))
1246 01238 <font class="keywordflow">return</font> False;
1247 01239 <font class="keywordflow">return</font> True ;
1248 01240 } <font class="comment">/* IsLattice */</font>
1249 01241
1250 01242 <font class="comment">/*</font>
1251 01243 <font class="comment"> * Check whether the matrix 'm' is full row-rank or not. </font>
1252 01244 <font class="comment"> */</font>
1253 <a name="l01245"></a><a class="code" href="Lattice_8c.html#a27">01245</a> Bool <a class="code" href="Lattice_8c.html#a27">isfulldim</a>(Matrix *m) {
1254 01246
1255 01247 Matrix *h, *u ;
1256 01248 <font class="keywordtype">int</font> i ;
1257 01249
1258 01250 <font class="comment">/* </font>
1259 01251 <font class="comment"> res = Hermite (m, &amp;h, &amp;u);</font>
1260 01252 <font class="comment"> if (res != m-&gt;NbRows)</font>
1261 01253 <font class="comment"> return False ;</font>
1262 01254 <font class="comment"> */</font>
1263 01255
1264 01256 <a class="code" href="NormalForms_8c.html#a16">Hermite</a>(m, &amp;h, &amp;u);
1265 01257 <font class="keywordflow">for</font> (i = 0; i &lt; h-&gt;NbRows; i ++)
1266 01258 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a67">value_zero_p</a>(h-&gt;p[i][i])) {
1267 01259 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (h);
1268 01260 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (u);
1269 01261 <font class="keywordflow">return</font> False;
1270 01262 }
1271 01263 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (h);
1272 01264 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a> (u);
1273 01265 <font class="keywordflow">return</font> True;
1274 01266 } <font class="comment">/* isfulldim */</font>
1275 01267
1276 01268 <font class="comment">/* </font>
1277 01269 <font class="comment"> * This function takes as input a lattice list in which the lattices have the </font>
1278 01270 <font class="comment"> * same linear part, and almost the same affinepart, i.e. if A and B are two </font>
1279 01271 <font class="comment"> * of the lattices in the above lattice list and [a1, .. , an] and [b1 .. bn]</font>
1280 01272 <font class="comment"> * are the affineparts of A and B respectively, then for 0 &lt; i &lt; n ai = bi and</font>
1281 01273 <font class="comment"> * 'an' may not be equal to 'bn'. These are not the affine parts in the n-th</font>
1282 01274 <font class="comment"> * dimension, but the lattices have been tranformed such that the value of the </font>
1283 01275 <font class="comment"> * elment in the dimension on which we are simplifying is in the last row and</font>
1284 01276 <font class="comment"> * also the lattices are in a sorted order. </font>
1285 01277 <font class="comment"> * This function also takes as input the dimension along which we</font>
1286 01278 <font class="comment"> * are simplifying and takes the diagonal element of the lattice along that</font>
1287 01279 <font class="comment"> * dimension and tries to find out the factors of that element and sees if the</font>
1288 01280 <font class="comment"> * list of lattices can be simplified using these factors. The output of this </font>
1289 01281 <font class="comment"> * function is the list of lattices in the simplified form and a flag to indic-</font>
1290 01282 <font class="comment"> * ate whether any form of simplification was actually done or not. </font>
1291 01283 <font class="comment"> */</font>
1292 <a name="l01284"></a><a class="code" href="Lattice_8c.html#a28">01284</a> <font class="keyword">static</font> Bool <a class="code" href="Lattice_8c.html#a28">Simplify</a>(LatticeUnion **InputList, LatticeUnion **ResultList, <font class="keywordtype">int</font> dim) {
1293 01285
1294 01286 <font class="keywordtype">int</font> i;
1295 01287 LatticeUnion *prev, *temp;
1296 01288 <a class="code" href="structfactor.html">factor</a> allfac;
1297 01289 Bool retval = False;
1298 01290 <font class="keywordtype">int</font> width;
1299 01291 <a class="code" href="arithmetique_8h.html#a93">Value</a> cnt, aux, k, fac, num, tmp, foobar;
1300 01292
1301 01293 <font class="keywordflow">if</font> ((*InputList == NULL) || (InputList[0]-&gt;next == NULL))
1302 01294 <font class="keywordflow">return</font> False ;
1303 01295
1304 01296 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(aux); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(cnt);
1305 01297 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(k); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(fac);
1306 01298 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(num); <a class="code" href="arithmetique_8h.html#a10">value_init</a>(tmp);
1307 01299 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(foobar);
1308 01300
1309 01301 width = InputList[0]-&gt;M-&gt;NbRows-1;
1310 01302 allfac = <a class="code" href="Lattice_8c.html#a0">allfactors</a>(<a class="code" href="arithmetique_8h.html#a7">VALUE_TO_INT</a>(InputList[0]-&gt;M-&gt;p[dim][dim]));
1311 01303 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(cnt,0);
1312 01304 <font class="keywordflow">for</font> (temp = InputList[0]; temp != NULL; temp = temp-&gt;next)
1313 01305 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(cnt,cnt);
1314 01306 <font class="keywordflow">for</font>(i = 0; i &lt; allfac.<a class="code" href="structfactor.html#m0">count</a>; i++) {
1315 01307 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(foobar,allfac.<a class="code" href="structfactor.html#m1">fac</a>[i]);
1316 01308 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(aux,InputList[0]-&gt;M-&gt;p[dim][dim],foobar);
1317 01309 <font class="keywordflow">if</font>(<a class="code" href="arithmetique_8h.html#a25">value_ge</a>(cnt,aux))
1318 01310 <font class="keywordflow">break</font>;
1319 01311 }
1320 01312 <font class="keywordflow">if</font> (i == allfac.<a class="code" href="structfactor.html#m0">count</a>) {
1321 01313 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(cnt); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(aux);
1322 01314 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(k); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(fac);
1323 01315 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(num); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
1324 01316 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(foobar);
1325 01317 <font class="keywordflow">return</font> False;
1326 01318 }
1327 01319 <font class="keywordflow">for</font> (; i &lt; allfac.<a class="code" href="structfactor.html#m0">count</a>; i++) {
1328 01320 Bool Present = False;
1329 01321 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(k,0);
1330 01322
1331 01323 <font class="keywordflow">if</font> (*InputList == NULL) {
1332 01324 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(cnt); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(aux);
1333 01325 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(k); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(fac);
1334 01326 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(num); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
1335 01327 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(foobar);
1336 01328 <font class="keywordflow">return</font> retval;
1337 01329 }
1338 01330 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(foobar,allfac.<a class="code" href="structfactor.html#m1">fac</a>[i]);
1339 01331 <a class="code" href="arithmetique_8h.html#a51">value_division</a>(num,InputList[0]-&gt;M-&gt;p[dim][dim],foobar);
1340 01332 <font class="keywordflow">while</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(k,foobar)) {
1341 01333 Present = False;
1342 01334 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(fac,k);
1343 01335 <font class="keywordflow">for</font> (temp = *InputList; temp != NULL; temp = temp-&gt;next) {
1344 01336 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1],fac)) {
1345 01337 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(foobar,allfac.<a class="code" href="structfactor.html#m1">fac</a>[i]);
1346 01338 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(fac,fac,foobar);
1347 01339 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a25">value_ge</a>(fac,(*InputList)-&gt;M-&gt;p[dim][dim])) {
1348 01340 Present = True;
1349 01341 <font class="keywordflow">break</font>;
1350 01342 }
1351 01343 }
1352 01344 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1],fac))
1353 01345 <font class="keywordflow">break</font>;
1354 01346 }
1355 01347 <font class="keywordflow">if</font> (Present == True) {
1356 01348 retval = True;
1357 01349 <font class="keywordflow">if</font> (*ResultList == NULL)
1358 01350 *ResultList = temp = (LatticeUnion *)malloc(<font class="keyword">sizeof</font>(LatticeUnion));
1359 01351 <font class="keywordflow">else</font> {
1360 01352 <font class="keywordflow">for</font> (temp = *ResultList; temp-&gt;next != NULL; temp = temp-&gt;next);
1361 01353 temp-&gt;next = (LatticeUnion *) malloc (<font class="keyword">sizeof</font> (LatticeUnion));
1362 01354 temp = temp-&gt;next;
1363 01355 }
1364 01356 temp-&gt;M = <a class="code" href="Matop_8c.html#a5">Matrix_Copy</a>(InputList[0]-&gt;M);
1365 01357 temp-&gt;next = NULL;
1366 01358 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(foobar,allfac.<a class="code" href="structfactor.html#m1">fac</a>[i]);
1367 01359 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[dim][dim],foobar);
1368 01360 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[dim][width],k);
1369 01361 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(temp-&gt;M-&gt;p[width][width],1);
1370 01362
1371 01363 <font class="comment">/* Deleting the Lattices from the curlist */</font>
1372 01364 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(tmp,k);
1373 01365 prev = NULL;
1374 01366 temp = InputList[0];
1375 01367 <font class="keywordflow">while</font> (temp != NULL) {
1376 01368 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a22">value_eq</a>(temp-&gt;M-&gt;p[width][width],tmp)) {
1377 01369 <font class="keywordflow">if</font> (temp == InputList[0]) {
1378 01370 prev = temp;
1379 01371 temp = InputList [0] = temp-&gt;next;
1380 01372 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(prev-&gt;M);
1381 01373 free(prev);
1382 01374 }
1383 01375 <font class="keywordflow">else</font> {
1384 01376 prev-&gt;next = temp-&gt;next;
1385 01377 <a class="code" href="matrix_8c.html#a1">Matrix_Free</a>(temp-&gt;M);
1386 01378 free(temp);
1387 01379 temp = prev-&gt;next;
1388 01380 }
1389 01381 <a class="code" href="arithmetique_8h.html#a12">value_set_si</a>(foobar,allfac.<a class="code" href="structfactor.html#m1">fac</a>[i]);
1390 01382 <a class="code" href="arithmetique_8h.html#a43">value_addto</a>(tmp,tmp,foobar);
1391 01383 }
1392 01384 <font class="keywordflow">else</font> {
1393 01385 prev = temp;
1394 01386 temp = temp-&gt;next;
1395 01387 }
1396 01388 }
1397 01389 }
1398 01390 <a class="code" href="arithmetique_8h.html#a45">value_increment</a>(k,k);
1399 01391 }
1400 01392 }
1401 01393 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(cnt); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(aux);
1402 01394 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(k); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(fac);
1403 01395 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(num); <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(tmp);
1404 01396 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(foobar);
1405 01397 <font class="keywordflow">return</font> retval;
1406 01398 } <font class="comment">/* Simplify */</font>
1407 01399
1408 01400 <font class="comment">/*</font>
1409 01401 <font class="comment"> * This function is used in the qsort function in sorting the lattices. Given </font>
1410 01402 <font class="comment"> * two lattices 'A' and 'B', both in HNF, where A = [ [a11 0], [a21, a22, 0] .</font>
1411 01403 <font class="comment"> * .... [an1, .., ann] ] and B = [ [b11 0], [b21, b22, 0] ..[bn1, .., bnn] ],</font>
1412 01404 <font class="comment"> * then A &lt; B, if there exists a pair &lt;i,j&gt; such that [aij &lt; bij] and for every</font>
1413 01405 <font class="comment"> * other pair &lt;i1, j1&gt;, 0&lt;=i1&lt;i, 0&lt;=j1&lt;j [ai1j1 = bi1j1]. </font>
1414 01406 <font class="comment"> */</font>
1415 <a name="l01407"></a><a class="code" href="Lattice_8c.html#a29">01407</a> <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a29">LinearPartCompare</a>(<font class="keyword">const</font> <font class="keywordtype">void</font> *A, <font class="keyword">const</font> <font class="keywordtype">void</font> *B) {
1416 01408
1417 01409 Lattice **L1, **L2;
1418 01410 <font class="keywordtype">int</font> i, j;
1419 01411
1420 01412 L1 = (Lattice **) A;
1421 01413 L2 = (Lattice **) B;
1422 01414
1423 01415 <font class="keywordflow">for</font> (i = 0; i &lt; L1[0]-&gt;NbRows-1; i++)
1424 01416 <font class="keywordflow">for</font> (j = 0; j &lt;= i ; j++) {
1425 01417 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(L1[0]-&gt;p[i][j],L2[0]-&gt;p[i][j]))
1426 01418 <font class="keywordflow">return</font> 1;
1427 01419 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(L1[0]-&gt;p[i][j],L2[0]-&gt;p[i][j]))
1428 01420 <font class="keywordflow">return</font> -1;
1429 01421 }
1430 01422 <font class="keywordflow">return</font> 0;
1431 01423 } <font class="comment">/* LinearPartCompare */</font>
1432 01424
1433 01425 <font class="comment">/*</font>
1434 01426 <font class="comment"> * This function takes as input a List of Lattices and sorts them on the basis</font>
1435 01427 <font class="comment"> * of their Linear parts. It sorts in place, as a result of which the input </font>
1436 01428 <font class="comment"> * list is modified to the sorted order.</font>
1437 01429 <font class="comment"> */</font>
1438 <a name="l01430"></a><a class="code" href="Lattice_8c.html#a30">01430</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a30">LinearPartSort</a> (LatticeUnion *Head) {
1439 01431
1440 01432 <font class="keywordtype">int</font> cnt;
1441 01433 Lattice **Latlist;
1442 01434 LatticeUnion *temp ;
1443 01435
1444 01436 cnt = 0;
1445 01437 <font class="keywordflow">for</font> (temp = Head; temp != NULL; temp = temp-&gt;next)
1446 01438 cnt ++;
1447 01439
1448 01440 Latlist = (Lattice **) malloc ( <font class="keyword">sizeof</font> (Lattice *) * cnt);
1449 01441
1450 01442 cnt = 0;
1451 01443 <font class="keywordflow">for</font> (temp = Head; temp != NULL; temp = temp-&gt;next)
1452 01444 Latlist[cnt++] = temp-&gt;M;
1453 01445
1454 01446 qsort(Latlist, cnt, <font class="keyword">sizeof</font>(Lattice *), <a class="code" href="Lattice_8c.html#a29">LinearPartCompare</a>);
1455 01447
1456 01448 cnt = 0;
1457 01449 <font class="keywordflow">for</font> (temp = Head; temp != NULL; temp = temp-&gt;next)
1458 01450 temp-&gt;M = Latlist[cnt++];
1459 01451
1460 01452 free (Latlist);
1461 01453 <font class="keywordflow">return</font>;
1462 01454 } <font class="comment">/* LinearPartSort */</font>
1463 01455
1464 01456 <font class="comment">/*</font>
1465 01457 <font class="comment"> * This function is used in 'AfiinePartSort' in sorting the lattices with the</font>
1466 01458 <font class="comment"> * same linear part. GIven two lattices 'A' and 'B' with affineparts [a1 .. an]</font>
1467 01459 <font class="comment"> * and [b1 ... bn], then A &lt; B if for some 0 &lt; i &lt;= n, ai &lt; bi and for 0 &lt; i1 &lt;</font>
1468 01460 <font class="comment"> * i, ai1 = bi1. </font>
1469 01461 <font class="comment"> */</font>
1470 <a name="l01462"></a><a class="code" href="Lattice_8c.html#a31">01462</a> <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a31">AffinePartCompare</a>(<font class="keyword">const</font> <font class="keywordtype">void</font> *A, <font class="keyword">const</font> <font class="keywordtype">void</font> *B) {
1471 01463
1472 01464 <font class="keywordtype">int</font> i;
1473 01465 Lattice **L1, **L2;
1474 01466
1475 01467 L1 = (Lattice **)A;
1476 01468 L2 = (Lattice **)B;
1477 01469
1478 01470 <font class="keywordflow">for</font> (i = 0; i &lt; L1[0]-&gt;NbRows; i++) {
1479 01471 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a24">value_gt</a>(L1[0]-&gt;p[i][L1[0]-&gt;NbColumns-1],L2[0]-&gt;p[i][L1[0]-&gt;NbColumns-1]))
1480 01472 <font class="keywordflow">return</font> 1;
1481 01473
1482 01474 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a26">value_lt</a>(L1[0]-&gt;p[i][L1[0]-&gt;NbColumns-1],L2[0]-&gt;p[i][L1[0]-&gt;NbColumns-1]))
1483 01475 <font class="keywordflow">return</font> -1;
1484 01476 }
1485 01477 <font class="keywordflow">return</font> 0 ;
1486 01478 } <font class="comment">/* AffinePartCompare */</font>
1487 01479
1488 01480 <font class="comment">/* </font>
1489 01481 <font class="comment"> * This function takes a list of lattices with the same linear part and sorts</font>
1490 01482 <font class="comment"> * them on the basis of their affine part. The sorting is done in place.</font>
1491 01483 <font class="comment"> */</font>
1492 <a name="l01484"></a><a class="code" href="Lattice_8c.html#a32">01484</a> <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="Lattice_8c.html#a32">AffinePartSort</a> (LatticeUnion *List) {
1493 01485
1494 01486 <font class="keywordtype">int</font> cnt;
1495 01487 Lattice **LatList;
1496 01488 LatticeUnion *tmp;
1497 01489
1498 01490 cnt = 0;
1499 01491 <font class="keywordflow">for</font> (tmp = List; tmp != NULL; tmp = tmp-&gt;next)
1500 01492 cnt ++;
1501 01493
1502 01494 LatList = (Lattice **) malloc (<font class="keyword">sizeof</font>(Lattice *) * cnt);
1503 01495
1504 01496 cnt = 0;
1505 01497 <font class="keywordflow">for</font> (tmp = List; tmp != NULL; tmp = tmp-&gt;next)
1506 01498 LatList[cnt++] = tmp-&gt;M;
1507 01499
1508 01500 qsort(LatList,cnt, <font class="keyword">sizeof</font> (Lattice *), <a class="code" href="Lattice_8c.html#a31">AffinePartCompare</a>);
1509 01501
1510 01502 cnt = 0;
1511 01503 <font class="keywordflow">for</font> (tmp = List; tmp != NULL; tmp = tmp-&gt;next)
1512 01504 tmp-&gt;M = LatList[cnt++];
1513 01505 <font class="keywordflow">return</font>;
1514 01506 } <font class="comment">/* AffinePartSort */</font>
1515 01507
1516 <a name="l01508"></a><a class="code" href="Lattice_8c.html#a33">01508</a> <font class="keyword">static</font> Bool <a class="code" href="Lattice_8c.html#a33">AlmostSameAffinePart</a>(LatticeUnion *A, LatticeUnion *B) {
1517 01509
1518 01510 <font class="keywordtype">int</font> i;
1519 01511
1520 01512 <font class="keywordflow">if</font> ((A == NULL) || (B == NULL))
1521 01513 <font class="keywordflow">return</font> False;
1522 01514
1523 01515 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;M-&gt;NbRows-1; i ++)
1524 01516 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(A-&gt;M-&gt;p[i][A-&gt;M-&gt;NbColumns-1],B-&gt;M-&gt;p[i][A-&gt;M-&gt;NbColumns-1]))
1525 01517 <font class="keywordflow">return</font> False;
1526 01518 <font class="keywordflow">return</font> True;
1527 01519 } <font class="comment">/* AlmostSameAffinePart */</font>
1528 01520
1529 01521 <font class="comment">/* </font>
1530 01522 <font class="comment"> * This function takes a list of lattices having the same linear part and tries</font>
1531 01523 <font class="comment"> * to simplify these lattices. This may not be the only way of simplifying the</font>
1532 01524 <font class="comment"> * lattices. The function returns a list of partially simplified lattices and </font>
1533 01525 <font class="comment"> * also a flag to tell whether any simplification was performed at all. </font>
1534 01526 <font class="comment"> */</font>
1535 <a name="l01527"></a><a class="code" href="Lattice_8c.html#a34">01527</a> <font class="keyword">static</font> Bool <a class="code" href="Lattice_8c.html#a34">AffinePartSimplify</a>(LatticeUnion *curlist, LatticeUnion **newlist) {
1536 01528
1537 01529 <font class="keywordtype">int</font> i;
1538 01530 <a class="code" href="arithmetique_8h.html#a93">Value</a> aux;
1539 01531 LatticeUnion *temp, *curr, *next;
1540 01532 LatticeUnion *nextlist;
1541 01533 Bool change = False, chng;
1542 01534
1543 01535 <font class="keywordflow">if</font> (curlist == NULL)
1544 01536 <font class="keywordflow">return</font> False;
1545 01537
1546 01538 <font class="keywordflow">if</font> (curlist-&gt;next == NULL) {
1547 01539 curlist-&gt;next = newlist[0];
1548 01540 newlist[0] = curlist;
1549 01541 <font class="keywordflow">return</font> False ;
1550 01542 }
1551 01543
1552 01544 <a class="code" href="arithmetique_8h.html#a10">value_init</a>(aux);
1553 01545 <font class="keywordflow">for</font> (i = 0; i &lt; curlist-&gt;M-&gt;NbRows - 1; i ++) {
1554 01546
1555 01547 <font class="comment">/* Interchanging the elements of the Affine part for easy computation</font>
1556 01548 <font class="comment"> of the sort (using qsort) */</font>
1557 01549
1558 01550 <font class="keywordflow">for</font> (temp = curlist; temp != NULL; temp = temp-&gt;next) {
1559 01551 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(aux,temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1]);
1560 01552 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1],temp-&gt;M-&gt;p[i][temp-&gt;M-&gt;NbColumns-1]);
1561 01553 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[i][temp-&gt;M-&gt;NbColumns-1],aux);
1562 01554 }
1563 01555 <a class="code" href="Lattice_8c.html#a32">AffinePartSort</a>(curlist);
1564 01556 nextlist = NULL;
1565 01557 curr = curlist;
1566 01558 <font class="keywordflow">while</font> (curr != NULL) {
1567 01559 next = curr-&gt;next;
1568 01560 <font class="keywordflow">if</font> (!<a class="code" href="Lattice_8c.html#a33">AlmostSameAffinePart</a>(curr, next)) {
1569 01561 curr-&gt;next = NULL;
1570 01562 chng = <a class="code" href="Lattice_8c.html#a28">Simplify</a>(&amp;curlist, newlist, i);
1571 01563 <font class="keywordflow">if</font> (nextlist == NULL)
1572 01564 nextlist = curlist;
1573 01565 <font class="keywordflow">else</font> {
1574 01566 LatticeUnion *tmp;
1575 01567 <font class="keywordflow">for</font> (tmp = nextlist; tmp-&gt;next; tmp=tmp-&gt;next);
1576 01568 tmp-&gt;next = curlist;
1577 01569 }
1578 01570 change = change | chng ;
1579 01571 curlist = next;
1580 01572 }
1581 01573 curr = next;
1582 01574 }
1583 01575 curlist = nextlist;
1584 01576
1585 01577 <font class="comment">/* Interchanging the elements of the Affine part for easy computation</font>
1586 01578 <font class="comment"> of the sort (using qsort) */</font>
1587 01579
1588 01580 <font class="keywordflow">for</font>(temp = curlist; temp != NULL; temp = temp-&gt;next) {
1589 01581 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(aux,temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1]);
1590 01582 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[temp-&gt;M-&gt;NbRows-1][temp-&gt;M-&gt;NbColumns-1],temp-&gt;M-&gt;p[i][temp-&gt;M-&gt;NbColumns-1]);
1591 01583 <a class="code" href="arithmetique_8h.html#a11">value_assign</a>(temp-&gt;M-&gt;p[i][temp-&gt;M-&gt;NbColumns-1],aux);
1592 01584 }
1593 01585 <font class="keywordflow">if</font> (curlist == NULL)
1594 01586 <font class="keywordflow">break</font>;
1595 01587 }
1596 01588 <font class="keywordflow">if</font> ( *newlist == NULL)
1597 01589 *newlist = nextlist;
1598 01590 <font class="keywordflow">else</font> {
1599 01591 <font class="keywordflow">for</font> (curr = *newlist; curr-&gt;next != NULL; curr = curr-&gt;next);
1600 01592 curr-&gt;next = nextlist;
1601 01593 }
1602 01594 <a class="code" href="arithmetique_8h.html#a14">value_clear</a>(aux);
1603 01595 <font class="keywordflow">return</font> change;
1604 01596 } <font class="comment">/* AffinePartSimplify */</font>
1605 01597
1606 <a name="l01598"></a><a class="code" href="Lattice_8c.html#a35">01598</a> <font class="keyword">static</font> Bool <a class="code" href="Lattice_8c.html#a35">SameLinearPart</a>(LatticeUnion *A, LatticeUnion *B) {
1607 01599
1608 01600 <font class="keywordtype">int</font> i, j;
1609 01601 <font class="keywordflow">if</font> ((A == NULL) || (B ==NULL))
1610 01602 <font class="keywordflow">return</font> False;
1611 01603 <font class="keywordflow">for</font> (i = 0; i &lt; A-&gt;M-&gt;NbRows-1; i++)
1612 01604 <font class="keywordflow">for</font> (j = 0; j &lt;= i; j++)
1613 01605 <font class="keywordflow">if</font> (<a class="code" href="arithmetique_8h.html#a23">value_ne</a>(A-&gt;M-&gt;p[i][j],B-&gt;M-&gt;p[i][j]))
1614 01606 <font class="keywordflow">return</font> False;
1615 01607
1616 01608 <font class="keywordflow">return</font> True;
1617 01609 } <font class="comment">/* SameLinearPart */</font>
1618 01610
1619 01611 <font class="comment">/* </font>
1620 01612 <font class="comment"> * Given a union of lattices, return a simplified list of lattices. </font>
1621 01613 <font class="comment"> */</font>
1622 <a name="l01614"></a><a class="code" href="Lattice_8c.html#a36">01614</a> LatticeUnion *<a class="code" href="Lattice_8c.html#a36">LatticeSimplify</a>(LatticeUnion *latlist) {
1623 01615
1624 01616 LatticeUnion *curlist, *nextlist;
1625 01617 LatticeUnion *curr, *next;
1626 01618 Bool change = True, chng;
1627 01619
1628 01620 curlist = latlist;
1629 01621 <font class="keywordflow">while</font> (change == True) {
1630 01622 change = False;
1631 01623 <a class="code" href="Lattice_8c.html#a30">LinearPartSort</a>(curlist);
1632 01624 curr = curlist;
1633 01625 nextlist = NULL;
1634 01626 <font class="keywordflow">while</font>(curr != NULL) {
1635 01627 next = curr-&gt;next;
1636 01628 <font class="keywordflow">if</font> (!<a class="code" href="Lattice_8c.html#a35">SameLinearPart</a>(curr, next)) {
1637 01629 curr-&gt;next = NULL;
1638 01630 chng = <a class="code" href="Lattice_8c.html#a34">AffinePartSimplify</a>(curlist, &amp;nextlist);
1639 01631 change = change | chng ;
1640 01632 curlist = next;
1641 01633 }
1642 01634 curr = next;
1643 01635 }
1644 01636 curlist = nextlist;
1645 01637 }
1646 01638 <font class="keywordflow">return</font> curlist;
1647 01639 } <font class="comment">/* LatticeSimplify */</font>
1648 01640
1649 <a name="l01641"></a><a class="code" href="Lattice_8c.html#a37">01641</a> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a37">intcompare</a> (<font class="keyword">const</font> <font class="keywordtype">void</font> *a, <font class="keyword">const</font> <font class="keywordtype">void</font> *b) {
1650 01642
1651 01643 <font class="keywordtype">int</font> *i, *j;
1652 01644
1653 01645 i = (<font class="keywordtype">int</font> *) a;
1654 01646 j = (<font class="keywordtype">int</font> *) b;
1655 01647 <font class="keywordflow">if</font> (*i &gt; *j)
1656 01648 <font class="keywordflow">return</font> 1;
1657 01649 <font class="keywordflow">if</font> (*i &lt; *j)
1658 01650 <font class="keywordflow">return</font> -1;
1659 01651 <font class="keywordflow">return</font> 0;
1660 01652 } <font class="comment">/* intcompare */</font>
1661 01653
1662 01654 <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a38">polylib_sqrt</a>(<font class="keywordtype">int</font> i);
1663 <a name="l01655"></a><a class="code" href="Lattice_8c.html#a0">01655</a> <font class="keyword">static</font> <a class="code" href="structfactor.html">factor</a> <a class="code" href="Lattice_8c.html#a0">allfactors</a> (<font class="keywordtype">int</font> num) {
1664 01656
1665 01657 <font class="keywordtype">int</font> i,j, tmp;
1666 01658 <font class="keywordtype">int</font> noofelmts = 1;
1667 01659 <font class="keywordtype">int</font> *list, *newlist;
1668 01660 <font class="keywordtype">int</font> count;
1669 01661 <a class="code" href="structfactor.html">factor</a> result;
1670 01662
1671 01663 list = (<font class="keywordtype">int</font> *)malloc(<font class="keyword">sizeof</font> (<font class="keywordtype">int</font>));
1672 01664 list[0] = 1;
1673 01665
1674 01666 tmp = num;
1675 01667 <font class="keywordflow">for</font> (i = 2; i &lt;= <a class="code" href="Lattice_8c.html#a38">polylib_sqrt</a>(tmp); i++) {
1676 01668 <font class="keywordflow">if</font> ((tmp % i) == 0) {
1677 01669 <font class="keywordflow">if</font> (noofelmts == 0) {
1678 01670 list = (<font class="keywordtype">int</font> *) malloc (<font class="keyword">sizeof</font> (<font class="keywordtype">int</font>));
1679 01671 list[0] = i;
1680 01672 noofelmts = 1;
1681 01673 }
1682 01674 <font class="keywordflow">else</font> {
1683 01675 newlist = (<font class="keywordtype">int</font> *) malloc (<font class="keyword">sizeof</font> (<font class="keywordtype">int</font>) * 2 * noofelmts + 1);
1684 01676 <font class="keywordflow">for</font> (j = 0; j &lt; noofelmts; j++)
1685 01677 newlist[j] = list[j] ;
1686 01678 newlist[j] = i;
1687 01679 <font class="keywordflow">for</font> (j = 0; j &lt; noofelmts; j++)
1688 01680 newlist[j+noofelmts+1] = i * list[j];
1689 01681 free (list);
1690 01682 list = newlist;
1691 01683 noofelmts= 2*noofelmts+1;
1692 01684 }
1693 01685 tmp = tmp / i;
1694 01686 i = 1;
1695 01687 }
1696 01688 }
1697 01689
1698 01690 <font class="keywordflow">if</font> ((tmp != 0) &amp;&amp; (tmp != num)) {
1699 01691 newlist = (<font class="keywordtype">int</font> *) malloc (<font class="keyword">sizeof</font> (<font class="keywordtype">int</font>) * 2 * noofelmts + 1);
1700 01692 <font class="keywordflow">for</font> (j = 0; j &lt; noofelmts; j ++)
1701 01693 newlist[j] = list[j] ;
1702 01694 newlist[j] = tmp;
1703 01695 <font class="keywordflow">for</font> (j = 0; j &lt; noofelmts; j ++)
1704 01696 newlist[j+noofelmts+1] = tmp * list[j];
1705 01697 free (list);
1706 01698 list = newlist;
1707 01699 noofelmts= 2*noofelmts+1;
1708 01700 }
1709 01701 qsort (list, noofelmts, <font class="keyword">sizeof</font>(<font class="keywordtype">int</font>), <a class="code" href="Lattice_8c.html#a37">intcompare</a>);
1710 01702 count = 1;
1711 01703 <font class="keywordflow">for</font> (i = 1; i &lt; noofelmts; i ++)
1712 01704 <font class="keywordflow">if</font> (list[i] != list[i-1])
1713 01705 list[count++] = list[i];
1714 01706 <font class="keywordflow">if</font> (list[count-1] == num)
1715 01707 count --;
1716 01708
1717 01709 result.<a class="code" href="structfactor.html#m1">fac</a> = (<font class="keywordtype">int</font> *) malloc (<font class="keyword">sizeof</font> (<font class="keywordtype">int</font>) * count);
1718 01710 result.<a class="code" href="structfactor.html#m0">count</a> = count;
1719 01711 <font class="keywordflow">for</font> (i = 0; i &lt; count; i ++)
1720 01712 result.<a class="code" href="structfactor.html#m1">fac</a>[i] = list[i];
1721 01713 free (list);
1722 01714 <font class="keywordflow">return</font> result;
1723 01715 } <font class="comment">/* allfactors */</font>
1724 01716
1725 <a name="l01717"></a><a class="code" href="Lattice_8c.html#a38">01717</a> <font class="keyword">static</font> <font class="keywordtype">int</font> <a class="code" href="Lattice_8c.html#a38">polylib_sqrt</a> (<font class="keywordtype">int</font> i) {
1726 01718
1727 01719 <font class="keywordtype">int</font> j;
1728 01720 j = 0;
1729 01721 i = i &gt; 0 ? i : -i;
1730 01722
1731 01723 <font class="keywordflow">while</font> (1) {
1732 01724 <font class="keywordflow">if</font> ((j * j) &gt; i)
1733 01725 <font class="keywordflow">break</font>;
1734 01726 <font class="keywordflow">else</font>
1735 01727 j ++;
1736 01728 }
1737 01729 <font class="keywordflow">return</font> (j-1);
1738 01730 } <font class="comment">/* polylib_sqrt */</font>
1739 01731
1740 01732
1741 01733
1742 01734
1743 01735
1744 01736
1745 01737
1746 </pre></div><hr><address align="right"><small>Generated on Fri Nov 8 12:10:06 2002 for Polylib by
1747 <a href="http://www.doxygen.org/index.html">
1748 <img src="doxygen.png" alt="doxygen" align="middle" border=0
1749 width=110 height=53></a>1.2.15 </small></address>
1750 </body>
1751 </html>