source: git/Singular/LIB/ring.lib @ 8942a5

spielwiese
Last change on this file since 8942a5 was 8942a5, checked in by Gert-Martin Greuel <greuel@…>, 23 years ago
* GMG: Kosmetik git-svn-id: file:///usr/local/Singular/svn/trunk@4982 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 27.0 KB
Line 
1//(GMG, last modified 03.11.95)
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: ring.lib,v 1.14 2000-12-22 14:33:13 greuel Exp $";
4category="General purpose";
5info="
6LIBRARY:  ring.lib      Manipulating Rings and Maps
7
8PROCEDURES:
9 changechar(\"R\",c[,r]); make a copy R of basering [ring r] with new char c
10 changeord(\"R\",o[,r]);  make a copy R of basering [ring r] with new ord o
11 changevar(\"R\",v[,r]);  make a copy R of basering [ring r] with new vars v
12 defring(\"R\",c,n,v,o);  define a ring R in specified char c, n vars v, ord o
13 defrings(n[,p]);         define ring Sn in n vars, char 32003 [p], ord ds
14 defringp(n[,p]);         define ring Pn in n vars, char 32003 [p], ord dp
15 extendring(\"R\",n,v,o); extend given ring by n vars v, ord o and name it R
16 fetchall(R[,str]);       fetch all objects of ring R to basering
17 imapall(R[,str]);        imap all objects of ring R to basering
18 mapall(R,i[,str]);       map all objects of ring R via ideal i to basering
19 ord_test(R);             test wether ordering of R is global, local or mixed
20 ringtensor(\"R\",s,t,..);create ring R, tensor product of rings s,t,...
21           (parameters in square brackets [] are optional)
22";
23
24LIB "inout.lib";
25LIB "general.lib";
26///////////////////////////////////////////////////////////////////////////////
27
28proc changechar (string newr, string c, list #)
29"USAGE:   changechar(newr,c[,r]);  newr,c=strings, r=ring
30CREATE:  create a new ring with name `newr` and make it the basering if r is
31         an existing ring [default: r=basering].
32         The new ring differs from the old ring only in the characteristic.
33         If, say, (newr,c) = (\"R\",\"0,A\") and the ring r exists, the new
34         basering will have name R characteristic 0 and one parameter A.
35RETURN:  No return value
36NOTE:    Works for qrings if map from old_char to new_char is implemented
37         This proc uses 'execute' or calls a procedure using 'execute'.
38         If you use it in your own proc, let the local names of your proc
39         start with @ (see the file HelpForProc)
40EXAMPLE: example changechar; shows an example
41"
42{
43   if( size(#)==0 ) { def @r=basering; }
44   if( size(#)==1 ) { def @r=#[1]; }
45   setring @r;
46   ideal i = ideal(@r); int @q = size(i);
47   if( @q!=0 )
48      { string @s = "@newr1"; }
49   else
50      { string @s = newr; }
51   string @newring = @s+"=("+c+"),("+varstr(@r)+"),("+ordstr(@r)+");";
52   execute("ring "+@newring);
53   if( @q!=0 )
54   {
55      map phi = @r,maxideal(1);
56      ideal i = phi(i);
57      attrib(i,"isSB",1);         //*** attrib funktioniert ?
58      execute("qring "+newr+"=i;");
59   }
60   export(`newr`);
61   keepring(`newr`);
62   if (voice==2) { "// basering is now",newr; }
63   return();
64}
65example
66{  "EXAMPLE:"; echo = 2;
67   ring r=0,(x,y,u,v),(dp(2),ds);
68   changechar("R","2,A"); R;"";
69   changechar("R1","32003",R); R1;
70   kill R,R1;
71   if(system("with","Namespaces")) {
72      if( nameof(Current) == "Ring" ) {
73        kill Top::R,Top::R1;
74      } else {
75        kill Ring::R,Ring::R1;
76      }
77   }
78}
79///////////////////////////////////////////////////////////////////////////////
80
81proc changeord (string newr, string o, list #)
82"USAGE:   changeord(newr,o[,r]);  newr,o=strings, r=ring/qring
83CREATE:  create a new ring with name `newr` and make it the basering if r is
84         an existing ring/qring [default: r=basering].
85         The new ring differs from the old ring only in the ordering. If, say,
86         (newr,o) = (\"R\",\"wp(2,3),dp\") and the ring r exists and has >=3
87         variables, the new basering will have name R and ordering wp(2,3),dp.
88RETURN:  No return value
89NOTE:    This proc uses 'execute' or calls a procedure using 'execute'.
90         If you use it in your own proc, let the local names of your proc
91         start with @ (see the file HelpForProc)
92EXAMPLE: example changeord; shows an example
93"
94{
95   if( size(#)==0 ) { def @r=basering; }
96   if( size(#)==1 ) { def @r=#[1]; }
97   setring @r;
98   ideal i = ideal(@r); int @q = size(i);
99   if( @q!=0 )
100      { string @s = "@newr1"; }
101   else
102      { string @s = newr; }
103   string @newring = @s+"=("+charstr(@r)+"),("+varstr(@r)+"),("+o+");";
104   execute("ring "+@newring);
105   if( @q!=0 )
106   {
107      map phi = @r,maxideal(1);
108      ideal i = phi(i);
109      attrib(i,"isSB",1);         //*** attrib funktioniert ?
110      execute("qring "+newr+"=i;");
111   }
112   export(`newr`);
113   keepring(`newr`);
114   if (voice==2) { "// basering is now",newr; }
115   return();
116}
117example
118{  "EXAMPLE:"; echo = 2;
119   ring r=0,(x,y,u,v),(dp(2),ds);
120   changeord("R","wp(2,3),dp"); R; "";
121   ideal i = x^2,y^2-u^3,v;
122   qring Q = std(i);
123   changeord("Q'","lp",Q); Q';
124   kill R,Q,Q';
125   if(system("with","Namespaces")) {
126      if( nameof(Current) == "Ring" ) {
127        kill Top::R,Top::Q';
128      } else {
129        kill Ring::R,Ring::Q';
130      }
131   }
132}
133///////////////////////////////////////////////////////////////////////////////
134
135proc changevar (string newr, string vars, list #)
136"USAGE:   changevar(newr,vars[,r]);  newr,vars=strings, r=ring/qring
137CREATE:  creates a new ring with name `newr` and makes it the basering if r
138         is an existing ring/qring [default: r=basering].
139         The new ring differs from the old ring only in the variables. If,
140         say, (newr,vars) = (\"R\",\"t()\") and the ring r exists and has n
141         variables, the new basering will have name R and variables
142         t(1),...,t(n).
143         If vars = \"a,b,c,d\", the new ring will have the variables a,b,c,d.
144RETURN:  No return value
145NOTE:    This procedure is useful in connection with the procedure ringtensor,
146         when a conflict between variable names must be avoided.
147         This proc uses 'execute' or calls a procedure using 'execute'.
148         If you use it in your own proc, let the local names of your proc
149         start with @ (see the file HelpForProc)
150EXAMPLE: example changevar; shows an example
151"
152{
153   if( size(#)==0 ) { def @r=basering; }
154   if( size(#)==1 ) { def @r=#[1]; }
155   setring @r;
156   ideal i = ideal(@r); int @q = size(i);
157   if( @q!=0 )
158      { string @s = "@newr1"; }
159   else
160      { string @s = newr; }
161   string @newring = @s+"=("+charstr(@r)+"),(";
162   if( vars[size(vars)-1]=="(" and vars[size(vars)]==")" )
163   {
164      @newring = @newring+vars[1,size(vars)-2]+"(1.."+string(nvars(@r))+")";
165   }
166   else { @newring = @newring+vars; }
167   @newring = @newring+"),("+ordstr(@r)+");";
168   execute("ring "+@newring);
169   if( @q!=0 )
170   {
171      map phi = @r,maxideal(1);
172      ideal i = phi(i);
173      attrib(i,"isSB",1);         //*** attrib funktioniert ?
174      execute("qring "+newr+"=i;");
175   }
176   export(`newr`);
177   keepring(`newr`);
178   if (voice==2) { "// basering is now",newr; }
179   return();
180}
181example
182{  "EXAMPLE:"; echo = 2;
183   ring r=0,(x,y,u,v),(dp(2),ds);
184   ideal i = x^2,y^2-u^3,v;
185   qring Q = std(i);
186   setring(r);
187   changevar("R","A()"); R; "";
188   changevar("Q'","a,b,c,d",Q); Q';
189   kill R,Q,Q';
190   if(system("with","Namespaces")) {
191      if( nameof(Current) == "Ring" ) {
192        kill Top::R,Top::Q';
193      } else {
194        kill Ring::R,Ring::Q';
195      }
196   }
197}
198///////////////////////////////////////////////////////////////////////////////
199
200proc defring (string s1, string s2, int n, string s3, string s4)
201"USAGE:   defring(s1,s2,n,s3,s4);  s1..s4=strings, n=integer
202CREATE:  Define a ring with name 's1', characteristic 's2', ordering 's4' and
203         n variables with names derived from s3 and make it the basering.
204         If s3 is a single letter, say s3=\"a\", and if n<=26 then a and the
205         following n-1 letters from the alphabeth (cyclic order) are taken as
206         variables. If n>26 or if s3 is a single letter followed by (, say
207         s3=\"T(\", the variables are T(1),...,T(n).
208RETURN:  No return value
209NOTE:    This proc is useful for defining a ring in a procedure.
210         This proc uses 'execute' or calls a procedure using 'execute'.
211         If you use it in your own proc, let the local names of your proc
212         start with @ (see the file HelpForProc)
213EXAMPLE: example defring; shows an example
214"
215{
216   string @newring = "ring "+s1+"=("+s2+"),(";
217   if( n>26 or s3[2]=="(" ) { string @v = s3[1]+"(1.."+string(n)+")"; }
218   else { string @v = A_Z(s3,n); }
219   @newring=@newring+@v+"),("+s4+");";
220   execute(@newring);
221   export(basering);
222   keepring(`s1`);
223   if (voice==2) { "// basering is now:",s1; }
224   return();
225}
226example
227{ "EXAMPLE:"; echo = 2;
228   defring("r","0",5,"u","ls"); r; "";
229   defring("R","2,A",10,"x(","dp(3),ws(1,2,3),ds"); R;
230   kill r,R;
231   if(system("with","Namespaces")) {
232      if( nameof(Current) == "Ring" ) {
233        kill Top::r,Top::R;
234      } else {
235        kill Ring::r,Ring::R;
236      }
237   }
238}
239///////////////////////////////////////////////////////////////////////////////
240
241proc defrings (int n, list #)
242"USAGE:   defrings(n,[p]);  n,p integers
243CREATE:  Defines a ring with name Sn, characteristic p, ordering ds and n
244         variables x,y,z,a,b,...if n<=26 (resp. x(1..n) if n>26) and makes it
245         the basering (default: p=32003)
246RETURN:  No return value
247EXAMPLE: example defrings; shows an example
248"
249{
250   int p;
251   if (size(#)==0) { p=32003; }
252   else { p=#[1]; }
253   if (n >26)
254   {
255      string s="ring S"+string(n)+"="+string(p)+",x(1.."+string(n)+"),ds;";
256   }
257   else
258   {
259      string s="ring S"+string(n)+"="+string(p)+",("+A_Z("x",n)+"),ds;";
260   }
261   execute(s);
262   export basering;
263   execute("keepring S"+string(n)+";");
264   if (voice==2) { "// basering is now:",s; }
265}
266example
267{ "EXAMPLE:"; echo = 2;
268   defrings(5,0); S5; "";
269   defrings(30); S30;
270   kill S5, S30;
271   if(system("with","Namespaces")) {
272      if( nameof(Current) == "Ring" ) {
273        kill Top::S5,Top::S30;
274      } else {
275        kill Ring::S5,Ring::S30;
276      }
277   }
278}
279///////////////////////////////////////////////////////////////////////////////
280
281proc defringp (int n,list #)
282"USAGE:   defringp(n,[p]);  n,p=integers
283CREATE:  defines a ring with name Pn, characteristic p, ordering dp and n
284         variables x,y,z,a,b,...if n<=26 (resp. x(1..n) if n>26) and makes it
285         the basering (default: p=32003)
286RETURN:  No return value
287EXAMPLE: example defringp; shows an example
288"
289{
290   int p;
291   if (size(#)==0) { p=32003; }
292   else { p=#[1]; }
293   if (n >26)
294   {
295      string s="ring P"+string(n)+"="+string(p)+",x(1.."+string(n)+"),dp;";
296   }
297   else
298   {
299     string s="ring P"+string(n)+"="+string(p)+",("+A_Z("x",n)+"),dp;";
300   }
301   execute(s);
302   export basering;
303   execute("keepring P"+string(n)+";");
304   //the next comment is only shown if defringp is not called by another proc
305   if (voice==2) { "// basering is now:",s; }
306}
307example
308{ "EXAMPLE:"; echo = 2;
309   defringp(5,0); P5; "";
310   defringp(30); P30;
311   kill P5, P30;
312   if(system("with","Namespaces")) {
313      if( nameof(Current) == "Ring" ) {
314        kill Top::P5,Top::P30;
315      } else {
316        kill Ring::P5,Ring::P30;
317      }
318   }
319}
320///////////////////////////////////////////////////////////////////////////////
321
322proc extendring (string na, int n, string va, string o, list #)
323"USAGE:   extendring(na,n,va,o[iv,i,r]);  na,va,o=strings,
324         n,i=integers, r=ring, iv=intvec of positive integers or iv=0
325CREATE:  Define a ring with name `na` which extends the ring r by adding n new
326         variables in front of [after, if i!=0] the old variables and make it
327         the basering [default: (i,r)=(0,basering)]
328         -- The characteristic is the characteristic of r
329         -- The new vars are derived from va. If va is a single letter, say
330            va=\"T\", and if n<=26 then T and the following n-1 letters from
331            T..Z..T (resp. T(1..n) if n>26) are taken as additional variables.
332            If va is a single letter followed by (, say va=\"x(\", the new
333            variables are x(1),...,x(n)
334         -- The ordering is the product ordering between the ordering of r and
335            an ordering derived from `o` [and iv]
336         -  If o contains a 'c' or a 'C' in front resp. at the end this is
337            taken for the whole ordering in front resp. at the end. If o does
338            not contain a 'c' or a 'C' the same rule applies to ordstr(r).
339         -  If no intvec iv is given, or if iv=0, o may be any allowed ordstr,
340            like \"ds\" or \"dp(2),wp(1,2,3),Ds(2)\" or \"ds(a),dp(b),ls\" if a and b
341            are globally (!) defined integers and if a+b+1<=n
342            If, however, a and b are local to a proc calling extendring, the
343            intvec iv must be used to let extendring know the values of a and b
344         -  If an intvec iv !=0 is given, iv[1],iv[2],... is taken for the 1st,
345            2nd,... block of o, if o contains no substring \"w\" or \"W\" i.e. no
346            weighted ordering (in the above case o=\"ds,dp,ls\" and iv=a,b).
347            If o contains a weighted ordering (only one (!) weighted block is
348            allowed) iv[1] is taken as size for the weight-vector, the next
349            iv[1] values of iv are taken as weights and the remaining values of
350            iv as block-size for the remaining non-weighted blocks.
351            e.g. o=\"dp,ws,Dp,ds\", iv=3,2,3,4,2,5 creates the ordering
352            dp(2),ws(2,3,4),Dp(5),ds
353RETURN:  No return value
354NOTE:    This proc is useful for adding deformation parameters.
355         This proc uses 'execute' or calls a procedure using 'execute'.
356         If you use it in your own proc, let the local names of your proc
357         start with @ (see the file HelpForProc)
358EXAMPLE: example extendring; shows an example
359"
360{
361//--------------- initialization and place c/C of ordering properly -----------
362   string @o1,@o2,@ro,@wstr,@v,@newring;
363   int @i,@w,@ii,@k;
364   intvec @iv,@iw;
365   if( find(o,"c")+find(o,"C") != 0)
366   {
367      @k=1;
368      if( o[1]=="c" or o[1]=="C" ) { @o1=o[1,2]; o=o[3..size(o)]; }
369      else                         { @o2=o[size(o)-1,2]; o=o[1..size(o)-2]; }
370   }
371   if( size(#)==0 ) { #[1]=0; }
372   if( typeof(#[1])!="intvec" )
373   {
374     if( size(#)==1 ) { @i=#[1]; def @r=basering; }
375     if( size(#)==2 ) { @i=#[1]; def @r=#[2]; }
376     if( o[size(o)]!=")" and find(o,",")==0 ) { o=o+"("+string(n)+")"; }
377   }
378   else
379   {
380     @iv=#[1];
381     if( size(#)==2 ) { @i=#[2]; def @r=basering; }
382     if( size(#)==3 ) { @i=#[2]; def @r=#[3]; }
383     if( @iv==0 && o[size(o)]!=")" && find(o,",")==0 ) {o=o+"("+string(n)+")";}
384   }
385   @ro=ordstr(@r);
386   if( @ro[1]=="c" or @ro[1]=="C" )
387      { @v=@ro[1,2]; @ro=@ro[3..size(@ro)]; }
388   else
389      { @wstr=@ro[size(@ro)-1,2]; @ro=@ro[1..size(@ro)-2]; }
390   if( @k==0) { @o1=@v; @o2=@wstr; }
391//----------------- prepare ordering if an intvec is given --------------------
392   if( typeof(#[1])=="intvec" and #[1]!=0 )
393   {
394      @k=n;                               //@k counts no of vars not yet ordered
395      @w=find(o,"w")+find(o,"W");o=o+" ";
396      if( @w!=0 )
397      {
398         @wstr=o[@w..@w+1];
399         o=o[1,@w-1]+"@"+o[@w+2,size(o)];
400         @iw=@iv[2..@iv[1]+1];
401         @wstr=@wstr+"("+string(@iw)+")";
402         @k=@k-@iv[1];
403         @iv=@iv[@iv[1]+2..size(@iv)];
404         @w=0;
405      }
406      for( @ii=1; @ii<=size(@iv); @ii=@ii+1 )
407      {
408         if( find(o,",",@w+1)!=0 )
409         {
410            @w=find(o,",",@w+1);
411            if( o[@w-1]!="@" )
412            {
413               o=o[1,@w-1]+"("+string(@iv[@ii])+")"+o[@w,size(o)];
414               @w=find(o,",",@w+1);
415               @k=@k-@iv[@ii];
416            }
417            else { @ii=@ii-1; }
418         }
419      }
420      @w=find(o,"@");
421      if( @w!=0 ) { o=o[1,@w-1] + @wstr + o[@w+1,size(o)]; }
422      if( @k>0 and o[size(o)]!=")" ) { o=o+"("+string(@k)+")"; }
423   }
424//------------------------ prepare string of new ring -------------------------
425   @newring = "ring "+na+"=("+charstr(@r)+"),(";
426   if( n>26 or va[2]=="(" ) { @v = va[1]+"(1.."+string(n)+")"; }
427   else                     { @v = A_Z(va,n); }
428   if( @i==0 )
429   {
430      @v=@v+","+varstr(@r);
431      o=@o1+o+","+@ro+@o2;
432   }
433   else
434   {
435      @v=varstr(@r)+","+@v;
436      o=@o1+@ro+","+o+@o2;
437   }
438   @newring=@newring+@v+"),("+o+");";
439//---------------------------- execute and export -----------------------------
440   execute(@newring);
441   export(basering);
442   keepring(`na`);
443   if (voice==2) { "// basering is now",na; }
444   return();
445}
446example
447{ "EXAMPLE:"; echo = 2;
448   ring r=0,(x,y,z),ds;
449   show(r);"";
450   //no intvec given, no blocksize given: blocksize is derived from no of vars
451   int t=5;
452   extendring("R1",t,"a","dp");         //t global: "dp" -> "dp(5)"
453   show(R1); "";
454   extendring("R2",4,"T(","c,dp",1,r);    //"dp" -> "c,..,dp(4)"
455   show(R2);"";
456
457   //no intvec given, blocksize given: given blocksize is used
458   extendring("R3",4,"T(","dp(2)",0,r);   // "dp(2)" -> "dp(2)"
459   show(R3);"";
460
461   //intvec given: weights and blocksize is derived from given intvec
462   //(no specification of a blocksize in the given ordstr is allowed!)
463   //if intvec does not cover all given blocks, the last block is used for
464   //the remaining variables, if intvec has too many components, the last
465   //ones are ignored
466   intvec v=3,2,3,4,1,3;
467   extendring("R4",10,"A","ds,ws,Dp,dp",v,0,r);
468         //v covers 3 blocks: v[1] (=3) : no of components of ws
469         //next v[1] values (=v[2..4]) give weights
470         //remaining components of v are used for the remaining blocks
471   show(R4);
472   kill r,R1,R2,R3,R4;
473   if(system("with","Namespaces")) {
474      if( nameof(Current) == "Ring" ) {
475        kill Top::R1,Top::R2,Top::R3,Top::R4;
476      } else {
477        kill Ring::R1,Ring::R2,Ring::R3,Ring::R4;
478      }
479   }
480}
481///////////////////////////////////////////////////////////////////////////////
482
483proc fetchall (R, list #)
484"USAGE:   fetchall(R[,s]);  R=ring/qring, s=string
485CREATE:  fetch all objects of ring R (of type poly/ideal/vector/module/number/
486         matrix) into the basering.
487         If no 3rd argument is present, the names are the same as in R. If,
488         say, f is a poly in R and the 3rd argument is the string \"R\", then f
489         is maped to f_R etc.
490RETURN:  no return value
491NOTE:    As fetch, this procedure maps the 1st, 2nd, ... variable of R to the
492         1st, 2nd, ... variable of the basering.
493         The 3rd argument is useful in order to avoid conflicts of names, the
494         empty string is allowed
495CAUTION: fetchall does not work inside a procedure
496         //***at the moment it does not work if R contains a map
497EXAMPLE: example fetchall; shows an example
498"
499{
500   list @L@=names(R);
501   int @ii@; string @s@;
502   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
503   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
504   {
505      execute("def "+@L@[@ii@]+@s@+"=fetch(R,`@L@[@ii@]`);");
506      execute("export "+@L@[@ii@]+@s@+";");
507   }
508   return();
509}
510example
511{  "EXAMPLE:"; echo=2;
512// This example is not executed since fetchall does not work in a procedure;
513// (and hence not in the example procedure). Just try the following commands:;
514//   ring R=0,(x,y,z),dp;
515//   ideal j=x,y2,z2;
516//   matrix M[2][3]=1,2,3,x,y,z;
517//   j; print(M);
518//   ring S=0,(a,b,c),ds;
519//   fetchall(R);           // map from R to S: x->a, y->b, z->c;
520//   names(S);
521//   j; print(M);
522//   fetchall(S,"1");       // identity map of S: copy objects, change names;
523//   names(S);
524//   kill R,S;
525}
526///////////////////////////////////////////////////////////////////////////////
527
528proc imapall (R, list #)
529"USAGE:   imapall(R[,s]);  R=ring/qring, s=string
530CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
531         matrix) into the basering, by applying imap to all objects of R.
532         If no 3rd argument is present, the names are the same as in R. If,
533         say, f is a poly in R and the 3rd argument is the string \"R\", then f
534         is maped to f_R etc.
535RETURN:  no return value
536NOTE:    As imap, this procedure maps the variables of R to the variables with
537         the same name in the basering, the other variables are maped to 0.
538         The 3rd argument is useful in order to avoid conflicts of names, the
539         empty string is allowed
540CAUTION: imapall does not work inside a procedure
541         //***at the moment it does not work if R contains a map
542EXAMPLE: example imapall; shows an example
543"
544{
545   list @L@=names(R);
546   int @ii@; string @s@;
547   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
548   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
549   {
550         execute("def "+@L@[@ii@]+@s@+"=imap(R,`@L@[@ii@]`);");
551         execute("export "+@L@[@ii@]+@s@+";");
552   }
553   return();
554}
555example
556{  "EXAMPLE:"; echo = 2;
557// This example is not executed since imapall does not work in a procedure
558// (and hence not in the example procedure). Just try the following commands:
559//   ring R=0,(x,y,z,u),dp;
560//   ideal j=x,y,z,u2+ux+z;
561//   matrix M[2][3]=1,2,3,x,y,uz;
562//   j; print(M);
563//   ring S=0,(a,b,c,x,z,y),ds;
564//   imapall(R);           // map from R to S: x->x, y->y, z->z, u->0
565//   names(S);
566//   j; print(M);
567//   imapall(S,"1");       // identity map of S: copy objects, change names
568//   names(S);
569//   kill R,S;
570}
571///////////////////////////////////////////////////////////////////////////////
572
573proc mapall (R, ideal i, list #)
574"USAGE:   mapall(R,i[,s]);  R=ring/qring, i=ideal of basering, s=string
575CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
576         matrix, map) into the basering, by mapping the jth variable of R to
577         the jth generator of the ideal i. If no 3rd argument is present, the
578         names are the same as in R. If, say, f is a poly in R and the 3rd
579         argument is the string \"R\", then f is maped to f_R etc.
580RETURN:  no return value
581NOTE:    This procedure has the same effect as defining a map, say psi, by
582         map psi=R,i; and then applying psi to all objects of R. In particular,
583         maps from R to some ring S are composed with psi, creating thus a map
584         from the basering to S.
585         mapall may be combined with copyring to change vars for all objects.
586         The 3rd argument is useful in order to avoid conflicts of names, the
587         empty string is allowed
588CAUTION: mapall does not work inside a procedure
589EXAMPLE: example mapall; shows an example
590"
591{
592   list @L@=names(R); map @psi@ = R,i;
593   int @ii@; string @s@;
594   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
595   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
596   {
597      execute("def "+@L@[@ii@]+@s@+"=@psi@(`@L@[@ii@]`);");
598      execute("export "+@L@[@ii@]+@s@+";");
599   }
600   return();
601}
602example
603{  "EXAMPLE:"; echo = 2;
604// This example is not executed since mapall does not work in a procedure
605// (and hence not in the example procedure). Just try the following commands:
606//   ring R=0,(x,y,z),dp;
607//   ideal j=x,y,z;
608//   matrix M[2][3]=1,2,3,x,y,z;
609//   map phi=R,x2,y2,z2;
610//   ring S=0,(a,b,c),ds;
611//   ideal i=c,a,b;
612//   mapall(R,i);             // map from R to S: x->c, y->a, z->b
613//   names(S);
614//   j; print(M); phi;        // phi is a map from R to S: x->c2, y->a2, z->b2
615//   ideal i1=a2,a+b,1;
616//   mapall(R,i1,\"\");         // map from R to S: x->a2, y->a+b, z->1
617//   names(S);
618//   j_; print(M_); phi_;
619//   changevar(\"T\",\"x()\",R);  // change vars in R and call result T
620//   mapall(R,maxideal(1));   // identity map from R to T
621//   names(T);
622//   j; print(M); phi;
623//   kill R,S,T;
624}
625///////////////////////////////////////////////////////////////////////////////
626
627proc ord_test (r)
628"USAGE:   ord_test(r);  r ring
629RETURN:  int 1 (resp. -1, resp. 0) if ordering of r is global (resp. local,
630         resp. mixed)
631EXAMPLE: example ord_test; shows an example
632"
633{
634   if (typeof(r) != "ring")
635   {
636      "// ord_test requires a ring as input";
637      return();
638   }
639   def BAS = basering;
640   setring r;
641   poly f;
642   int n,o,u = nvars(r),1,1;
643   int ii;
644   for ( ii=1; ii<=n; ii++ )
645   {
646      f = 1+var(ii);
647      o = o*(lead(f) == var(ii));
648      u = u*(lead(f) == 1);
649   }
650   setring BAS;
651   if ( o==1 ) { return(1); }
652   if ( u==1 ) { return(-1); }
653   else { return(0); }
654}
655example
656{ "EXAMPLE:"; echo = 2;
657   ring R = 0,(x,y),dp;
658   ring S = 0,(u,v),ls;
659   ord_test(R);
660   ord_test(S);
661   ord_test(R+S);   
662}
663///////////////////////////////////////////////////////////////////////////////
664
665proc ringtensor (string s, list #)
666"USAGE:   ringtensor(s,r1,r2,...); s=string, r1,r2,...=rings
667CREATE:  A new base ring with name `s` if r1,r2,... are existing rings.
668         If, say, s = \"R\" and the rings r1,r2,... exist, the new ring will
669         have name R, variables from all rings r1,r2,... and as monomial
670         ordering the block (product) ordering of r1,r2,... . Hence, R
671         is the tensor product of the rings r1,r2,... with ordering matrix
672         equal to the direct sum of the ordering matrices of r1,r2,...
673RETURN:  no return value
674NOTE:    The characteristic of the new ring will be that of r1. The names of
675         variables in the rings r1,r2,... should differ (if a name, say x,
676         occurs in r1 and r2, then, in the new ring r, x always refers to the
677         variable with name x in r1, there is no access to x in r2).
678         The procedure works also for quotient rings ri, if the characteristic
679         of ri is compatible with the characteristic of r1 (i.e. if imap from
680         ri to r1 is implemented)
681         This proc uses 'execute' or calls a procedure using 'execute'.
682         If you use it in your own proc, let the local names of your proc
683         start with @ (see the file HelpForProc)
684EXAMPLE: example ringtensor; shows an example
685"
686{
687   int @ii,@q;
688   int @n = size(#);
689   string @vars,@order,@oi,@s1;
690//---- gather variables, orderings and ideals (of qrings) from given rings ----
691   for(@ii=1; @ii<=@n; @ii=@ii+1)
692   {
693      if( ordstr(#[@ii])[1]=="C" or ordstr(#[@ii])[1]=="c" )
694           { @oi=ordstr(#[@ii])[3,size(ordstr(#[@ii]))-2]; }
695      else { @oi=ordstr(#[@ii])[1,size(ordstr(#[@ii]))-2]; }
696      @vars = @vars+varstr(#[@ii])+",";
697      @order= @order+@oi+",";
698      def @r(@ii)=#[@ii];
699      setring @r(@ii);
700      ideal i(@ii)=ideal(@r(@ii));
701      int @q(@ii)=size(i(@ii));
702      @q=@q+@q(@ii);
703   }
704   if( @q!=0 ) { @s1 = "@newr"; }   // @q=0 iff none of the rings ri is a qring
705   else {  @s1 = s; }
706//------------------------------- create new ring -----------------------------
707   string @newring ="=("+charstr(#[1])+"),("+@vars[1,size(@vars)-1]+"),("
708                  +@order[1,size(@order)-1]+");";
709   execute("ring "+@s1+@newring);
710//------ create ideal for new ring if one of the given rings is a qring -------
711   if( @q!=0 )
712   {
713      ideal i;
714      for(@ii=1; @ii<=@n; @ii=@ii+1)
715      {
716         if( @q(@ii)!=0 )
717         {
718            i=i+imap(@r(@ii),i(@ii));
719         }
720      }
721      i=std(i);
722      execute("qring "+s+"=i;");
723   }
724//----------------------- export and keep created ring ------------------------
725   export(`s`);
726   keepring(`s`);
727   if (voice==2) { "// basering is now",s; }
728   return();
729}
730example
731{ "EXAMPLE:"; echo = 2;
732   ring r=32003,(x,y,u,v),dp;
733   ring s=0,(a,b,c),wp(1,2,3);
734   ring t=0,x(1..5),(c,ls);
735   ringtensor("R",r,s,t);
736   type R;
737   setring s;
738   ideal i = a2+b3+c5;
739   changevar("S","x,y,z");      //set S (change vars of s to x,y,z) the basering
740   qring qS =std(fetch(s,i));    //create qring of S mod i (maped to S)
741   changevar("T","d,e,f,g,h",t); //set T (change vars of t to d..h) the basering
742   qring qT=std(d2+e2-f3);       //create qring of T mod d2+e2-f3
743   ringtensor("Q",s,qS,t,qT);
744   type Q;
745   kill R,Q,S,T;
746   if(system("with","Namespaces")) {
747      if( nameof(Current) == "Ring" ) {
748        kill Top::R,Top::Q,Top::S,Top::T;
749      } else {
750        kill Ring::R,Ring::Q,Ring::S,Ring::T;
751      }
752   }
753}
754///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.