source: git/Singular/LIB/control.lib @ 0dd77c2

fieker-DuValspielwiese
Last change on this file since 0dd77c2 was 0610f0e, checked in by Hans Schoenemann <hannes@…>, 14 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@12790 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 43.5 KB
Line 
1version="$Id$";
2category="System and Control Theory";
3info="
4LIBRARY:  control.lib     Algebraic analysis tools for System and Control Theory
5
6AUTHORS:  Oleksandr Iena,       yena@mathematik.uni-kl.de
7@*        Markus Becker,        mbecker@mathematik.uni-kl.de
8@*        Viktor Levandovskyy,  levandov@mathematik.uni-kl.de
9
10SUPPORT: Forschungsschwerpunkt 'Mathematik und Praxis' (Project of Dr. E. Zerz
11and V. Levandovskyy), University of Kaiserslautern
12
13MAIN PROCEDURES:
14  control(R);     analysis of controllability-related properties of R (using Ext modules)
15  controlDim(R);  analysis of controllability-related properties of R (using dimension)
16  autonom(R);     analysis of autonomy-related properties of R (using Ext modules)
17  autonomDim(R);  analysis of autonomy-related properties of R (using dimension)
18
19COMPONENT PROCEDURES:
20  leftKernel(R);       a left kernel of R
21  rightKernel(R);      a right kernel of R
22  leftInverse(R);      a left inverse of R
23  rightInverse(R);     a right inverse of R
24  colrank(M);          a column rank of M as of matrix
25  genericity(M);       analysis of the genericity of parameters
26  canonize(L);         Groebnerification for modules in the output of control or autonomy procs
27  iostruct(R);         computes an IO-structure of behavior given by a module R
28  findTorsion(R, I);   generators of the submodule of a module R, annihilated by the ideal I
29
30AUXILIARY PROCEDURES:
31  controlExample(s);   set up an example from the mini database inside of the library
32  view();              well-formatted output of lists, modules and matrices
33";
34
35LIB "homolog.lib";
36LIB "poly.lib";
37LIB "primdec.lib";
38LIB "matrix.lib";
39
40//---------------------------------------------------------------
41static proc Opt_Our()
42"USAGE: Opt_Our();
43RETURN: intvec, where previous options are stored
44PURPOSE: save previous options and set customized options
45"
46{
47  intvec v;
48  v=option(get);
49  option(redSB);
50  option(redTail);
51  return (v);
52}
53
54//-------------------------------------------------------------------------
55
56static proc space(int n)
57"USAGE:spase(n); n is an integer (number of needed spaces)
58RETURN:  string consisting of n spaces
59NOTE:  the procedure is used in the procedure 'view' to have a better formatted output
60"{
61  int i;
62  string s="";
63  for(i=1;i<=n;i++)
64  {
65    s=s+" ";
66  };
67  return(s);
68};
69//-----------------------------------------------------------------------------
70proc view(M)
71"USAGE:  view(M);   M is of any type
72RETURN:  no return value
73PURPOSE:  procedure for (well-) formatted output of modules, matrices, lists of modules, matrices; shows everything even if entries are long
74NOTE:  in case of other types( not 'module', 'matrix', 'list') works just as standard 'print' procedure
75EXAMPLE:  example view; shows an example
76"{
77  // to be replaced with something more feasible
78  if ( (typeof(M)=="module")||(typeof(M)=="matrix") )
79  {
80  int @R=nrows(M);
81  int @C=ncols(M);
82  int i;
83  int j;
84  list MaxLength=list();
85  int Size=0;
86  int max;
87  string s;
88
89  for(i=1;i<=@C;i++)
90  {
91    max=0;
92
93    for(j=1;j<=@R;j++)
94    {
95      Size=size( string( M[j,i] ) );
96      if( Size>max )
97      {
98        max=Size;
99      };
100    };
101    MaxLength[i] = max;
102  };
103
104  for(i=1;i<=@R;i++)
105  {
106    s="";
107    for(j=1;j<@C;j++)
108    {
109      s=s+string(M[i,j])+space( MaxLength[j]-size( string( M[i,j] ) ) ) +",";
110    };
111
112    s=s+string(M[i,j])+space( MaxLength[j]-size( string( M[i,j] ) ) );
113
114    if (i!=@R)
115    {
116      s=s+",";
117    };
118    print(s);
119  };
120
121  return();
122  };
123
124  if(typeof(M)=="list")
125  {
126    int sz=size(M);
127    int i;
128    for(i=1;i<=sz;i++)
129    {
130      view(M[i]);
131      print("");
132    };
133
134    return();
135  };
136  print(M);
137  return();
138}
139example
140{"EXAMPLE:";echo = 2;
141  ring r;
142  list L;
143  matrix M[1][3] = x2+x,y3-y,z5-4z+7;
144  L[1] = "a matrix:";
145  L[2] = M;
146  L[3] = "an ideal:";
147  L[4] = ideal(M);
148  view(L);
149};
150//--------------------------------------------------------------------------
151proc rightKernel(matrix M)
152"USAGE:  rightKernel(M);   M a matrix
153RETURN:  module
154PURPOSE: computes the right kernel of matrix M (a module of all elements v such that Mv=0)
155EXAMPLE: example rightKernel; shows an example
156"{
157  return(modulo(M,std(0)));
158}
159example
160{"EXAMPLE:";echo = 2;
161  ring r = 0,(x,y,z),dp;
162  matrix M[1][3] = x,y,z;
163  print(M);
164  matrix R = rightKernel(M);
165  print(R);
166  // check:
167  print(M*R);
168};
169//-------------------------------------------------------------------------
170proc leftKernel(matrix M)
171"USAGE:  leftKernel(M);   M a matrix
172RETURN:  module
173PURPOSE: computes left kernel of matrix M (a module of all elements v such that vM=0)
174EXAMPLE:  example leftKernel; shows an example
175"
176{
177  return( transpose( modulo( transpose(M),std(0) ) ) );
178}
179example
180{"EXAMPLE:";echo = 2;
181  ring r= 0,(x,y,z),dp;
182  matrix M[3][1] = x,y,z;
183  print(M);
184  matrix L = leftKernel(M);
185  print(L);
186  // check:
187  print(L*M);
188};
189//------------------------------------------------------------------------
190proc leftInverse(module M)
191"USAGE:  leftInverse(M);  M a module
192RETURN:  module
193PURPOSE: computes such a matrix L, that LM = Id;
194EXAMPLE: example leftInverse; shows an example
195NOTE: exists only in the case when M is free submodule
196"
197{
198  // it works also for the NC case;
199  int NCols = ncols(M);
200  module Id = freemodule(NCols);
201  module N  = transpose(M);
202  intvec old_opt=Opt_Our();
203  Id = std(Id);
204  matrix T;
205  // check the correctness (Id \subseteq M)
206  // via dimension: dim (M) = -1!
207  int d = dim_Our(N);
208  if (d != -1)
209  {
210    // No left inverse exists
211    return(matrix(0));
212  }
213  matrix T2 = lift(N, Id);
214  T2 =  transpose(T2);
215  option(set,old_opt);  // set the options back
216  return(T2);
217}
218example
219{
220  "EXAMPLE:";echo =2;
221  // a trivial example:
222  ring r = 0,(x,z),dp;
223  matrix M[2][1] = 1,x2z;
224  print(M);
225  print( leftInverse(M) );
226  kill r;
227  // derived from the example TwoPendula:
228  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
229  matrix U[3][1];
230  U[1,1]=(-L2)*Dt^4+(g)*Dt^2;
231  U[2,1]=(-L1)*Dt^4+(g)*Dt^2;
232  U[3,1]=(L1*L2)*Dt^4+(-g*L1-g*L2)*Dt^2+(g^2);
233  module M = module(U);
234  module L = leftInverse(M);
235  print(L);
236  // check
237  print(L*M);
238};
239//-----------------------------------------------------------------------
240proc rightInverse(module R)
241"USAGE:  rightInverse(M);  M a module
242RETURN:  module
243PURPOSE: computes such a matrix L, that ML = Id
244EXAMPLE: example rightInverse; shows an example
245NOTE: exists only in the case when M is free submodule
246"
247{
248  // for comm case it suffices
249  if (isCommutative())
250  {
251    return(transpose(leftInverse(transpose(R))));
252  }
253  // for noncomm
254  def save = basering; def sop = opposite(save);
255  setring sop; module Mop = oppose(save,R);
256  Mop = transpose(Mop);
257  module L = leftInverse(Mop);
258  setring save; module L = oppose(sop,L);
259  L = transpose(L);
260  return(matrix(L));
261}
262example
263{ "EXAMPLE:";echo =2;
264  // a trivial example:
265  ring r = 0,(x,z),dp;
266  matrix M[1][2] = 1,x2+z;
267  print(M);
268  print( rightInverse(M) );
269  kill r;
270  // derived from the TwoPendula example:
271  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
272  matrix U[1][3];
273  U[1,1]=(-L2)*Dt^4+(g)*Dt^2;
274  U[1,2]=(-L1)*Dt^4+(g)*Dt^2;
275  U[1,3]=(L1*L2)*Dt^4+(-g*L1-g*L2)*Dt^2+(g^2);
276  module M = module(U);
277  module L = rightInverse(M);
278  print(L);
279  // check
280  print(M*L);
281};
282//-----------------------------------------------------------------------
283static proc dim_Our(module R)
284{
285  int d;
286  if (attrib(R,"isSB")<>1)
287  {
288    R = std(R);
289  }
290  d = dim(R);
291  return(d);
292}
293//-----------------------------------------------------------------------
294static proc Ann_Our(module R)
295{
296  return(Ann(R));
297}
298//-----------------------------------------------------------------------
299static proc Ext_Our(int i, module R, list #)
300{
301  // mimicking 'Ext_R' from homolog.lib
302  int ExtraArg = ( size(#)>0 );
303  if (ExtraArg)
304  {
305    return( Ext_R(i,R,#[1]) );
306  }
307  else
308  {
309    return( Ext_R(i,R) );
310  }
311}
312//------------------------------------------------------------------------
313static proc is_zero_Our
314{
315  //just a copy of 'is_zero' from "poly.lib" patched with GKdim
316  int d = dim_Our(std(#[1]));
317  int a = ( d==-1 );
318  if( size(#) >1 ) { list L=a,d; return(L); }
319  return(a);
320  //  return( is_zero(R) ) ;
321};
322//------------------------------------------------------------------------
323static proc control_output(int i, int NVars, module R, module Ext_1, list Gen)
324"USAGE:  control_output(i, NVars, R, Ext_1),
325PURPOSE: where
326@*         i is integer (number of first nonzero Ext or a number of variables in a basering + 1 in case that all the Exts are zero),
327@*           NVars:  integer, number of variables in a base ring,
328@*           R:  module R (cokernel representation),
329@*           Ext_1:  module, the first Ext(its cokernel representation)
330RETURN:  list with all the contollability properties of the system which is to be returned in 'control' procedure
331NOTE:  this procedure is used in 'control' procedure
332"{
333  // TODO: NVars to be replaced with the global hom. dimension of basering!!!
334  // Is not clear what to do with gl.dim of qrings
335  string DofS = "dimension of the system:";
336  string Fn   = "number of first nonzero Ext:";
337  string Gen_mes = "Parameter constellations which might lead to a non-controllable system:";
338
339  module RK = rightKernel(R);
340  int d=dim_Our(std(transpose(R)));
341
342  if (i==1)
343  {
344    return(
345            list ( Fn,
346                   i,
347                  "not controllable , image representation for controllable part:",
348                    RK,
349                  "kernel representation for controllable part:",
350                   leftKernel( RK ),
351                  "obstruction to controllability",
352                   Ext_1,
353                  "annihilator of torsion module (of obstruction to controllability)",
354                   Ann_Our(Ext_1),
355                   DofS,
356                   d
357                 )
358          );
359  };
360
361  if(i>NVars)
362  {
363    return( list(  Fn,
364                   -1,
365                  "strongly controllable(flat), image representation:",
366                   RK,
367                  "left inverse to image representation:",
368                   leftInverse(RK),
369                   DofS,
370                   d,
371                   Gen_mes,
372                   Gen)
373          );
374  };
375
376  //
377  //now i<=NVars
378  //
379
380  if( (i==2) )
381  {
382    return( list( Fn,
383                  i,
384                 "controllable, not reflexive, image representation:",
385                  RK,
386                  DofS,
387                  d,
388                  Gen_mes,
389                  Gen)
390          );
391  };
392
393  if( (i>=3) )
394  {
395    return( list ( Fn,
396                   i,
397                  "reflexive, not strongly controllable, image representation:",
398                   RK,
399                   DofS,
400                   d,
401                      Gen_mes,
402                   Gen)
403          );
404  };
405};
406//-------------------------------------------------------------------------
407
408proc control(module R)
409"USAGE:  control(R);  R a module (R is the matrix of the system of equations to be investigated)
410RETURN:  list
411PURPOSE: compute the list of all the properties concerning controllability of the system (behavior), represented by the matrix R
412NOTE: the properties and corresponding data like controllability, flatness, dimension of the system, degree of controllability, kernel and image representations, genericity of parameters, obstructions to controllability, annihilator of torsion submodule and left inverse are investigated
413EXAMPLE:  example control; shows an example
414"
415{
416  int i;
417  int NVars=nvars(basering);
418  // TODO: NVars to be replaced with the global hom. dimension of basering!!!
419  int ExtIsZero;
420  intvec v=Opt_Our();
421  module R_std=std(R);
422  module Ext_1 = std(Ext_Our(1,R_std));
423
424  ExtIsZero=is_zero_Our(Ext_1);
425  i=1;
426  while( (ExtIsZero) && (i<=NVars) )
427  {
428    i++;
429    ExtIsZero = is_zero_Our( Ext_Our(i,R_std) );
430  };
431  matrix T=lift(R,R_std);
432  list l=genericity(T);
433  option(set,v);
434
435  return( control_output( i, NVars, R, Ext_1, l ) );
436}
437example
438{"EXAMPLE:";echo = 2;
439  // a WindTunnel example
440  ring A = (0,a, omega, zeta, k),(D1, delta),dp;
441  module R;
442  R = [D1+a, -k*a*delta, 0, 0],
443      [0, D1, -1, 0],
444      [0, omega^2, D1+2*zeta*omega, -omega^2];
445  R=transpose(R);
446  view(R);
447  view(control(R));
448};
449//--------------------------------------------------------------------------
450proc controlDim(module R)
451"USAGE:  controlDim(R); R a module (R is the matrix of the system of equations to be investigated)
452RETURN: list
453PURPOSE: computes list of all the properties concerning controllability of the system (behavior), represented by the  matrix R
454EXAMPLE:  example controlDim; shows an example
455NOTE: the properties and corresponding data like controllability, flatness, dimension of the system, degree of controllability, kernel and image representations, genericity of parameters, obstructions to controllability, annihilator of torsion submodule and left inverse are investigated.
456@* This procedure is analogous to 'control' but uses dimension calculations.
457@* The implemented approach works for full row rank matrices only (the check is done automatically).
458"
459{
460  if( nrows(R) != colrank(transpose(R)) )
461  {
462    return ("controlDim cannot be applied, since R does not have full row rank");
463  }
464  intvec     v = Opt_Our();
465  module R_std = std(R);
466  int        d = dim_Our(R_std);
467  int    NVars = nvars(basering);
468  int        i = NVars-d;
469  module Ext_1 = std(Ext_Our(1,R_std));
470  matrix     T = lift(R,R_std);
471  list       l = genericity(T);
472  option(set, v);
473  return( control_output( i, NVars, R, Ext_1, l));
474}
475example
476{"EXAMPLE:";echo = 2;
477  //a WindTunnel example
478  ring A = (0,a, omega, zeta, k),(D1, delta),dp;
479  module R;
480  R = [D1+a, -k*a*delta, 0, 0],
481      [0, D1, -1, 0],
482      [0, omega^2, D1+2*zeta*omega, -omega^2];
483  R=transpose(R);
484  view(R);
485  view(controlDim(R));
486};
487//------------------------------------------------------------------------
488proc colrank(module M)
489"USAGE: colrank(M); M a matrix/module
490RETURN: int
491PURPOSE: compute the column rank of M as of matrix
492NOTE: this procedure uses Bareiss algorithm
493"{
494  // NOte continued:
495  // which might not terminate in some cases
496  module M_red  = bareiss(M)[1];
497  int NCols_red = ncols(M_red);
498  return (NCols_red);
499}
500example
501{"EXAMPLE: ";echo = 2;
502  // de Rham complex
503  ring r=0,(D(1..3)),dp;
504  module R;
505  R=[0,-D(3),D(2)],
506    [D(3),0,-D(1)],
507    [-D(2),D(1),0];
508  R=transpose(R);
509  colrank(R);
510};
511
512//------------------------------------------------------------------------
513static proc autonom_output( int i, int NVars, module RC, int R_rank )
514"USAGE:  proc autonom_output(i, NVars, RC, R_rank)
515           i:  integer, number of first nonzero Ext or
516               just number of variables in a base ring + 1 in case that all the Exts are zero
517           NVars:  integer, number of variables in a base ring
518           RC: module, kernel-representation of controllable part of the system
519           R_rank: integer, column rank of the representation matrix
520PURPOSE: compute all the autonomy properties of the system which is to be returned in 'autonom' procedure
521RETURN:  list
522NOTE:  this procedure is used in 'autonom' procedure
523"
524{
525  int d=NVars-i;//that is the dimension of the system
526  string DofS="dimension of the system:";
527  string Fn = "number of first nonzero Ext:";
528  if(i==0)
529  {
530    return( list(  Fn,
531                   i,
532                  "not autonomous",
533                   "kernel representation for controllable part",
534                   RC,
535                   "column rank of the matrix",
536                   R_rank,
537                   DofS,
538                   d )
539          );
540  };
541
542  if( i>NVars )
543  {
544    return( list( Fn,
545                  -1,
546                  "trivial",
547                  DofS,
548                  d )
549          );
550  };
551
552  //
553  //now i<=NVars
554  //
555
556
557  if( i==1 )
558  // in case that NVars==1 there is no sense to consider the notion
559  // of strongly autonomous behavior, because it does not imply
560  // that system is overdetermined in this case
561  {
562    return( list ( Fn,
563                   i,
564                  "autonomous, not overdetermined",
565                   DofS,
566                   d )
567          );
568  };
569
570  if( i==NVars )
571  {
572    return( list(  Fn,
573                   i,
574                  "strongly autonomous(fin. dimensional),in particular overdetermined",
575                   DofS,
576                   d)
577          );
578  };
579
580  if( i<NVars )
581  {
582    return( list ( Fn,
583                   i,
584                  "overdetermined, not strongly autonomous",
585                   DofS,
586                   d)
587          );
588  };
589};
590//--------------------------------------------------------------------------
591proc autonomDim(module R)
592"USAGE:  autonomDim(R);   R a module (R is a matrix of the system of equations which is to be investigated)
593RETURN: list
594PURPOSE: computes the list of all the properties concerning autonomy of the system (behavior), represented by the matrix R
595NOTE: the properties and corresponding data like autonomy resp. strong autonomy, dimension of the system, autonomy degree, kernel representation and (over)determinacy are investigated.
596@* This procedure is analogous to 'autonom' but uses dimension calculations
597EXAMPLE:  example autonomDim; shows an example
598"
599{
600  int d;
601  int NVars  = nvars(basering);
602  module RT  = transpose(R);
603  module RC;  //for computation of controllable part if if exists
604  int R_rank = ncols(R);
605  d          = dim_Our( std(RT) );  //this is the dimension of the system
606  int      i = NVars-d;  //First non-zero Ext
607  if( d==0 )
608    {
609      RC = leftKernel(rightKernel(R));
610      R_rank=colrank(R);
611    }
612  return( autonom_output(i,NVars,RC,R_rank) );
613}
614example
615{"EXAMPLE:"; echo = 2;
616  // Cauchy1 example
617  ring r=0,(s1,s2,s3,s4),dp;
618  module R= [s1,-s2],
619            [s2, s1],
620            [s3,-s4],
621            [s4, s3];
622  R=transpose(R);
623  view( R );
624  view( autonomDim(R) );
625};
626//----------------------------------------------------------
627proc autonom(module R)
628"USAGE:  autonom(R);   R a module (R is a matrix of the system of equations which is to be investigated)
629RETURN:  list
630PURPOSE: find all the properties concerning autonomy of the system (behavior) represented by the  matrix R
631NOTE: the properties and corresponding data like autonomy resp. strong autonomy, dimension of the system, autonomy degree, kernel representation and (over)determinacy are investigated
632EXAMPLE: example autonom; shows an example
633"
634{
635  int NVars=nvars(basering);
636  int ExtIsZero;
637  module RT=transpose(R);
638  module RC;
639  int R_rank=ncols(R);
640  ExtIsZero=is_zero_Our(Ext_Our(0,RT));
641  int i=0;
642  while( (ExtIsZero)&&(i<=NVars) )
643  {
644    i++;
645    ExtIsZero = is_zero_Our(Ext_Our(i,RT));
646  };
647  if (i==0)
648  {
649    RC = leftKernel(rightKernel(R));
650    R_rank=colrank(R);
651  }
652  return(autonom_output(i,NVars,RC,R_rank));
653}
654example
655{"EXAMPLE:"; echo = 2;
656  // Cauchy
657  ring r=0,(s1,s2,s3,s4),dp;
658  module R= [s1,-s2],
659            [s2, s1],
660            [s3,-s4],
661            [s4, s3];
662  R=transpose(R);
663  view( R );
664  view( autonom(R) );
665};
666
667
668//----------------------------------------------------------
669proc genericity(matrix M)
670"USAGE:  genericity(M); M is a matrix/module
671RETURN:  list (of strings)
672PURPOSE: determine parametric expressions which have been assumed to be non-zero in the process of computing the Groebner basis
673NOTE: the output list consists of strings. The first string contains the variables only, whereas each further string contains
674      a single polynomial in parameters.
675@* We strongly recommend to switch on the redSB and redTail options.
676@* The procedure is effective with the lift procedure for modules with parameters
677EXAMPLE:  example genericity; shows an example
678"
679{
680  // returns "-", if there are no parameters!
681  if (npars(basering)==0)
682  {
683    return("-");
684  }
685  list RT = evas_genericity(M); // list of strings
686  if ((size(RT)==1) && (RT[1] == ""))
687  {
688    return("-");
689  }
690  return(RT);
691}
692example
693{  // TwoPendula
694  "EXAMPLE:"; echo = 2;
695  ring r=(0,m1,m2,M,g,L1,L2),Dt,dp;
696  module RR =
697    [m1*L1*Dt^2, m2*L2*Dt^2, -1, (M+m1+m2)*Dt^2],
698    [m1*L1^2*Dt^2-m1*L1*g, 0, 0, m1*L1*Dt^2],
699    [0, m2*L2^2*Dt^2-m2*L2*g, 0, m2*L2*Dt^2];
700  module R = transpose(RR);
701  module SR = std(R);
702  matrix T = lift(R,SR);
703  genericity(T);
704  //-- The result might be different when computing reduced bases:
705  matrix T2;
706  option(redSB);
707  option(redTail);
708  module SR2 = std(R);
709  T2 =  lift(R,SR2);
710  genericity(T2);
711}
712//---------------------------------------------------------------
713static proc victors_genericity(matrix M)
714{
715  // returns "-", if there are no parameters!
716  if (npars(basering)==0)
717  {
718    return("-");
719  }
720  int plevel = printlevel-voice+2;
721  // M is a matrix over a ring with params and vars;
722  ideal I = ideal(M); // a list of entries
723  I = simplify(I,2); // delete 0's
724  // decompose every coeff in every poly
725  int i;
726  int s = size(I);
727  ideal NM;
728  poly p;
729  number num;
730  int  cl=1;
731  intvec ZeroVec; ZeroVec[nvars(basering)] = 0;
732  intvec W;
733  ideal Numero, Denomiro;
734  int cNu=0; int cDe=0;
735  for (i=1; i<=s; i++)
736  {
737    // remove contents and add them as polys
738    p   = I[i];
739    W   = leadexp(p);
740    if (W == ZeroVec) // i.e. just a coef
741    {
742      num    = denominator(leadcoef(p)); // from poly.lib
743      NM[cl] = numerator(leadcoef(p));
744      dbprint(p,"numerator:");
745      dbprint(p, string(NM[cl]));
746      cNu++; Numero[cNu]= NM[cl];
747      cl++;
748      NM[cl] = num; // denominator
749      dbprint(p,"denominator:");
750      dbprint(p, string(NM[cl]));
751      cDe++; Denomiro[cDe]= NM[cl];
752      cl++;
753      p = p - lead(p); // for the next cycle
754    }
755    if ( p!= 0)
756    {
757      num = content(p);
758      p   = p/num;
759      NM[cl] = denominator(num);
760      dbprint(p,"content denominator:");
761      dbprint(p, string(NM[cl]));
762      cNu++; Numero[cNu]= NM[cl];
763      cl++;
764      NM[cl] = numerator(num);
765      dbprint(p,"content numerator:");
766      dbprint(p, string(NM[cl]));
767      cDe++; Denomiro[cDe]= NM[cl];
768      cl++;
769    }
770    // it seems that the next elements will not have real influence
771    while( p != 0)
772    {
773      NM[cl] = leadcoef(p); // should be all integer, i.e. non-rational
774      dbprint(p,"coef:");
775      dbprint(p, string(NM[cl]));
776      cl++;
777      p = p - lead(p);
778    }
779  }
780  NM = simplify(NM,4); // delete identical
781  string newvars = parstr(basering);
782  def save = basering;
783  string NewRing = "ring @NR =" +string(char(basering))+",("+newvars+"),Dp;";
784  execute(NewRing);
785  // get params as variables
786  // create a list of non-monomials
787  ideal @L;
788  ideal F;
789  ideal NM = imap(save,NM);
790  NM = simplify(NM,8); //delete multiples
791  poly p,q;
792  cl = 1;
793  int j, cf;
794  for(i=1; i<=size(NM);i++)
795  {
796    p = NM[i] - lead(NM[i]);
797    if (p!=0)
798    {
799      //      L[cl] = p;
800      F  = factorize(NM[i],1); //non-constant factors only
801      cf = 1;
802      // factorize every polynomial
803      // throw away every monomial from factorization (also constants from above ring)
804      for (j=1; j<=size(F);j++)
805      {
806        q = F[j]-lead(F[j]);
807        if (q!=0)
808        {
809          @L[cl] = F[j];
810          cl++;
811        }
812      }
813    }
814  }
815  // return the result [in string-format]
816  @L = simplify(@L,2+4+8); // skip zeroes, doubled and entries, diff. by a constant
817  list SL;
818  for (j=1; j<=size(@L);j++)
819  {
820    SL[j] = string(@L[j]);
821  }
822  setring save;
823  return(SL);
824}
825//---------------------------------------------------------------
826static proc evas_genericity(matrix M)
827{
828  // called from the main genericity proc
829  ideal I = ideal(M);
830  I = simplify(I,2+4);
831  int s = ncols(I);
832  ideal Den;
833  poly p;
834  int i;
835  for (i=1; i<=s; i++)
836  {
837    p = I[i];
838    while (p !=0)
839    {
840      Den = Den, denominator(leadcoef(p));
841      p   = p-lead(p);
842    }
843  }
844  Den = simplify(Den,2+4);
845  string newvars = parstr(basering);
846  def save = basering;
847  string NewRing = "ring @NR =(" +string(char(basering))+"),("+newvars+"),Dp;";
848  execute(NewRing);
849  ideal F;
850  ideal Den = imap(save,Den);
851  Den = simplify(Den,2);
852  int s1 = ncols(Den);
853  for (i=1; i<=s1; i++)
854  {
855    Den[i] = normalize(Den[i]);
856    if ( Den[i] !=1)
857    {
858      F= F, factorize(Den[i],1);
859    }
860  }
861  F = simplify(F, 2+4+8);
862  ideal @L = F;
863  @L = simplify(@L,2);
864  list SL;
865  int c,j;
866  string Mono;
867  c = 1;
868  for (j=1; j<= ncols(@L);j++)
869  {
870    if (leadcoef(@L[j]) <0)
871    {
872      @L[j] = -1*@L[j];
873    }
874    if (((@L[j] - lead(@L[j]))==0 ) && (@L[j]!=0) ) //@L[j] is a monomial
875    {
876      Mono = Mono + string(@L[j])+ ","; // concatenation
877    }
878    else
879    {
880      c++;
881      SL[c] = string(@L[j]);
882    }
883  }
884  if (Mono!="")
885  {
886    Mono = Mono[1..size(Mono)-1]; // delete the last colon
887  }
888  SL[1] = Mono;
889  setring save;
890  return(SL);
891}
892
893//---------------------------------------------------------------
894proc canonize(list L)
895"USAGE:  canonize(L); L a list
896RETURN:  list
897PURPOSE: modules in the list are canonized by computing their reduced minimal (= unique up to constant factor w.r.t. the given ordering) Groebner bases
898ASSUME:  L is the output of control/autonomy procedures
899EXAMPLE:  example canonize; shows an example
900"
901{
902  list M = L;
903  intvec v=Opt_Our();
904  int s = size(L);
905  int i;
906  for (i=2; i<=s; i=i+2)
907  {
908    if (typeof(M[i])=="module")
909    {
910      M[i] = std(M[i]);
911      //      M[i] = prune(M[i]); // mimimal embedding: no need yet
912      //      M[i] = std(M[i]);
913    }
914  }
915  option(set, v); //set old values back
916  return(M);
917}
918example
919{  // TwoPendula with L1=L2=L
920  "EXAMPLE:"; echo = 2;
921  ring r=(0,m1,m2,M,g,L),Dt,dp;
922  module RR =
923    [m1*L*Dt^2, m2*L*Dt^2, -1, (M+m1+m2)*Dt^2],
924    [m1*L^2*Dt^2-m1*L*g, 0, 0, m1*L*Dt^2],
925    [0, m2*L^2*Dt^2-m2*L*g, 0, m2*L*Dt^2];
926  module R = transpose(RR);
927  list C = control(R);
928  list CC = canonize(C);
929  view(CC);
930}
931
932//----------------------------------------------------------------
933
934static proc elementof (int i, intvec v)
935{
936  int b=0;
937  for(int j=1;j<=nrows(v);j++)
938    {
939      if(v[j]==i)
940        {
941          b=1;
942          return (b);
943        }
944    }
945  return (b);
946}
947//-----------------------------------------------------------------
948proc iostruct(module R)
949"USAGE: iostruct( R ); R a module
950RETURN:  list L with entries: string s, intvec v, module P and module Q
951PURPOSE:  if R is the kernel-representation-matrix of some system, then we output a input-ouput representation Py=Qu of the system, the components that have been chosen as outputs(intvec v) and a comment s
952NOTE:  the procedure uses Bareiss algorithm
953EXAMPLE:  example iostruct; shows an example
954"
955{
956  // NOTE cont'd
957  //which might not terminate in some cases
958  list L = bareiss(R);
959  int R_rank = ncols(L[1]);
960  int NCols=ncols(R);
961  intvec v=L[2];
962  int temp;
963  int NRows=nrows(v);
964  int i,j;
965  int b=1;
966  module P;
967  module Q;
968  int n=0;
969
970  while(b==1)               //sort v through bubblesort
971    {
972      b=0;
973      for(i=1;i<NRows;i++)
974        {
975          if(v[i]>v[i+1])
976          {
977            temp=v[i];
978            v[i]=v[i+1];
979            v[i+1]=temp;
980            b=1;
981          }
982        }
983    }
984  P=R[v];                     //generate P
985  for(i=1;i<=NCols;i++)       //generate Q
986    {
987      if(elementof(i,v)==1)
988        {
989          i++;
990          continue;
991        }
992      Q=Q,R[i];
993    }
994  Q=simplify(Q,2);
995  string s="The following components have been chosen as outputs: ";
996  return (list(s,v,P,Q));
997}
998example
999{"EXAMPLE:";echo = 2;
1000 //Example Antenna
1001 ring r = (0, K1, K2, Te, Kp, Kc),(Dt, delta), (c,dp);
1002 module RR;
1003 RR =
1004   [Dt, -K1, 0, 0, 0, 0, 0, 0, 0],
1005   [0, Dt+K2/Te, 0, 0, 0, 0, -Kp/Te*delta, -Kc/Te*delta, -Kc/Te*delta],
1006   [0, 0, Dt, -K1, 0, 0, 0, 0, 0],
1007   [0, 0, 0, Dt+K2/Te, 0, 0, -Kc/Te*delta, -Kp/Te*delta, -Kc/Te*delta],
1008   [0, 0, 0, 0, Dt, -K1, 0, 0, 0],
1009   [0, 0, 0, 0, 0, Dt+K2/Te, -Kc/Te*delta, -Kc/Te*delta, -Kp/Te*delta];
1010 module R = transpose(RR);
1011 view(iostruct(R));
1012};
1013
1014//---------------------------------------------------------------
1015static proc smdeg(matrix N)
1016"USAGE: smdeg( N ); N a matrix
1017RETURN:  intvec
1018PURPOSE: returns an intvec of length 2 with the index of an element of N with smallest degree
1019"
1020{
1021  int n = nrows(N);
1022  int m = ncols(N);
1023  int d,d_temp;
1024  intvec v;
1025  int i,j;            // counter
1026
1027  if (N==0)
1028  {
1029    v = 1,1;
1030    return(v);
1031  }
1032
1033  for (i=1; i<=n; i++)
1034// hier wird ein Element ausgewaehlt(!=0) und mit dessen Grad gestartet
1035  {
1036    for (j=1; j<=m; j++)
1037    {
1038      if( deg(N[i,j])!=-1 )
1039      {
1040        d=deg(N[i,j]);
1041        break;
1042      }
1043    }
1044    if (d != -1)
1045    {
1046      break;
1047    }
1048  }
1049  for(i=1; i<=n; i++)
1050  {
1051    for(j=1; j<=m; j++)
1052    {
1053      d_temp = deg(N[i,j]);
1054      if ( (d_temp < d) && (N[i,j]!=0) )
1055      {
1056        d=d_temp;
1057      }
1058    }
1059  }
1060  for (i=1; i<=n; i++)
1061  {
1062    for (j=1; j<=m;j++)
1063    {
1064      if ( (deg(N[i,j]) == d) && (N[i,j]!=0) )
1065      {
1066        v = i,j;
1067        return(v);
1068      }
1069    }
1070  }
1071}
1072//---------------------------------------------------------------
1073static proc NoNon0Pol(vector v)
1074"USAGE: NoNon0Pol(v), v a vector
1075RETURN:  int
1076PURPOSE: returns 1, if there is only one non-zero element in v and 0 else
1077"{
1078  int i,j;
1079  int n = nrows(v);
1080  for( j=1; j<=n; j++)
1081  {
1082    if (v[j] != 0)
1083    {
1084      i++;
1085    }
1086  }
1087  if ( i!=1 )
1088  {
1089    i=0;
1090  }
1091  return(i);
1092}
1093//---------------------------------------------------------------
1094static proc extgcd_Our(poly p, poly q)
1095{
1096  ideal J;   //for extgcd-computations
1097  matrix T; //----------"------------
1098  list L;
1099  // the extgcd-command has a bug in versions before 2-0-7
1100  if ( system("version")<=2006 )
1101  {
1102    J = p,q; // J = N[k-1,k-1],N[k,k]; //J is of type ideal
1103    L[1] = liftstd(J,T);  //T is of type matrix
1104    if(J[1]==p) //this is just for the case the SINGULAR swaps the
1105    //      two elements due to ordering
1106    {
1107      L[2] = T[1,1];
1108      L[3] = T[2,1];
1109    }
1110    else
1111    {
1112      L[2] = T[2,1];
1113      L[3] = T[1,1];
1114    }
1115  }
1116  else
1117  {
1118    L=extgcd(p,q);
1119    //    L=extgcd(N[k-1,k-1],N[k,k]);
1120    //one can use this line if extgcd-bug is fixed
1121  }
1122  return(L);
1123}
1124static proc normalize_Our(matrix N, matrix Q)
1125"USAGE: normalize_Our(N,Q), N, Q are two matrices
1126PURPOSE: normalizes N and divides the columns of Q through the leading coefficients of the columns of N
1127RETURN: normalized matrix N and altered Q(according to the scheme mentioned in purpose). If number of columns of N and Q do not coincide, N and Q are returned unchanged
1128NOTE: number of columns of N and Q must coincide.
1129"
1130{
1131  if(ncols(N) != ncols(Q))
1132    {
1133      return (N,Q);
1134    }
1135  module M = module(N);
1136  module S = module(Q);
1137  int NCols = ncols(N);
1138  number n;
1139  for(int i=1;i<=NCols;i++)
1140    {
1141      n = leadcoef(M[i]);
1142      if( n != 0 )
1143        {
1144          M[i]=M[i]/n;
1145          S[i]=S[i]/n;
1146        }
1147     }
1148   N = matrix(M);
1149   Q = matrix(S);
1150   return (N,Q);
1151}
1152
1153//---------------------------------------------------------------
1154proc oldsmith( module M )
1155"USAGE: oldsmith(M); M a module/matrix
1156PURPOSE: computes the Smith normal form of a matrix
1157RETURN: a list of length 4 with the following entries:
1158@*      [1]: the Smith normal form S of M,
1159@*      [2]: the rank of M,
1160@*      [3]: a unimodular matrix U,
1161@*      [4]: a unimodular matrix V,
1162such that U*M*V=S. An warning is returned when no Smith form exists.
1163NOTE: Older experimental implementation. The Smith form only exists over PIDs (principal ideal domains). Use global ordering for computations!
1164"
1165{
1166  if (nvars(basering)>1) //if more than one variable, return empty list
1167  {
1168    string s="The Smith-Form only exists for principal ideal domains";
1169    return (s);
1170  }
1171  matrix N = matrix(M);         //Typecasting
1172  int n = nrows(N);
1173  int m = ncols(N);
1174  matrix P = unitmat(n);       //left transformation matrix
1175  matrix Q = unitmat(m);       //right transformation matrix
1176  int k, i, j, deg_temp;
1177  poly tmp;
1178  vector v;
1179  list L;                      //for extgcd-computation
1180  intmat f[1][n];              //to save degrees
1181  matrix lambda[1][n];         //to save leadcoefficients
1182  intmat g[1][m];              //to save degrees
1183  matrix mu[1][m];             //to save leadcoefficients
1184  int ii;                       //counter
1185
1186  while ((k!=n) && (k!=m) )
1187  {
1188    k++;
1189    while ((k<=n) && (k<=m))  //outer while-loop for column-operations
1190    {
1191      while(k<=m )        //inner while-loop for row-operations
1192      {
1193        if( (n>m) && (k < n) && (k<m))
1194        {
1195          if( simplify((ideal(submat(N,k+1..n,k+1..m))),2)== 0)
1196          {
1197            return(N,k-1,P,Q);
1198          }
1199        }
1200        i,j = smdeg(submat(N,k..n,k..m)); //choose smallest degree in the remaining submatrix
1201        i=i+(k-1);                        //indices adjusted to the whole matrix
1202        j=j+(k-1);
1203        if(i!=k)                    //take the element with smallest degree in the first position
1204        {
1205          N=permrow(N,i,k);
1206          P=permrow(P,i,k);
1207        }
1208        if(j!=k)
1209        {
1210          N=permcol(N,j,k);
1211          Q=permcol(Q,j,k);
1212        }
1213        if(NoNon0Pol(N[k])==1)
1214        {
1215          break;
1216        }
1217        tmp=leadcoef(N[k,k]);
1218        deg_temp=ord(N[k,k]);             //ord outputs the leading degree of N[k,k]
1219        for(ii=k+1;ii<=n;ii++)
1220        {
1221          lambda[1,ii]=leadcoef(N[ii,k])/tmp;
1222          f[1,ii]=deg(N[ii,k])-deg_temp;
1223        }
1224        for(ii=k+1;ii<=n;ii++)
1225        {
1226          N = addrow(N,k,-lambda[1,ii]*var(1)^f[1,ii],ii);
1227          P = addrow(P,k,-lambda[1,ii]*var(1)^f[1,ii],ii);
1228          N,Q=normalize_Our(N,Q);
1229        }
1230      }
1231      if (k>n)
1232      {
1233        break;
1234      }
1235      if(NoNon0Pol(transpose(N)[k])==1)
1236      {
1237        break;
1238      }
1239      tmp=leadcoef(N[k,k]);
1240      deg_temp=ord(N[k,k]); //ord outputs the leading degree of N[k][k]
1241
1242      for(ii=k+1;ii<=m;ii++)
1243      {
1244        mu[1,ii]=leadcoef(N[k,ii])/tmp;
1245        g[1,ii]=deg(N[k,ii])-deg_temp;
1246      }
1247      for(ii=k+1;ii<=m;ii++)
1248      {
1249        N=addcol(N,k,-mu[1,ii]*var(1)^g[1,ii],ii);
1250        Q=addcol(Q,k,-mu[1,ii]*var(1)^g[1,ii],ii);
1251        N,Q=normalize_Our(N,Q);
1252      }
1253    }
1254    if( (k!=1) && (k<n) && (k<m) )
1255    {
1256      L = extgcd_Our(N[k-1,k-1],N[k,k]);
1257      if ( N[k-1,k-1]!=L[1] )  //means that N[k-1,k-1] is not a divisor of N[k,k]
1258      {
1259        N=addrow(N,k-1,L[2],k);
1260        P=addrow(P,k-1,L[2],k);
1261        N,Q=normalize_Our(N,Q);
1262
1263        N=addcol(N,k,-L[3],k-1);
1264        Q=addcol(Q,k,-L[3],k-1);
1265        N,Q=normalize_Our(N,Q);
1266        k=k-2;
1267      }
1268    }
1269  }
1270  if( (k<=n) && (k<=m) )
1271  {
1272    if( N[k,k]==0)
1273    {
1274      return(N,k-1,P,Q);
1275    }
1276  }
1277  return(N,k,P,Q);
1278}
1279example
1280{
1281  "EXAMPLE:";echo = 2;
1282  option(redSB);
1283  option(redTail);
1284  ring r   = 0,x,dp;
1285  module M = [x2,x,3x3-4], [2x2-1,4x,5x2], [2x5,3x,4x];
1286  print(M);
1287  list P = oldsmith(M);
1288  print(P[1]);
1289  matrix N = matrix(M);
1290  matrix B = P[3]*N*P[4];
1291  print(B);
1292}
1293// see what happens when the matrix is already in Smith-Form
1294//  module M = [x,0,0],[0,x2,0],[0,0,x3];
1295//  list L = oldsmith(M);
1296// print(L[1]);
1297//matrix N=matrix(M);
1298//matrix B=L[3]*N*L[4];
1299//print(B);
1300//---------------------------------------------------------------
1301static proc list_tex(L, string name,link l,int nr_loop)
1302"USAGE: list_tex(L,name,l), where L is a list, name a string, l a link
1303         writes the content of list L in a tex-file 'name'
1304RETURN: nothing
1305"
1306{
1307  if(typeof(L)!="list")  //in case L is not a list
1308  {
1309    texobj(name,L);
1310  }
1311  if(size(L)==0)
1312  {
1313  }
1314  else
1315  {
1316    string t;
1317    for (int i=1;i<=size(L);i++)
1318    {
1319      while(1)
1320      {
1321        if(typeof(L[i])=="string")  //Fehler hier fuer normalen output->nur wenn string in liste dann verbatim
1322        {
1323          t=L[i];
1324          if(nr_loop==1)
1325          {
1326            write(l,"\\begin\{center\}");
1327            write(l,"\\begin\{verbatim\}");
1328          }
1329          write(l,t);
1330          if(nr_loop==0)
1331          {
1332            write(l,"\\par");
1333          }
1334          if(nr_loop==1)
1335          {
1336            write(l,"\\end\{verbatim\}");
1337            write(l,"\\end\{center\}");
1338          }
1339          break;
1340        }
1341        if(typeof(L[i])=="module")
1342        {
1343          texobj(name,matrix(L[i]));
1344          break;
1345        }
1346        if(typeof(L[i])=="list")
1347        {
1348          list_tex(L[i],name,l,1);
1349          break;
1350        }
1351        write(l,"\\begin\{center\}");
1352        texobj(name,L[i]);
1353        write(l,"\\end\{center\}");
1354        write(l,"\\par");
1355        break;
1356      }
1357    }
1358  }
1359}
1360example
1361{
1362  "EXAMPLE:";echo = 2;
1363}
1364//---------------------------------------------------------------
1365proc verbatim_tex(string s, link l)
1366"USAGE: verbatim_tex(s,l), where s is a string and l a link
1367PURPOSE: writes the content of s in verbatim-environment in the file
1368         specified by link
1369RETURN: nothing
1370"
1371{
1372  write(l,"\\begin{verbatim}");
1373  write(l,s);
1374  write(l,"\\end{verbatim}");
1375  write(l,"\\par");
1376}
1377example
1378{
1379  "EXAMPLE:";echo = 2;
1380}
1381//---------------------------------------------------------------
1382proc findTorsion(module R, ideal TAnn)
1383"USAGE:  findTorsion(R, I);   R an ideal/matrix/module, I an ideal
1384RETURN:  module
1385PURPOSE: computes the Groebner basis of the submodule of R, annihilated by I
1386NOTE: especially helpful, when I is the annihilator of the t(R) - the torsion submodule of R. In this case, the result is the explicit presentation of t(R) as
1387the submodule of R
1388EXAMPLE: example findTorsion; shows an example
1389"
1390{
1391  // motivation: let R be a module,
1392  // TAnn is the annihilator of t(R)\subset R
1393  // compute the generators of t(R) explicitly
1394  ideal AS = TAnn;
1395  module S = R;
1396  if (attrib(S,"isSB")<>1)
1397  {
1398    S = std(S);
1399  }
1400  if (attrib(AS,"isSB")<>1)
1401  {
1402    AS = std(AS);
1403  }
1404  int nc  = ncols(S);
1405  module To = quotient(S,AS);
1406  To = std(NF(To,S));
1407  return(To);
1408}
1409example
1410{
1411  "EXAMPLE:";echo = 2;
1412  // Flexible Rod
1413  ring A = 0,(D1, D2), (c,dp);
1414  module R= [D1, -D1*D2, -1], [2*D1*D2, -D1-D1*D2^2, 0];
1415  module RR = transpose(R);
1416  list L = control(RR);
1417  // here, we have the annihilator:
1418  ideal LAnn = D1; // = L[10]
1419  module Tr  = findTorsion(RR,LAnn);
1420  print(RR);  // the module itself
1421  print(Tr); // generators of the torsion submodule
1422}
1423
1424
1425proc controlExample(string s)
1426"USAGE:  controlExample(s);   s a string
1427RETURN:  ring
1428PURPOSE: set up an example from the mini database by initalizing a ring and a module in a ring
1429NOTE: in order to see the list of available examples, execute @code{controlExample(\"show\");}
1430@* To use an example, one has to do the following. Suppose one calls the ring, where the example will be activated, A. Then, by executing
1431@*  @code{def A = controlExample(\"Antenna\");} and @code{setring A;},
1432@* A will become a basering from the example \"Antenna\" with
1433the predefined system module R (transposed).
1434After that one can just execute @code{control(R);} respectively
1435@code{autonom(R);} to perform the control resp. autonomy analysis of R.
1436EXAMPLE: example controlExample; shows an example
1437"{
1438  list E, S, D; // E=official name, S=synonym, D=description
1439  E[1] = "Cauchy1";  S[1] = "cauchy1";  D[1] = "1-dimensional Cauchy equation";
1440  E[2] = "Cauchy2";  S[2] = "cauchy2";  D[2] = "2-dimensional Cauchy equation";
1441  E[3] = "Control1"; S[3] = "control1"; D[3] = "example of a simple noncontrollable system";
1442  E[4] = "Control2"; S[4] = "control2"; D[4] = "example of a simple controllable system";
1443  E[5] = "Antenna";  S[5] = "antenna";  D[5] = "antenna";
1444  E[6] = "Einstein"; S[6] = "einstein"; D[6] = "Einstein equations in vacuum";
1445  E[7] = "FlexibleRod"; S[7] = "flexible rod"; D[7] = "flexible rod";
1446  E[8] = "TwoPendula";  S[8] = "two pendula";  D[8] = "two pendula mounted on a cart";
1447  E[9] = "WindTunnel";  S[9] = "wind tunnel";D[9] = "wind tunnel";
1448  E[10] = "Zerz1";      S[10] = "zerz1"; D[10] = "example from the lecture of Eva Zerz";
1449  // all the examples so far
1450  int i;
1451  if ( (s=="show") || (s=="Show") )
1452  {
1453    print("The list of examples:");
1454    for (i=1; i<=size(E); i++)
1455    {
1456      printf("name: %s,  desc: %s", E[i],D[i]);
1457    }
1458    return();
1459  }
1460  string t;
1461  for (i=1; i<=size(E); i++)
1462  {
1463    if ( (s==E[i]) || (s==S[i]) )
1464    {
1465      t = "def @A = ex"+E[i]+"();";
1466      execute(t);
1467      return(@A);
1468    }
1469  }
1470  "No example found";
1471  return();
1472}
1473example
1474{
1475  "EXAMPLE:";echo = 2;
1476  controlExample("show");   // let us see all available examples:
1477  def B = controlExample("TwoPendula"); // let us set up a particular example
1478  setring B;
1479  print(R);
1480}
1481
1482//----------------------------------------------------------
1483//
1484//Some example rings with defined systems
1485//----------------------------------------------------------
1486//autonomy:
1487//
1488//----------------------------------------------------------
1489static proc exCauchy1()
1490{
1491  ring @r=0,(s1,s2),dp;
1492  module R= [s1,-s2],
1493            [s2, s1];
1494  R=transpose(R);
1495  export R;
1496  return(@r);
1497}
1498//----------------------------------------------------------
1499static proc exCauchy2()
1500{
1501  ring @r=0,(s1,s2,s3,s4),dp;
1502  module R= [s1,-s2],
1503            [s2, s1],
1504            [s3,-s4],
1505            [s4, s3];
1506  R=transpose(R);
1507  export R;
1508  return(@r);
1509}
1510//----------------------------------------------------------
1511static proc exZerz1()
1512{
1513  ring @r=0,(d1,d2),dp;
1514  module R=[d1^2-d2],
1515           [d2^2-1];
1516  R=transpose(R);
1517  export R;
1518  return(@r);
1519}
1520//----------------------------------------------------------
1521//control
1522//----------------------------------------------------------
1523static proc exControl1()
1524{
1525  ring @r=0,(s1,s2,s3),dp;
1526  module R=[0,-s3,s2],
1527           [s3,0,-s1];
1528  R=transpose(R);
1529  export R;
1530  return(@r);
1531}
1532//----------------------------------------------------------
1533static proc exControl2()
1534{
1535  ring @r=0,(s1,s2,s3),dp;
1536  module R=[0,-s3,s2],
1537           [s3,0,-s1],
1538           [-s2,s1,0];
1539  R=transpose(R);
1540  export R;
1541  return(@r);
1542}
1543//----------------------------------------------------------
1544static proc exAntenna()
1545{
1546  ring @r = (0, K1, K2, Te, Kp, Kc),(Dt, delta), dp;
1547  module R;
1548  R = [Dt, -K1, 0, 0, 0, 0, 0, 0, 0],
1549      [0, Dt+K2/Te, 0, 0, 0, 0, -Kp/Te*delta, -Kc/Te*delta, -Kc/Te*delta],
1550      [0, 0, Dt, -K1, 0, 0, 0, 0, 0],
1551      [0, 0, 0, Dt+K2/Te, 0, 0, -Kc/Te*delta, -Kp/Te*delta, -Kc/Te*delta],
1552      [0, 0, 0, 0, Dt, -K1, 0, 0, 0],
1553      [0, 0, 0, 0, 0, Dt+K2/Te, -Kc/Te*delta, -Kc/Te*delta, -Kp/Te*delta];
1554
1555  R=transpose(R);
1556  export R;
1557  return(@r);
1558}
1559
1560//----------------------------------------------------------
1561
1562static proc exEinstein()
1563{
1564  ring @r = 0,(D(1..4)),dp;
1565  module R =
1566  [D(2)^2+D(3)^2-D(4)^2, D(1)^2, D(1)^2, -D(1)^2, -2*D(1)*D(2), 0, 0, -2*D(1)*D(3), 0, 2*D(1)*D(4)],
1567  [D(2)^2, D(1)^2+D(3)^2-D(4)^2, D(2)^2, -D(2)^2, -2*D(1)*D(2), -2*D(2)*D(3), 0, 0, 2*D(2)*D(4), 0],
1568  [D(3)^2, D(3)^2, D(1)^2+D(2)^2-D(4)^2, -D(3)^2, 0, -2*D(2)*D(3), 2*D(3)*D(4), -2*D(1)*D(3), 0, 0],
1569  [D(4)^2, D(4)^2, D(4)^2, D(1)^2+D(2)^2+D(3)^2, 0, 0, -2*D(3)*D(4), 0, -2*D(2)*D(4), -2*D(1)*D(4)],
1570  [0, 0, D(1)*D(2), -D(1)*D(2), D(3)^2-D(4)^2, -D(1)*D(3), 0, -D(2)*D(3), D(1)*D(4), D(2)*D(4)],
1571  [D(2)*D(3), 0, 0, -D(2)*D(3),-D(1)*D(3), D(1)^2-D(4)^2, D(2)*D(4), -D(1)*D(2), D(3)*D(4), 0],
1572  [D(3)*D(4), D(3)*D(4), 0, 0, 0, -D(2)*D(4), D(1)^2+D(2)^2, -D(1)*D(4), -D(2)*D(3), -D(1)*D(3)],
1573  [0, D(1)*D(3), 0, -D(1)*D(3), -D(2)*D(3), -D(1)*D(2), D(1)*D(4), D(2)^2-D(4)^2, 0, D(3)*D(4)],
1574  [D(2)*D(4), 0, D(2)*D(4), 0, -D(1)*D(4), -D(3)*D(4), -D(2)*D(3), 0, D(1)^2+D(3)^2, -D(1)*D(2)],
1575  [0, D(1)*D(4), D(1)*D(4), 0, -D(2)*D(4), 0, -D(1)*D(3), -D(3)*D(4), -D(1)*D(2), D(2)^2+D(3)^2];
1576
1577  R=transpose(R);
1578  export R;
1579  return(@r);
1580}
1581
1582//----------------------------------------------------------
1583static proc exFlexibleRod()
1584{
1585  ring @r = 0,(D1, delta), dp;
1586  module R;
1587  R = [D1, -D1*delta, -1], [2*D1*delta, -D1-D1*delta^2, 0];
1588
1589  R=transpose(R);
1590  export R;
1591  return(@r);
1592}
1593
1594//----------------------------------------------------------
1595static proc exTwoPendula()
1596{
1597  ring @r=(0,m1,m2,M,g,L1,L2),Dt,dp;
1598  module R = [m1*L1*Dt^2, m2*L2*Dt^2, -1, (M+m1+m2)*Dt^2],
1599             [m1*L1^2*Dt^2-m1*L1*g, 0, 0, m1*L1*Dt^2],
1600             [0, m2*L2^2*Dt^2-m2*L2*g, 0, m2*L2*Dt^2];
1601
1602  R=transpose(R);
1603  export R;
1604  return(@r);
1605}
1606//----------------------------------------------------------
1607static proc exWindTunnel()
1608{
1609  ring @r = (0,a, omega, zeta, k),(D1, delta),dp;
1610  module R = [D1+a, -k*a*delta, 0, 0],
1611             [0, D1, -1, 0],
1612             [0, omega^2, D1+2*zeta*omega, -omega^2];
1613
1614  R=transpose(R);
1615  export R;
1616  return(@r);
1617}
1618
1619/* noncomm examples for leftInverse/rightInverse:
1620
1621LIB "jacobson.lib";
1622    ring w = 0,(x,d),Dp;
1623    def W=nc_algebra(1,1);
1624    setring W;
1625    matrix m[3][3]=[d2,d+1,0],[d+1,0,d3-x2*d],[2d+1, d3+d2, d2];
1626    list J=jacobson(m,0);
1627
1628leftInverse(J[3]); // exist
1629rightInverse(J[3]);
1630
1631leftInverse(J[1]); // zero
1632rightInverse(J[1]);
1633
1634list JJ = jacobson(J[1],0);
1635
1636leftInverse(JJ[3]); // exist
1637rightInverse(JJ[3]);
1638
1639leftInverse(JJ[1]); // exist
1640rightInverse(JJ[1]);
1641
1642leftInverse(JJ[2]); // zero
1643rightInverse(JJ[2]);
1644
1645*/
Note: See TracBrowser for help on using the repository browser.