1 | ////////////////////////////////////////////////////////////////////////////// |
---|
2 | version="$Id: jacobson.lib,v 1.4 2008-12-01 20:51:16 levandov Exp $"; |
---|
3 | category="System and Control Theory"; |
---|
4 | info=" |
---|
5 | LIBRARY: jacobson.lib Algorithms for Smith and Jacobson Normal Form |
---|
6 | AUTHOR: Kristina Schindelar, Kristina.Schindelar@math.rwth-aachen.de |
---|
7 | |
---|
8 | THEORY: We work over a ring R, that is a principal ideal domain. |
---|
9 | @* If R is commutative, we suppose R to be a polynomial ring in one variable. |
---|
10 | @* If R is non-commutative, we suppose R to be in two variables, say x and d. We treat |
---|
11 | @* then the Ore localization of R with respect to the mult.closed set S = K[x] without 0. |
---|
12 | @* Given a rectangular matrix M over R, one can compute unimodular matrices U, V |
---|
13 | @* such that U*M*V=D is a diagonal matrix. |
---|
14 | @* Depending on the ring, the diagonal entries of D have certain properties. |
---|
15 | |
---|
16 | PROCEDURES: |
---|
17 | smith(R,M[,eng1,eng2]); compute the Smith Normal Form of M over commutative ring |
---|
18 | jacobson(R,M[,eng]); compute a weak Jacobson Normal Form of M over non-commutative ring, i.e. a diagonal matrix |
---|
19 | |
---|
20 | SEE ALSO: control_lib |
---|
21 | "; |
---|
22 | LIB "poly.lib"; |
---|
23 | LIB "involut.lib"; |
---|
24 | |
---|
25 | proc smith(R, matrix MA, list #) |
---|
26 | "USAGE: smith(R, M[, eng1, eng2]); R ring, M matrix, eng1 and eng2 are optional int |
---|
27 | RETURN: list |
---|
28 | NOTE: By default, the diagonal matrix, the Smith normal form, is returned. |
---|
29 | @* If optional integer eng1 is nonzero, smith returns |
---|
30 | @* a list of matrices L such that L[1]*M*L[3]=L[2] with L[2]_11|L[2]_22|...|L[2]_nn and |
---|
31 | @* L[1], L[3] unimodular matrices. |
---|
32 | @* eng2 determines the engine, that computes the Groebner basis. By default eng2 equals zero. |
---|
33 | @* If optional integer eng2 = 0 than std is used to caculate a Groebner basis , |
---|
34 | @* If eng2 = 1 than groebner is used to caculate a Groebner basis |
---|
35 | @* If eng2 = 2 than slimgb is used to caculate a Groebner basis |
---|
36 | @* If @code{printlevel}=1, progress debug messages will be printed, |
---|
37 | @* if @code{printlevel}>=2, all the debug messages will be printed. |
---|
38 | EXAMPLE: example smith; shows examples |
---|
39 | " |
---|
40 | { |
---|
41 | int eng = 0; |
---|
42 | int BASIS; |
---|
43 | if ( size(#)>0 ) |
---|
44 | { |
---|
45 | eng=1; |
---|
46 | if (typeof(#[1])=="int") |
---|
47 | { |
---|
48 | eng=int(#[1]); // zero can also happen |
---|
49 | } |
---|
50 | } |
---|
51 | if (size(#)==2) |
---|
52 | { |
---|
53 | BASIS=#[2]; |
---|
54 | } |
---|
55 | else{BASIS=0;} |
---|
56 | |
---|
57 | |
---|
58 | int ROW=ncols(MA); |
---|
59 | int COL=nrows(MA); |
---|
60 | |
---|
61 | //generate a module consisting of the columns of MA |
---|
62 | module m=MA[1]; |
---|
63 | int i; |
---|
64 | for(i=2;i<=ROW;i++) |
---|
65 | { |
---|
66 | m=m,MA[i]; |
---|
67 | } |
---|
68 | |
---|
69 | //if MA eqauls the zero matrix give back MA |
---|
70 | if ( (size(m)==0) and (size(transpose(m))==0) ) |
---|
71 | { |
---|
72 | module L=freemodule(COL); |
---|
73 | matrix LM=L; |
---|
74 | L=freemodule(ROW); |
---|
75 | matrix RM=L; |
---|
76 | list RUECK=RM; |
---|
77 | RUECK=insert(RUECK,MA); |
---|
78 | RUECK=insert(RUECK,LM); |
---|
79 | return(RUECK); |
---|
80 | } |
---|
81 | |
---|
82 | if(eng==1) |
---|
83 | { |
---|
84 | list rueckLI=diagonal_with_trafo(R,MA,BASIS); |
---|
85 | list rueckLII=divisibility(rueckLI[2]); |
---|
86 | matrix CON=divideByContent(rueckLII[2]); |
---|
87 | list rueckL=CON*rueckLII[1]*rueckLI[1], CON*rueckLII[2], rueckLI[3]*rueckLII[3]; |
---|
88 | return(rueckL); |
---|
89 | } |
---|
90 | else |
---|
91 | { |
---|
92 | matrix rueckm=diagonal_without_trafo(R,MA,BASIS); |
---|
93 | list rueckL=divisibility(rueckm); |
---|
94 | matrix CON=divideByContent(rueckm); |
---|
95 | rueckm=CON*rueckL[2]; |
---|
96 | return(rueckm); |
---|
97 | } |
---|
98 | } |
---|
99 | example |
---|
100 | { "EXAMPLE:"; echo = 2; |
---|
101 | ring r = 0,x,Dp; |
---|
102 | matrix m[3][2]=x, x^4+x^2+21, x^4+x^2+x, x^3+x, 4*x^2+x, x; |
---|
103 | list s=smith(r,m,1); |
---|
104 | print(s[2]); |
---|
105 | print(s[1]*m*s[3]); |
---|
106 | } |
---|
107 | |
---|
108 | static proc diagonal_with_trafo( R, matrix MA, int B) |
---|
109 | { |
---|
110 | |
---|
111 | int ppl = printlevel-voice+2; |
---|
112 | |
---|
113 | int BASIS=B; |
---|
114 | int ROW=ncols(MA); |
---|
115 | int COL=nrows(MA); |
---|
116 | module m=MA[1]; |
---|
117 | int i,j,k; |
---|
118 | for(i=2;i<=ROW;i++) |
---|
119 | { |
---|
120 | m=m,MA[i]; |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | //add zero rows or columns |
---|
125 | //add zero rows or columns |
---|
126 | int adrow=0; |
---|
127 | for(i=1;i<=COL;i++) |
---|
128 | { |
---|
129 | k=0; |
---|
130 | for(j=1;j<=ROW;j++) |
---|
131 | { |
---|
132 | if(MA[i,j]!=0){k=1;} |
---|
133 | } |
---|
134 | if(k==0){adrow++;} |
---|
135 | } |
---|
136 | |
---|
137 | m=transpose(m); |
---|
138 | for(i=1;i<=adrow;i++){m=m,0;} |
---|
139 | m=transpose(m); |
---|
140 | |
---|
141 | list RINGLIST=ringlist(R); |
---|
142 | list o="C",0; |
---|
143 | list oo="lp",1; |
---|
144 | list ORD=o,oo; |
---|
145 | RINGLIST[3]=ORD; |
---|
146 | def r=ring(RINGLIST); |
---|
147 | setring r; |
---|
148 | //fix the required ordering |
---|
149 | map MAP=R,var(1); |
---|
150 | module m=MAP(m); |
---|
151 | |
---|
152 | int flag=1; ///////////////counts if the underlying ring is r (flag mod 2 == 1) or ro (flag mod 2 == 0) |
---|
153 | |
---|
154 | module TrafoL=freemodule(COL); |
---|
155 | module TrafoR=freemodule(ROW); |
---|
156 | module EXL=freemodule(COL); //because we start with transpose(m) |
---|
157 | module EXR=freemodule(ROW); |
---|
158 | |
---|
159 | option(redSB); |
---|
160 | option(redTail); |
---|
161 | module STD_EX; |
---|
162 | module Trafo; |
---|
163 | |
---|
164 | int s,st,p,ff; |
---|
165 | |
---|
166 | module LT,TSTD; |
---|
167 | module STD=transpose(m); |
---|
168 | int finish=0; |
---|
169 | int fehlpos; |
---|
170 | list pos; |
---|
171 | matrix END; |
---|
172 | matrix ENDSTD; |
---|
173 | matrix STDFIN; |
---|
174 | STDFIN=STD; |
---|
175 | list COMPARE=STDFIN; |
---|
176 | |
---|
177 | while(finish==0) |
---|
178 | { |
---|
179 | dbprint(ppl,"Going into the while cycle"); |
---|
180 | |
---|
181 | if(flag mod 2==1) |
---|
182 | { |
---|
183 | STD_EX=EXL,transpose(STD); |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | STD_EX=EXR,transpose(STD); |
---|
188 | } |
---|
189 | dbprint(ppl,"Computing Groebner basis: start"); |
---|
190 | dbprint(ppl-1,STD); |
---|
191 | STD=engine(STD,BASIS); |
---|
192 | dbprint(ppl,"Computing Groebner basis: finished"); |
---|
193 | dbprint(ppl-1,STD); |
---|
194 | |
---|
195 | if(flag mod 2==1){s=ROW; st=COL;}else{s=COL; st=ROW;} |
---|
196 | dbprint(ppl,"Computing Groebner basis for transformation matrix: start"); |
---|
197 | dbprint(ppl-1,STD_EX); |
---|
198 | STD_EX=transpose(STD_EX); |
---|
199 | STD_EX=engine(STD_EX,BASIS); |
---|
200 | dbprint(ppl,"Computing Groebner basis for transformation matrix: finished"); |
---|
201 | dbprint(ppl-1,STD_EX); |
---|
202 | |
---|
203 | //////// split STD_EX in STD and the transformation matrix |
---|
204 | STD_EX=transpose(STD_EX); |
---|
205 | STD=STD_EX[st+1]; |
---|
206 | LT=STD_EX[1]; |
---|
207 | |
---|
208 | ENDSTD=STD_EX; |
---|
209 | for(i=2; i<=ncols(ENDSTD); i++) |
---|
210 | { |
---|
211 | if (i<=st) |
---|
212 | { |
---|
213 | LT=LT,STD_EX[i]; |
---|
214 | } |
---|
215 | if (i>st+1) |
---|
216 | { |
---|
217 | STD=STD,STD_EX[i]; |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | STD=transpose(STD); |
---|
222 | LT=transpose(LT); |
---|
223 | |
---|
224 | ////////////////////// compute the transformation matrices |
---|
225 | |
---|
226 | if (flag mod 2 ==1) |
---|
227 | { |
---|
228 | TrafoL=transpose(LT)*TrafoL; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | TrafoR=TrafoR*LT; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | STDFIN=STD; |
---|
237 | /////////////////////////////////// check if the D-th row is finished /////////////////////////////////// |
---|
238 | COMPARE=insert(COMPARE,STDFIN); |
---|
239 | if(size(COMPARE)>=3) |
---|
240 | { |
---|
241 | if(STD==COMPARE[3]){finish=1;} |
---|
242 | } |
---|
243 | ////////////////////////////////// change to the opposite module |
---|
244 | TSTD=transpose(STD); |
---|
245 | STD=TSTD; |
---|
246 | flag++; |
---|
247 | dbprint(ppl,"Finished one while cycle"); |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | if (flag mod 2!=0) { STD=transpose(STD); } |
---|
252 | |
---|
253 | |
---|
254 | //zero colums to the end |
---|
255 | matrix STDMM=STD; |
---|
256 | pos=list(); |
---|
257 | fehlpos=0; |
---|
258 | while( size(STD)+fehlpos-ncols(STDMM) < 0) |
---|
259 | { |
---|
260 | for(i=1; i<=ncols(STDMM); i++) |
---|
261 | { |
---|
262 | ff=0; |
---|
263 | for(j=1; j<=nrows(STDMM); j++) |
---|
264 | { |
---|
265 | if (STD[j,i]==0) { ff++; } |
---|
266 | } |
---|
267 | if(ff==nrows(STDMM)) |
---|
268 | { |
---|
269 | pos=insert(pos,i); fehlpos++; |
---|
270 | } |
---|
271 | } |
---|
272 | } |
---|
273 | int fehlposc=fehlpos; |
---|
274 | module SORT; |
---|
275 | for(i=1; i<=fehlpos; i++) |
---|
276 | { |
---|
277 | SORT=gen(2); |
---|
278 | for (j=3;j<=ROW;j++) |
---|
279 | { |
---|
280 | SORT=SORT,gen(j); |
---|
281 | } |
---|
282 | SORT=SORT,gen(1); |
---|
283 | STD=STD*SORT; |
---|
284 | TrafoR=TrafoR*SORT; |
---|
285 | } |
---|
286 | |
---|
287 | //zero rows to the end |
---|
288 | STDMM=transpose(STD); |
---|
289 | pos=list(); |
---|
290 | fehlpos=0; |
---|
291 | while( size(transpose(STD))+fehlpos-ncols(STDMM) < 0) |
---|
292 | { |
---|
293 | for(i=1; i<=ncols(STDMM); i++) |
---|
294 | { |
---|
295 | ff=0; for(j=1; j<=nrows(STDMM); j++) |
---|
296 | { |
---|
297 | if(transpose(STD)[j,i]==0){ ff++;}} |
---|
298 | if(ff==nrows(STDMM)) { pos=insert(pos,i); fehlpos++; } |
---|
299 | } |
---|
300 | } |
---|
301 | int fehlposr=fehlpos; |
---|
302 | |
---|
303 | for(i=1; i<=fehlpos; i++) |
---|
304 | { |
---|
305 | SORT=gen(2); |
---|
306 | for(j=3;j<=COL;j++){SORT=SORT,gen(j);} |
---|
307 | SORT=SORT,gen(1); |
---|
308 | SORT=transpose(SORT); |
---|
309 | STD=SORT*STD; |
---|
310 | TrafoL=SORT*TrafoL; |
---|
311 | } |
---|
312 | |
---|
313 | setring R; |
---|
314 | map MAPinv=r,var(1); |
---|
315 | module STD=MAPinv(STD); |
---|
316 | module TrafoL=MAPinv(TrafoL); |
---|
317 | matrix TrafoLM=TrafoL; |
---|
318 | module TrafoR=MAPinv(TrafoR); |
---|
319 | matrix TrafoRM=TrafoR; |
---|
320 | matrix STDM=STD; |
---|
321 | |
---|
322 | //Test |
---|
323 | if(TrafoLM*m*TrafoRM!=STDM){ return(0); } |
---|
324 | |
---|
325 | list RUECK=TrafoRM; |
---|
326 | RUECK=insert(RUECK,STDM); |
---|
327 | RUECK=insert(RUECK,TrafoLM); |
---|
328 | return(RUECK); |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | static proc divisibility(matrix M) |
---|
333 | { |
---|
334 | matrix STDM=M; |
---|
335 | int i,j; |
---|
336 | int ROW=nrows(M); |
---|
337 | int COL=ncols(M); |
---|
338 | module TrafoR=freemodule(COL); |
---|
339 | module TrafoL=freemodule(ROW); |
---|
340 | module SORT; |
---|
341 | matrix TrafoRM=TrafoR; |
---|
342 | matrix TrafoLM=TrafoL; |
---|
343 | list posdeg0; |
---|
344 | int posdeg=0; |
---|
345 | int act; |
---|
346 | int Sort=ROW; |
---|
347 | if(size(std(STDM))!=0) |
---|
348 | { while( size(transpose(STDM)[Sort])==0 ){Sort--;}} |
---|
349 | |
---|
350 | for(i=1;i<=Sort ;i++) |
---|
351 | { |
---|
352 | if(leadexp(STDM[i,i])==0){posdeg0=insert(posdeg0,i);posdeg++;} |
---|
353 | } |
---|
354 | //entries of degree 0 at the beginning |
---|
355 | for(i=1; i<=posdeg; i++) |
---|
356 | { |
---|
357 | act=posdeg0[i]; |
---|
358 | SORT=gen(act); |
---|
359 | for(j=1; j<=COL; j++){if(j!=act){SORT=SORT,gen(j);}} |
---|
360 | STDM=STDM*SORT; |
---|
361 | TrafoRM=TrafoRM*SORT; |
---|
362 | SORT=gen(act); |
---|
363 | for(j=1; j<=ROW; j++){if(j!=act){SORT=SORT,gen(j);}} |
---|
364 | STDM=transpose(SORT)*STDM; |
---|
365 | TrafoLM=transpose(SORT)*TrafoLM; |
---|
366 | } |
---|
367 | |
---|
368 | poly G; |
---|
369 | module UNITL=freemodule(ROW); |
---|
370 | matrix GCDL=UNITL; |
---|
371 | module UNITR=freemodule(COL); |
---|
372 | matrix GCDR=UNITR; |
---|
373 | for(i=posdeg+1; i<=Sort; i++) |
---|
374 | { |
---|
375 | for(j=i+1; j<=Sort; j++) |
---|
376 | { |
---|
377 | GCDL=UNITL; |
---|
378 | GCDR=UNITR; |
---|
379 | G=gcd(STDM[i,i],STDM[j,j]); |
---|
380 | ideal Z=STDM[i,i],STDM[j,j]; |
---|
381 | matrix T=lift(Z,G); |
---|
382 | GCDL[i,i]=T[1,1]; |
---|
383 | GCDL[i,j]=T[2,1]; |
---|
384 | GCDL[j,i]=-STDM[j,j]/G; |
---|
385 | GCDL[j,j]=STDM[i,i]/G; |
---|
386 | GCDR[i,j]=T[2,1]*STDM[j,j]/G; |
---|
387 | GCDR[j,j]=T[2,1]*STDM[j,j]/G-1; |
---|
388 | GCDR[j,i]=1; |
---|
389 | STDM=GCDL*STDM*GCDR; |
---|
390 | TrafoLM=GCDL*TrafoLM; |
---|
391 | TrafoRM=TrafoRM*GCDR; |
---|
392 | } |
---|
393 | } |
---|
394 | list RUECK=TrafoRM; |
---|
395 | RUECK=insert(RUECK,STDM); |
---|
396 | RUECK=insert(RUECK,TrafoLM); |
---|
397 | return(RUECK); |
---|
398 | } |
---|
399 | |
---|
400 | static proc diagonal_without_trafo( R, matrix MA, int B) |
---|
401 | { |
---|
402 | int ppl = printlevel-voice+2; |
---|
403 | |
---|
404 | int BASIS=B; |
---|
405 | int ROW=ncols(MA); |
---|
406 | int COL=nrows(MA); |
---|
407 | module m=MA[1]; |
---|
408 | int i; |
---|
409 | for(i=2;i<=ROW;i++) |
---|
410 | {m=m,MA[i];} |
---|
411 | |
---|
412 | |
---|
413 | list RINGLIST=ringlist(R); |
---|
414 | list o="C",0; |
---|
415 | list oo="lp",1; |
---|
416 | list ORD=o,oo; |
---|
417 | RINGLIST[3]=ORD; |
---|
418 | def r=ring(RINGLIST); |
---|
419 | setring r; |
---|
420 | //RICHTIGE ORDNUNG MACHEN |
---|
421 | map MAP=R,var(1); |
---|
422 | module m=MAP(m); |
---|
423 | |
---|
424 | int flag=1; ///////////////counts if the underlying ring is r (flag mod 2 == 1) or ro (flag mod 2 == 0) |
---|
425 | |
---|
426 | |
---|
427 | int act, j, ff; |
---|
428 | option(redSB); |
---|
429 | option(redTail); |
---|
430 | |
---|
431 | |
---|
432 | module STD=transpose(m); |
---|
433 | module TSTD; |
---|
434 | int finish=0; |
---|
435 | matrix STDFIN; |
---|
436 | STDFIN=STD; |
---|
437 | list COMPARE=STDFIN; |
---|
438 | |
---|
439 | while(finish==0) |
---|
440 | { |
---|
441 | dbprint(ppl,"Going into the while cycle"); |
---|
442 | dbprint(ppl,"Computing Groebner basis: start"); |
---|
443 | dbprint(ppl-1,STD); |
---|
444 | STD=engine(STD,BASIS); |
---|
445 | dbprint(ppl,"Computing Groebner basis: finished"); |
---|
446 | dbprint(ppl-1,STD); |
---|
447 | STDFIN=STD; |
---|
448 | /////////////////////////////////// check if the D-th row is finished /////////////////////////////////// |
---|
449 | COMPARE=insert(COMPARE,STDFIN); |
---|
450 | if(size(COMPARE)>=3) |
---|
451 | { |
---|
452 | if(STD==COMPARE[3]){finish=1;} |
---|
453 | } |
---|
454 | ////////////////////////////////// change to the opposite module |
---|
455 | |
---|
456 | TSTD=transpose(STD); |
---|
457 | STD=TSTD; |
---|
458 | flag++; |
---|
459 | dbprint(ppl,"Finished one while cycle"); |
---|
460 | } |
---|
461 | |
---|
462 | matrix STDMM=STD; |
---|
463 | list pos=list(); |
---|
464 | int fehlpos=0; |
---|
465 | while( size(STD)+fehlpos-ncols(STDMM) < 0) |
---|
466 | { |
---|
467 | for(i=1; i<=ncols(STDMM); i++) |
---|
468 | { |
---|
469 | ff=0; |
---|
470 | for(j=1; j<=nrows(STDMM); j++) |
---|
471 | { |
---|
472 | if (STD[j,i]==0) { ff++; } |
---|
473 | } |
---|
474 | if(ff==nrows(STDMM)) |
---|
475 | { |
---|
476 | pos=insert(pos,i); fehlpos++; |
---|
477 | } |
---|
478 | } |
---|
479 | } |
---|
480 | int fehlposc=fehlpos; |
---|
481 | module SORT; |
---|
482 | for(i=1; i<=fehlpos; i++) |
---|
483 | { |
---|
484 | SORT=gen(2); |
---|
485 | for (j=3;j<=ROW;j++) |
---|
486 | { |
---|
487 | SORT=SORT,gen(j); |
---|
488 | } |
---|
489 | SORT=SORT,gen(1); |
---|
490 | STD=STD*SORT; |
---|
491 | } |
---|
492 | |
---|
493 | //zero rows to the end |
---|
494 | STDMM=transpose(STD); |
---|
495 | pos=list(); |
---|
496 | fehlpos=0; |
---|
497 | while( size(transpose(STD))+fehlpos-ncols(STDMM) < 0) |
---|
498 | { |
---|
499 | for(i=1; i<=ncols(STDMM); i++) |
---|
500 | { |
---|
501 | ff=0; for(j=1; j<=nrows(STDMM); j++) |
---|
502 | { |
---|
503 | if(transpose(STD)[j,i]==0){ ff++;}} |
---|
504 | if(ff==nrows(STDMM)) { pos=insert(pos,i); fehlpos++; } |
---|
505 | } |
---|
506 | } |
---|
507 | int fehlposr=fehlpos; |
---|
508 | |
---|
509 | for(i=1; i<=fehlpos; i++) |
---|
510 | { |
---|
511 | SORT=gen(2); |
---|
512 | for(j=3;j<=COL;j++){SORT=SORT,gen(j);} |
---|
513 | SORT=SORT,gen(1); |
---|
514 | SORT=transpose(SORT); |
---|
515 | STD=SORT*STD; |
---|
516 | } |
---|
517 | |
---|
518 | //add zero rows or columns |
---|
519 | |
---|
520 | int adrow=COL-size(transpose(STD)); |
---|
521 | int adcol=ROW-size(STD); |
---|
522 | |
---|
523 | for(i=1;i<=adcol;i++){STD=STD,0;} |
---|
524 | STD=transpose(STD); |
---|
525 | for(i=1;i<=adrow;i++){STD=STD,0;} |
---|
526 | STD=transpose(STD); |
---|
527 | |
---|
528 | setring R; |
---|
529 | map MAPinv=r,var(1); |
---|
530 | module STD=MAPinv(STD); |
---|
531 | matrix STDM=STD; |
---|
532 | return(STDM); |
---|
533 | } |
---|
534 | |
---|
535 | |
---|
536 | |
---|
537 | static proc engine(module I, int i) |
---|
538 | { |
---|
539 | module J; |
---|
540 | if (i==0) |
---|
541 | { |
---|
542 | J = std(I); |
---|
543 | } |
---|
544 | if (i==1) |
---|
545 | { |
---|
546 | J = groebner(I); |
---|
547 | } |
---|
548 | if (i==2) |
---|
549 | { |
---|
550 | J = slimgb(I); |
---|
551 | } |
---|
552 | return(J); |
---|
553 | } |
---|
554 | |
---|
555 | proc jacobson(R, matrix MA, list #) |
---|
556 | "USAGE: jacobson(R, matrix MA, eng); R ring, M matrix, eng an optional int |
---|
557 | RETURN: list |
---|
558 | NOTE: A list of matrices L such that L[1]*M*L[3]=L[2] such that L[2] is a diagonal matrix and |
---|
559 | @* L[1], L[3] unimodular matrices. |
---|
560 | @* eng determines the engine, that computes the Groebner basis. By default eng equals zero. |
---|
561 | @* If eng = 0 than std is used to caculate a Groebner basis |
---|
562 | @* If eng = 1 than groebner is used to caculate a Groebner basis |
---|
563 | @* If eng = 2 than slimgb is used to caculate a Groebner basis |
---|
564 | @* If @code{printlevel}=1, progress debug messages will be printed, |
---|
565 | @* if @code{printlevel}>=2, all the debug messages will be printed. |
---|
566 | EXAMPLE: example jacobson; shows examples |
---|
567 | " |
---|
568 | { |
---|
569 | int B=0; |
---|
570 | if ( size(#)>0 ) |
---|
571 | { |
---|
572 | B=1; |
---|
573 | if (typeof(#[1])=="int") |
---|
574 | { |
---|
575 | B=int(#[1]); // zero can also happen |
---|
576 | } |
---|
577 | } |
---|
578 | |
---|
579 | //change ring |
---|
580 | list RINGLIST=ringlist(R); |
---|
581 | list o="C",0; |
---|
582 | intvec v=1,0; |
---|
583 | list oo="a",v; |
---|
584 | v=1,1; |
---|
585 | list ooo="lp",v; |
---|
586 | list ORD=o,oo,ooo; |
---|
587 | RINGLIST[3]=ORD; |
---|
588 | def r=ring(RINGLIST); |
---|
589 | setring r; |
---|
590 | |
---|
591 | //fix the required ordering |
---|
592 | map MAP=R,var(1),var(2); |
---|
593 | matrix M=MAP(MA); |
---|
594 | |
---|
595 | module TrafoL, TrafoR; |
---|
596 | list TRIANGLE; |
---|
597 | TRIANGLE=triangle(M,B); |
---|
598 | TrafoL=TRIANGLE[1]; |
---|
599 | TrafoR=TRIANGLE[3]; |
---|
600 | module m=TRIANGLE[2]; |
---|
601 | |
---|
602 | //back to the ring |
---|
603 | setring R; |
---|
604 | map MAPR=r,var(1),var(2); |
---|
605 | module ma=MAPR(m); |
---|
606 | matrix MAA=ma; |
---|
607 | module TL=MAPR(TrafoL); |
---|
608 | module TR=MAPR(TrafoR); |
---|
609 | matrix CON=divideByContent(MAA); |
---|
610 | |
---|
611 | list RUECK=CON*TL, CON*MAA, TR; |
---|
612 | return(RUECK); |
---|
613 | } |
---|
614 | example |
---|
615 | { "EXAMPLE:"; echo = 2; |
---|
616 | ring r = 0,(x,d),Dp; |
---|
617 | def R=nc_algebra(1,1); // the Weyl algebra |
---|
618 | setring R; |
---|
619 | matrix m[2][2]=d,x,0,d; print(m); |
---|
620 | list J=jacobson(R,m); // returns a list with 3 entries |
---|
621 | print(J[2]); // a Jacobson Form D |
---|
622 | print(J[1]*m*J[3]); // check that U*M*V = D |
---|
623 | } |
---|
624 | |
---|
625 | |
---|
626 | |
---|
627 | static proc triangle( matrix MA, int B) |
---|
628 | { |
---|
629 | int ppl = printlevel-voice+2; |
---|
630 | |
---|
631 | map inv=ncdetection(); |
---|
632 | int ROW=ncols(MA); |
---|
633 | int COL=nrows(MA); |
---|
634 | |
---|
635 | //generate a module consisting of the columns of MA |
---|
636 | module m=MA[1]; |
---|
637 | int i,j,s,st,p,k,ff,ex, nz, ii,nextp; |
---|
638 | for(i=2;i<=ROW;i++) |
---|
639 | { |
---|
640 | m=m,MA[i]; |
---|
641 | } |
---|
642 | int BASIS=B; |
---|
643 | |
---|
644 | //add zero rows or columns |
---|
645 | int adrow=0; |
---|
646 | for(i=1;i<=COL;i++) |
---|
647 | { |
---|
648 | k=0; |
---|
649 | for(j=1;j<=ROW;j++) |
---|
650 | { |
---|
651 | if(MA[i,j]!=0){k=1;} |
---|
652 | } |
---|
653 | if(k==0){adrow++;} |
---|
654 | } |
---|
655 | |
---|
656 | m=transpose(m); |
---|
657 | for(i=1;i<=adrow;i++){m=m,0;} |
---|
658 | m=transpose(m); |
---|
659 | |
---|
660 | |
---|
661 | int flag=1; ///////////////counts if the underlying ring is r (flag mod 2 == 1) or ro (flag mod 2 == 0) |
---|
662 | |
---|
663 | module TrafoL=freemodule(COL); |
---|
664 | module TrafoR=freemodule(ROW); |
---|
665 | module EXL=freemodule(COL); //because we start with transpose(m) |
---|
666 | module EXR=freemodule(ROW); |
---|
667 | |
---|
668 | option(redSB); |
---|
669 | option(redTail); |
---|
670 | module STD_EX,LT,TSTD, L, Trafo; |
---|
671 | |
---|
672 | |
---|
673 | |
---|
674 | module STD=transpose(m); |
---|
675 | int finish=0; |
---|
676 | list pos, COM, COM_EX; |
---|
677 | matrix END, ENDSTD, STDFIN; |
---|
678 | STDFIN=STD; |
---|
679 | list COMPARE=STDFIN; |
---|
680 | |
---|
681 | |
---|
682 | while(finish==0) |
---|
683 | { |
---|
684 | dbprint(ppl,"Going into the while cycle"); |
---|
685 | if(flag mod 2==1){STD_EX=EXL,transpose(STD); ex=2*COL;} else {STD_EX=EXR,transpose(STD); ex=2*ROW;} |
---|
686 | |
---|
687 | dbprint(ppl,"Computing Groebner basis: start"); |
---|
688 | dbprint(ppl-1,STD); |
---|
689 | STD=engine(STD,BASIS); |
---|
690 | dbprint(ppl,"Computing Groebner basis: finished"); |
---|
691 | dbprint(ppl-1,STD); |
---|
692 | if(flag mod 2==1){s=ROW; st=COL;}else{s=COL; st=ROW;} |
---|
693 | |
---|
694 | STD_EX=transpose(STD_EX); |
---|
695 | dbprint(ppl,"Computing Groebner basis for transformation matrix: start"); |
---|
696 | dbprint(ppl-1,STD_EX); |
---|
697 | STD_EX=engine(STD_EX,BASIS); |
---|
698 | dbprint(ppl,"Computing Groebner basis for transformation matrix: finished"); |
---|
699 | dbprint(ppl-1,STD_EX); |
---|
700 | |
---|
701 | COM=1; |
---|
702 | COM_EX=1; |
---|
703 | for(i=2; i<=size(STD); i++) |
---|
704 | { COM=COM[1..size(COM)],i; COM_EX=COM_EX[1..size(COM_EX)],i; } |
---|
705 | nz=size(STD_EX)-size(STD); |
---|
706 | |
---|
707 | //zero rows in the begining |
---|
708 | |
---|
709 | if(size(STD)!=size(STD_EX) ) |
---|
710 | { |
---|
711 | for(i=1; i<=size(STD_EX)-size(STD); i++) |
---|
712 | { |
---|
713 | COM_EX=0,COM_EX[1..size(COM_EX)]; |
---|
714 | } |
---|
715 | } |
---|
716 | |
---|
717 | |
---|
718 | |
---|
719 | |
---|
720 | for(i=nz+1; i<=size(STD_EX); i++ ) |
---|
721 | {if( leadcoef(STD[i-nz])!=leadcoef(STD_EX[i]) ) {STD[i-nz]=leadcoef(STD_EX[i])*STD[i-nz];} |
---|
722 | } |
---|
723 | |
---|
724 | //assign the zero rows in STD_EX |
---|
725 | |
---|
726 | for (j=2; j<=nz; j++) |
---|
727 | { |
---|
728 | p=0; |
---|
729 | i=1; |
---|
730 | while(STD_EX[j-1][i]==0){i++;}; |
---|
731 | p=i-1; |
---|
732 | nextp=1; |
---|
733 | k=0; |
---|
734 | i=1; |
---|
735 | while(STD_EX[j][i]==0 and i<=p) |
---|
736 | { k++; i++;} |
---|
737 | if (k==p){ COM_EX[j]=-1; } |
---|
738 | } |
---|
739 | |
---|
740 | //assign the zero rows in STD |
---|
741 | for (j=2; j<=size(STD); j++) |
---|
742 | { |
---|
743 | i=size(transpose(STD)); |
---|
744 | while(STD[j-1][i]==0){i--;} |
---|
745 | p=i; |
---|
746 | i=size(transpose(STD[j])); |
---|
747 | while(STD[j][i]==0){i--;} |
---|
748 | if (i==p){ COM[j]=-1; } |
---|
749 | } |
---|
750 | |
---|
751 | for(j=1; j<=size(COM); j++) |
---|
752 | { |
---|
753 | if(COM[j]<0){COM=delete(COM,j);} |
---|
754 | } |
---|
755 | |
---|
756 | for(i=1; i<=size(COM_EX); i++) |
---|
757 | {ff=0; |
---|
758 | if(COM_EX[i]==0){ff=1;} |
---|
759 | else |
---|
760 | { for(j=1; j<=size(COM); j++) |
---|
761 | { if(COM_EX[i]==COM[j]){ff=1;} } |
---|
762 | } |
---|
763 | if(ff==0){COM_EX[i]=-1;} |
---|
764 | } |
---|
765 | |
---|
766 | L=STD_EX[1]; |
---|
767 | for(i=2; i<=size(COM_EX); i++) |
---|
768 | { |
---|
769 | if(COM_EX[i]!=-1){L=L,STD_EX[i];} |
---|
770 | } |
---|
771 | |
---|
772 | //////// split STD_EX in STD and the transformation matrix |
---|
773 | |
---|
774 | L=transpose(L); |
---|
775 | STD=L[st+1]; |
---|
776 | LT=L[1]; |
---|
777 | |
---|
778 | |
---|
779 | for(i=2; i<=s+st; i++) |
---|
780 | { |
---|
781 | if (i<=st) |
---|
782 | { |
---|
783 | LT=LT,L[i]; |
---|
784 | } |
---|
785 | if (i>st+1) |
---|
786 | { |
---|
787 | STD=STD,L[i]; |
---|
788 | } |
---|
789 | } |
---|
790 | |
---|
791 | STD=transpose(STD); |
---|
792 | STDFIN=matrix(STD); |
---|
793 | COMPARE=insert(COMPARE,STDFIN); |
---|
794 | LT=transpose(LT); |
---|
795 | |
---|
796 | ////////////////////// compute the transformation matrices |
---|
797 | |
---|
798 | if (flag mod 2 ==1) |
---|
799 | { |
---|
800 | TrafoL=transpose(LT)*TrafoL; |
---|
801 | } |
---|
802 | else |
---|
803 | { |
---|
804 | TrafoR=TrafoR*involution(LT,inv); |
---|
805 | } |
---|
806 | |
---|
807 | |
---|
808 | ///////////////////////// check whether the alg termined ///////////////// |
---|
809 | if(size(COMPARE)>=3) |
---|
810 | { |
---|
811 | if(STD==COMPARE[3]){finish=1;} |
---|
812 | } |
---|
813 | ////////////////////////////////// change to the opposite module |
---|
814 | TSTD=transpose(STD); |
---|
815 | STD=involution(TSTD,inv); |
---|
816 | flag++; |
---|
817 | dbprint(ppl,"Finished one while cycle"); |
---|
818 | } |
---|
819 | |
---|
820 | if (flag mod 2 ==0){ STD = involution(STD,inv);} else { STD = transpose(STD); } |
---|
821 | |
---|
822 | list REVERSE=TrafoL,STD,TrafoR; |
---|
823 | return(REVERSE); |
---|
824 | } |
---|
825 | |
---|
826 | static proc divideByContent(matrix M) |
---|
827 | { |
---|
828 | //find first entrie not equal to zero |
---|
829 | int i,k; |
---|
830 | k=1; |
---|
831 | vector CON; |
---|
832 | for(i=1;i<=ncols(M);i++) |
---|
833 | { |
---|
834 | if(leadcoef(M[i])!=0){CON=CON+leadcoef(M[i])*gen(k); k++;} |
---|
835 | } |
---|
836 | poly con=content(CON); |
---|
837 | matrix TL=1/con*freemodule(nrows(M)); |
---|
838 | return(TL); |
---|
839 | } |
---|
840 | |
---|
841 | |
---|
842 | /////interesting examples for smith//////////////// |
---|
843 | |
---|
844 | static proc Ex_One_wheeled_bicycle() |
---|
845 | { |
---|
846 | ring RA=(0,m), D, lp; |
---|
847 | matrix bicycle[2][3]=(1+m)*D^2, D^2, 1, D^2, D^2-1, 0; |
---|
848 | list s=smith(RA,bicycle, 1,0); |
---|
849 | print(s[2]); |
---|
850 | print(s[1]*bicycle*s[3]-s[2]); |
---|
851 | } |
---|
852 | |
---|
853 | |
---|
854 | static proc Ex_RLC-circuit() |
---|
855 | { |
---|
856 | ring RA=(0,m,R1,R2,L,C), D, lp; |
---|
857 | matrix circuit[2][3]=D+1/(R1*C), 0, -1/(R1*C), 0, D+R2/L, -1/L; |
---|
858 | list s=smith(RA,circuit, 1,0); |
---|
859 | print(s[2]); |
---|
860 | print(s[1]*circuit*s[3]-s[2]); |
---|
861 | } |
---|
862 | |
---|
863 | |
---|
864 | static proc Ex_two_pendula() |
---|
865 | { |
---|
866 | ring RA=(0,m,M,L1,L2,m1,m2,g), D, lp; |
---|
867 | |
---|
868 | matrix pendula[3][4]=m1*L1*D^2,m2*L2*D^2,(M+m1+m2)*D^2,-1,m1*L1^2*D^2-m1*L1*g,0,m1*L1*D^2,0,0, |
---|
869 | m2*L2^2*D^2-m2*L2*g,m2*L2*D^2,0; |
---|
870 | list s=smith(RA,pendula, 1,0); |
---|
871 | print(s[2]); |
---|
872 | print(s[1]*pendula*s[3]-s[2]); |
---|
873 | } |
---|
874 | |
---|
875 | |
---|
876 | |
---|
877 | static proc Ex_linerized_satellite_in_a_circular_equatorial_orbit() |
---|
878 | { |
---|
879 | ring RA=(0,m,omega,r,a,b), D, lp; |
---|
880 | |
---|
881 | matrix satellite[4][6]= |
---|
882 | D,-1,0,0,0,0, |
---|
883 | -3*omega^2,D,0,-2*omega*r,-a/m,0, |
---|
884 | 0,0,D,-1,0,0, |
---|
885 | 0,2*omega/r,0,D,0,-b/(m*r); |
---|
886 | |
---|
887 | list s=smith(RA,satellite, 1,0); |
---|
888 | print(s[2]); |
---|
889 | print(s[1]*satellite*s[3]-s[2]); |
---|
890 | } |
---|
891 | |
---|
892 | static proc Ex_flexible_one_link_robot() |
---|
893 | { |
---|
894 | ring RA=(0,M11,M12,M13,M21,M22,M31,M33,K1,K2), D, lp; |
---|
895 | |
---|
896 | matrix robot[3][4]=M11*D^2,M12*D^2,M13*D^2,-1,M21*D^2,M22*D^2+K1,0,0,M31*D^2,0,M33*D^2+K2,0; |
---|
897 | list s=smith(RA,robot, 1,0); |
---|
898 | print(s[2]); |
---|
899 | print(s[1]*robot*s[3]-s[2]); |
---|
900 | } |
---|
901 | |
---|
902 | |
---|
903 | |
---|
904 | /////interesting examples for jacobson//////////////// |
---|
905 | |
---|
906 | static proc Ex_compare_output_with_maple_package_JanetOre() |
---|
907 | { ring w = 0,(x,d),Dp; |
---|
908 | def W=nc_algebra(1,1); |
---|
909 | setring W; |
---|
910 | matrix m[3][3]=[d2,d+1,0],[d+1,0,d3-x2*d],[2d+1, d3+d2, d2]; |
---|
911 | list J=jacobson(W,m,0); |
---|
912 | print(J[1]*m*J[3]); |
---|
913 | print(J[2]); |
---|
914 | print(J[1]); |
---|
915 | print(J[3]); |
---|
916 | print(J[1]*m*J[3]-J[2]); |
---|
917 | } |
---|
918 | |
---|
919 | |
---|
920 | static proc Ex_cyclic() |
---|
921 | { ring w = 0,(x,d),Dp; |
---|
922 | def W=nc_algebra(1,1); |
---|
923 | setring W; |
---|
924 | matrix m[3][3]=d,0,0,x*d+1,d,0,0,x*d,d; |
---|
925 | list J=jacobson(W,m,0); |
---|
926 | print(J[1]*m*J[3]); |
---|
927 | print(J[2]); |
---|
928 | print(J[1]); |
---|
929 | print(J[3]); |
---|
930 | print(J[1]*m*J[3]-J[2]); |
---|
931 | } |
---|
932 | |
---|