source: git/Singular/LIB/ring.lib @ 5480da

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