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

spielwiese
Last change on this file since bb7da7 was bb7da7, checked in by Gert-Martin Greuel <greuel@…>, 23 years ago
* GMG: Kosmetik git-svn-id: file:///usr/local/Singular/svn/trunk@4998 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 26.8 KB
Line 
1//(GMG, last modified 03.11.95)
2///////////////////////////////////////////////////////////////////////////////
3version="$Id: ring.lib,v 1.15 2000-12-31 01:57:42 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 @.
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 @.
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 @.
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 @.
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
341            a and b 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
345            1st, 2nd,... block of o, if o contains no substring \"w\" or \"W\"
346            i.e. no weighted ordering (in the above case o=\"ds,dp,ls\"
347            and iv=a,b).
348            If o contains a weighted ordering (only one (!) weighted block is
349            allowed) iv[1] is taken as size for the weight-vector, the next
350            iv[1] values of iv are taken as weights and the remaining values of
351            iv as block-size for the remaining non-weighted blocks.
352            e.g. o=\"dp,ws,Dp,ds\", iv=3,2,3,4,2,5 creates the ordering
353            dp(2),ws(2,3,4),Dp(5),ds
354RETURN:  No return value
355NOTE:    This proc is useful for adding deformation parameters.
356         This proc uses 'execute' or calls a procedure using 'execute'.
357         If you use it in your own proc, let the local names of your proc
358         start with @ (see the file HelpForProc)
359EXAMPLE: example extendring; shows an example
360"
361{
362//--------------- initialization and place c/C of ordering properly -----------
363   string @o1,@o2,@ro,@wstr,@v,@newring;
364   int @i,@w,@ii,@k;
365   intvec @iv,@iw;
366   if( find(o,"c")+find(o,"C") != 0)
367   {
368      @k=1;
369      if( o[1]=="c" or o[1]=="C" ) { @o1=o[1,2]; o=o[3..size(o)]; }
370      else                         { @o2=o[size(o)-1,2]; o=o[1..size(o)-2]; }
371   }
372   if( size(#)==0 ) { #[1]=0; }
373   if( typeof(#[1])!="intvec" )
374   {
375     if( size(#)==1 ) { @i=#[1]; def @r=basering; }
376     if( size(#)==2 ) { @i=#[1]; def @r=#[2]; }
377     if( o[size(o)]!=")" and find(o,",")==0 ) { o=o+"("+string(n)+")"; }
378   }
379   else
380   {
381     @iv=#[1];
382     if( size(#)==2 ) { @i=#[2]; def @r=basering; }
383     if( size(#)==3 ) { @i=#[2]; def @r=#[3]; }
384     if( @iv==0 && o[size(o)]!=")" && find(o,",")==0 ) {o=o+"("+string(n)+")";}
385   }
386   @ro=ordstr(@r);
387   if( @ro[1]=="c" or @ro[1]=="C" )
388      { @v=@ro[1,2]; @ro=@ro[3..size(@ro)]; }
389   else
390      { @wstr=@ro[size(@ro)-1,2]; @ro=@ro[1..size(@ro)-2]; }
391   if( @k==0) { @o1=@v; @o2=@wstr; }
392//----------------- prepare ordering if an intvec is given --------------------
393   if( typeof(#[1])=="intvec" and #[1]!=0 )
394   {
395      @k=n;                             //@k counts no of vars not yet ordered
396      @w=find(o,"w")+find(o,"W");o=o+" ";
397      if( @w!=0 )
398      {
399         @wstr=o[@w..@w+1];
400         o=o[1,@w-1]+"@"+o[@w+2,size(o)];
401         @iw=@iv[2..@iv[1]+1];
402         @wstr=@wstr+"("+string(@iw)+")";
403         @k=@k-@iv[1];
404         @iv=@iv[@iv[1]+2..size(@iv)];
405         @w=0;
406      }
407      for( @ii=1; @ii<=size(@iv); @ii=@ii+1 )
408      {
409         if( find(o,",",@w+1)!=0 )
410         {
411            @w=find(o,",",@w+1);
412            if( o[@w-1]!="@" )
413            {
414               o=o[1,@w-1]+"("+string(@iv[@ii])+")"+o[@w,size(o)];
415               @w=find(o,",",@w+1);
416               @k=@k-@iv[@ii];
417            }
418            else { @ii=@ii-1; }
419         }
420      }
421      @w=find(o,"@");
422      if( @w!=0 ) { o=o[1,@w-1] + @wstr + o[@w+1,size(o)]; }
423      if( @k>0 and o[size(o)]!=")" ) { o=o+"("+string(@k)+")"; }
424   }
425//------------------------ prepare string of new ring -------------------------
426   @newring = "ring "+na+"=("+charstr(@r)+"),(";
427   if( n>26 or va[2]=="(" ) { @v = va[1]+"(1.."+string(n)+")"; }
428   else                     { @v = A_Z(va,n); }
429   if( @i==0 )
430   {
431      @v=@v+","+varstr(@r);
432      o=@o1+o+","+@ro+@o2;
433   }
434   else
435   {
436      @v=varstr(@r)+","+@v;
437      o=@o1+@ro+","+o+@o2;
438   }
439   @newring=@newring+@v+"),("+o+");";
440//---------------------------- execute and export -----------------------------
441   execute(@newring);
442   export(basering);
443   keepring(`na`);
444   if (voice==2) { "// basering is now",na; }
445   return();
446}
447example
448{ "EXAMPLE:"; echo = 2;
449   ring r=0,(x,y,z),ds;
450   show(r);"";
451   //blocksize is derived from no of vars:
452   int t=5;
453   extendring("R1",t,"a","dp");         //t global: "dp" -> "dp(5)"
454   show(R1); "";
455   extendring("R2",4,"T(","c,dp",1,r);    //"dp" -> "c,..,dp(4)"
456   show(R2);"";
457
458   //no intvec given, blocksize given: given blocksize is used:
459   extendring("R3",4,"T(","dp(2)",0,r);   // "dp(2)" -> "dp(2)"
460   show(R3);"";
461
462   //intvec given: weights and blocksize is derived from given intvec
463   //(no specification of a blocksize in the given ordstr is allowed!)
464   //if intvec does not cover all given blocks, the last block is used
465   //for the remaining variables, if intvec has too many components,
466   //the last ones are ignored
467   intvec v=3,2,3,4,1,3;
468   extendring("R4",10,"A","ds,ws,Dp,dp",v,0,r);
469         //v covers 3 blocks: v[1] (=3) : no of components of ws
470         //next v[1] values (=v[2..4]) give weights
471         //remaining components of v are used for the remaining blocks
472   show(R4);
473   kill r,R1,R2,R3,R4;
474   if(system("with","Namespaces")) {
475      if( nameof(Current) == "Ring" ) {
476        kill Top::R1,Top::R2,Top::R3,Top::R4;
477      } else {
478        kill Ring::R1,Ring::R2,Ring::R3,Ring::R4;
479      }
480   }
481}
482///////////////////////////////////////////////////////////////////////////////
483
484proc fetchall (R, list #)
485"USAGE:   fetchall(R[,s]);  R=ring/qring, s=string
486CREATE:  fetch all objects of ring R (of type poly/ideal/vector/module/number/
487         matrix) into the basering.
488         If no 3rd argument is present, the names are the same as in R. If,
489         say, f is a poly in R and the 3rd argument is the string \"R\", then f
490         is maped to f_R etc.
491RETURN:  no return value
492NOTE:    As fetch, this procedure maps the 1st, 2nd, ... variable of R to the
493         1st, 2nd, ... variable of the basering.
494         The 3rd argument is useful in order to avoid conflicts of names, the
495         empty string is allowed
496CAUTION: fetchall does not work inside a procedure.
497         It does not work if R contains a map.
498EXAMPLE: example fetchall; shows an example
499"
500{
501   list @L@=names(R);
502   int @ii@; string @s@;
503   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
504   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
505   {
506      execute("def "+@L@[@ii@]+@s@+"=fetch(R,`@L@[@ii@]`);");
507      execute("export "+@L@[@ii@]+@s@+";");
508   }
509   return();
510}
511example
512{  "EXAMPLE:"; echo=2;
513// The example is not shown since fetchall does not work in a procedure;
514// (and hence not in the example procedure). Try the following commands:
515//   ring R=0,(x,y,z),dp;
516//   ideal j=x,y2,z2;
517//   matrix M[2][3]=1,2,3,x,y,z;
518//   j; print(M);
519//   ring S=0,(a,b,c),ds;
520//   fetchall(R);       //map from R to S: x->a, y->b, z->c;
521//   names(S);
522//   j; print(M);
523//   fetchall(S,"1");   //identity map of S: copy objects, change names
524//   names(S);
525//   kill R,S;
526}
527///////////////////////////////////////////////////////////////////////////////
528
529proc imapall (R, list #)
530"USAGE:   imapall(R[,s]);  R=ring/qring, s=string
531CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
532         matrix) into the basering, by applying imap to all objects of R.
533         If no 3rd argument is present, the names are the same as in R. If,
534         say, f is a poly in R and the 3rd argument is the string \"R\", then f
535         is maped to f_R etc.
536RETURN:  no return value
537NOTE:    As imap, this procedure maps the variables of R to the variables with
538         the same name in the basering, the other variables are maped to 0.
539         The 3rd argument is useful in order to avoid conflicts of names, the
540         empty string is allowed
541CAUTION: imapall does not work inside a procedure
542         It does not work if R contains a map
543EXAMPLE: example imapall; shows an example
544"
545{
546   list @L@=names(R);
547   int @ii@; string @s@;
548   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
549   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
550   {
551         execute("def "+@L@[@ii@]+@s@+"=imap(R,`@L@[@ii@]`);");
552         execute("export "+@L@[@ii@]+@s@+";");
553   }
554   return();
555}
556example
557{  "EXAMPLE:"; echo = 2;
558// The example is not shown since imapall does not work in a procedure
559// (and hence not in the example procedure). Try the following commands:
560//   ring R=0,(x,y,z,u),dp;
561//   ideal j=x,y,z,u2+ux+z;
562//   matrix M[2][3]=1,2,3,x,y,uz;
563//   j; print(M);
564//   ring S=0,(a,b,c,x,z,y),ds;
565//   imapall(R);         //map from R to S: x->x, y->y, z->z, u->0
566//   names(S);
567//   j; print(M);
568//   imapall(S,"1");     //identity map of S: copy objects, change names
569//   names(S);
570//   kill R,S;
571}
572///////////////////////////////////////////////////////////////////////////////
573
574proc mapall (R, ideal i, list #)
575"USAGE:   mapall(R,i[,s]);  R=ring/qring, i=ideal of basering, s=string
576CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
577         matrix, map) into the basering, by mapping the jth variable of R to
578         the jth generator of the ideal i. If no 3rd argument is present, the
579         names are the same as in R. If, say, f is a poly in R and the 3rd
580         argument is the string \"R\", then f is maped to f_R etc.
581RETURN:  no return value.
582NOTE:    This procedure has the same effect as defining a map, say psi, by
583         map psi=R,i; and then applying psi to all objects of R. In particular,
584         maps from R to some ring S are composed with psi, creating thus a map
585         from the basering to S.
586         mapall may be combined with copyring to change vars for all objects.
587         The 3rd argument is useful in order to avoid conflicts of names, the
588         empty string is allowed.
589CAUTION: mapall does not work inside a procedure.
590EXAMPLE: example mapall; shows an example
591"
592{
593   list @L@=names(R); map @psi@ = R,i;
594   int @ii@; string @s@;
595   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
596   for( @ii@=size(@L@); @ii@>0; @ii@=@ii@-1 )
597   {
598      execute("def "+@L@[@ii@]+@s@+"=@psi@(`@L@[@ii@]`);");
599      execute("export "+@L@[@ii@]+@s@+";");
600   }
601   return();
602}
603example
604{  "EXAMPLE:"; echo = 2;
605// The example is not shown since mapall does not work in a procedure
606// (and hence not in the example procedure). Try the following commands:
607//   ring R=0,(x,y,z),dp;
608//   ideal j=x,y,z;
609//   matrix M[2][3]=1,2,3,x,y,z;
610//   map phi=R,x2,y2,z2;
611//   ring S=0,(a,b,c),ds;
612//   ideal i=c,a,b;
613//   mapall(R,i);         //map from R to S: x->c, y->a, z->b
614//   names(S);
615//   j; print(M); phi;    //phi maps R to S: x->c2, y->a2, z->b2
616//   ideal i1=a2,a+b,1;
617//   mapall(R,i1,\"\");   //map from R to S: x->a2, y->a+b, z->1
618//   names(S);
619//   j_; print(M_); phi_;
620//   changevar(\"T\",\"x()\",R);  //change vars in R and call result T
621//   mapall(R,maxideal(1));       //identity map from R to T
622//   names(T);
623//   j; print(M); phi;
624//   kill R,S,T;
625}
626///////////////////////////////////////////////////////////////////////////////
627
628proc ord_test (r)
629"USAGE:   ord_test(r);  r ring
630RETURN:  int 1 (resp. -1, resp. 0) if ordering of r is global (resp. local,
631         resp. mixed)
632EXAMPLE: example ord_test; shows an example
633"
634{
635   if (typeof(r) != "ring")
636   {
637      "// ord_test requires a ring as input";
638      return();
639   }
640   def BAS = basering;
641   setring r;
642   poly f;
643   int n,o,u = nvars(r),1,1;
644   int ii;
645   for ( ii=1; ii<=n; ii++ )
646   {
647      f = 1+var(ii);
648      o = o*(lead(f) == var(ii));
649      u = u*(lead(f) == 1);
650   }
651   setring BAS;
652   if ( o==1 ) { return(1); }
653   if ( u==1 ) { return(-1); }
654   else { return(0); }
655}
656example
657{ "EXAMPLE:"; echo = 2;
658   ring R = 0,(x,y),dp;
659   ring S = 0,(u,v),ls;
660   ord_test(R);
661   ord_test(S);
662   ord_test(R+S);   
663}
664///////////////////////////////////////////////////////////////////////////////
665
666proc ringtensor (string s, list #)
667"USAGE:   ringtensor(s,r1,r2,...); s=string, r1,r2,...=rings
668CREATE:  A new base ring with name `s` if r1,r2,... are existing rings.
669         If, say, s = \"R\" and the rings r1,r2,... exist, the new ring will
670         have name R, variables from all rings r1,r2,... and as monomial
671         ordering the block (product) ordering of r1,r2,... . Hence, R
672         is the tensor product of the rings r1,r2,... with ordering matrix
673         equal to the direct sum of the ordering matrices of r1,r2,...
674RETURN:  no return value
675NOTE:    The characteristic of the new ring will be that of r1. The names of
676         variables in the rings r1,r2,... should differ (if a name, say x,
677         occurs in r1 and r2, then, in the new ring r, x always refers to the
678         variable with name x in r1, there is no access to x in r2).
679         The procedure works also for quotient rings ri, if the characteristic
680         of ri is compatible with the characteristic of r1 (i.e. if imap from
681         ri to r1 is implemented)
682         This proc uses 'execute' or calls a procedure using 'execute'.
683         If you use it in your own proc, let the local names of your proc
684         start with @ (see the file HelpForProc)
685EXAMPLE: example ringtensor; shows an example
686"
687{
688   int @ii,@q;
689   int @n = size(#);
690   string @vars,@order,@oi,@s1;
691//---- gather variables, orderings and ideals (of qrings) from given rings ----
692   for(@ii=1; @ii<=@n; @ii=@ii+1)
693   {
694      if( ordstr(#[@ii])[1]=="C" or ordstr(#[@ii])[1]=="c" )
695           { @oi=ordstr(#[@ii])[3,size(ordstr(#[@ii]))-2]; }
696      else { @oi=ordstr(#[@ii])[1,size(ordstr(#[@ii]))-2]; }
697      @vars = @vars+varstr(#[@ii])+",";
698      @order= @order+@oi+",";
699      def @r(@ii)=#[@ii];
700      setring @r(@ii);
701      ideal i(@ii)=ideal(@r(@ii));
702      int @q(@ii)=size(i(@ii));
703      @q=@q+@q(@ii);
704   }
705   if( @q!=0 ) { @s1 = "@newr"; }   // @q=0 iff none of the rings ri is a qring
706   else {  @s1 = s; }
707//------------------------------- create new ring -----------------------------
708   string @newring ="=("+charstr(#[1])+"),("+@vars[1,size(@vars)-1]+"),("
709                  +@order[1,size(@order)-1]+");";
710   execute("ring "+@s1+@newring);
711//------ create ideal for new ring if one of the given rings is a qring -------
712   if( @q!=0 )
713   {
714      ideal i;
715      for(@ii=1; @ii<=@n; @ii=@ii+1)
716      {
717         if( @q(@ii)!=0 )
718         {
719            i=i+imap(@r(@ii),i(@ii));
720         }
721      }
722      i=std(i);
723      execute("qring "+s+"=i;");
724   }
725//----------------------- export and keep created ring ------------------------
726   export(`s`);
727   keepring(`s`);
728   if (voice==2) { "// basering is now",s; }
729   return();
730}
731example
732{ "EXAMPLE:"; echo = 2;
733   ring r=32003,(x,y,u,v),dp;
734   ring s=0,(a,b,c),wp(1,2,3);
735   ring t=0,x(1..5),(c,ls);
736   ringtensor("R",r,s,t);
737   type R;
738   setring s;
739   ideal i = a2+b3+c5;
740   changevar("S","x,y,z");       //change vars of sand make S the basering
741   qring qS =std(fetch(s,i));    //create qring of S mod i (maped to S)
742   changevar("T","d,e,f,g,h",t); //change vars of t and make T the basering
743   qring qT=std(d2+e2-f3);       //create qring of T mod d2+e2-f3
744   ringtensor("Q",s,qS,t,qT);
745   type Q;
746   kill R,Q,S,T;
747   if(system("with","Namespaces")) {
748      if( nameof(Current) == "Ring" ) {
749        kill Top::R,Top::Q,Top::S,Top::T;
750      } else {
751        kill Ring::R,Ring::Q,Ring::S,Ring::T;
752      }
753   }
754}
755///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.