source: git/Singular/LIB/ring.lib @ de9f10

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