source: git/Singular/LIB/ring.lib @ 291c20

fieker-DuValspielwiese
Last change on this file since 291c20 was 810381, checked in by Hans Schoenemann <hannes@…>, 6 years ago
chg: version/date of libs, p2
  • Property mode set to 100644
File size: 39.7 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2version="version ring.lib 4.1.1.0 Dec_2017 "; // $Id$
3category="General purpose";
4info="
5LIBRARY:  ring.lib      Manipulating Rings and Maps
6AUTHORS: Singular team
7
8PROCEDURES:
9 changechar(c[,r]); make a copy of basering [ring r] with new char c
10 changeord(o[,r]);  make a copy of basering [ring r] with new ord o
11 changevar(v[,r]);  make a copy 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(s,t,..);      create ring, tensor product of rings s,t,...
21 ringweights(r);          intvec of weights of ring variables of ring r
22 preimageLoc(R,phi,Q)     computes preimage for non-global orderings
23 rootofUnity(n);          the minimal polynomial for the n-th primitive root of unity
24             (parameters in square brackets [] are optional)
25 optionIsSet(opt)         check if as a string given option is set or not.
26 hasFieldCoefficient      check if the coefficient ring is considered a field
27 hasGFCoefficient         check if the coefficient ring is GF(p,k)
28 hasZpCoefficient         check if the coefficient ring is ZZ/p
29 hasZp_aCoefficient       check if the coefficient ring is an elag. ext. of ZZ/p
30 hasQQCoefficient         check if the coefficient ring is QQ
31 hasNumericCoeffs(rng)    check for use of floating point numbers
32 hasCommutativeVars(rng)  non-commutive or commnuative polynomial ring
33 hasGlobalOrdering(rng)   global versus mixed/local monomial ordering
34 hasMixedOrdering()       mixed versus global/local ordering
35 hasAlgExtensionCoefficient(r) coefficients are an algebraic extension
36 hasTransExtensionCoefficient(r) coefficients are rational functions
37 isQuotientRing(rng)      ring is a qotient ring
38 isSubModule(I,J)         check if I is in J as submodule
39
40 changeordTo(r,o)         change the ordering of a ring to a simple one
41 addvarsTo(r,vars,i)      add variables to a ring
42 addNvarsTo(r,N,name,i)   add N variables to a ring
43";
44
45LIB "inout.lib";
46LIB "general.lib";
47LIB "primdec.lib";
48
49///////////////////////////////////////////////////////////////////////////////
50proc optionIsSet(string optionName)
51"
52USAGE:       optionIsSet( optionName )
53PARAMETERS:  optionName: a name as string of an option of interest
54RETURN:      true, if the by optionName given option is active, false otherwise.
55EXAMPLE:     example optionIsSet;
56"
57{
58   intvec op = option(get);
59   //sanity check, if option is valid. will raise an error if not
60   option(optionName);    option("no" + optionName);
61   option(set,op);
62   // first entry is currently a comment "//options:", which is not an option.
63   int pos = find(option(), optionName, 11 );
64   return(pos>0);
65}
66example
67{
68    // check if the option "warn" is set.
69    optionIsSet("warn");
70    option("warn");
71    // now the option is set
72    optionIsSet("warn");
73
74    option("nowarn");
75    // now the option is unset
76    optionIsSet("warn");
77}
78
79
80static proc testOptionIsSet()
81{
82     option("warn");
83     ASSUME(0, optionIsSet("warn") );
84     option("nowarn");
85     ASSUME(0, 0 == optionIsSet("warn") );
86}
87
88///////////////////////////////////////////////////////////////////////////////
89
90proc changechar (list @L, list #)
91"USAGE:   changechar(c[,r]);  c=list, r=ring
92RETURN:  ring R, obtained from the ring r [default: r=basering], by changing
93         ringlist(r)[1] to c.
94EXAMPLE: example changechar; shows an example
95"
96{
97   def save_ring=basering;
98   if( size(#)==0 ) { def @r=basering; }
99   if(( size(#)==1 ) and (typeof(#[1])=="ring")) { def @r=#[1]; }
100   setring @r;
101   list rl=ringlist(@r);
102   if(defined(@L)!=voice) { def @L=fetch(save_ring,@L); }
103   if (size(@L)==1) { rl[1]=@L[1];} else { rl[1]=@L;}
104   def Rnew=ring(rl);
105   setring save_ring;
106   return(Rnew);
107}
108example
109{  "EXAMPLE:"; echo = 2;
110   ring rr=2,A,dp;
111   ring r=0,(x,y,u,v),(dp(2),ds);
112   def R=changechar(ringlist(rr)); R;"";
113   def R1=changechar(32003,R); setring R1; R1;
114   kill R,R1;
115}
116///////////////////////////////////////////////////////////////////////////////
117
118proc changeord (list @o, list #)
119"USAGE:   changeord(neword[,r]);  newordstr=list, r=ring/qring
120RETURN:  ring R, obtained from the ring r [default: r=basering], by changing
121         order(r) to neword.
122         If, say, neword=list(list(\"wp\",intvec(2,3)),list(list(\"dp\",1:(n-2))));
123         and if the ring r exists and has n variables, the ring R will be
124         equipped with the monomial ordering wp(2,3),dp.
125EXAMPLE: example changeord; shows an example
126"
127{
128   def save_ring=basering;
129   if( size(#)==0 ) { def @r=basering; }
130   if( size(#)==1 ) { def @r=#[1]; }
131   setring @r;
132   list rl=ringlist(@r);
133   rl[3]=@o;
134   def Rnew=ring(rl);
135   setring save_ring;
136   return(Rnew);
137}
138example
139{  "EXAMPLE:"; echo = 2;
140   ring r=0,(x,y,u,v),(dp(2),ds);
141   def R=changeord(list(list("wp",intvec(2,3)),list("dp",1:2))); R; "";
142   ideal i = x^2,y^2-u^3,v;
143   qring Q = std(i);
144   def Q'=changeord(list(list("lp",nvars(Q))),Q); setring Q'; Q';
145   kill R,Q,Q';
146}
147///////////////////////////////////////////////////////////////////////////////
148
149proc changevar (string vars, list #)
150"USAGE:   changevar(vars[,r]);  vars=string, r=ring/qring
151RETURN:  ring R, obtained from the ring r [default: r=basering], by changing
152         varstr(r) according to the value of vars.
153         If, say, vars = \"t()\" and the ring r exists and has n
154         variables, the new basering will have name R and variables
155         t(1),...,t(n).
156         If vars = \"a,b,c,d\", the new ring will have the variables a,b,c,d.
157NOTE:    This procedure is useful in connection with the procedure ringtensor,
158         when a conflict between variable names must be avoided.
159         This proc uses 'execute' or calls a procedure using 'execute'.
160EXAMPLE: example changevar; shows an example
161"
162{
163   if( size(#)==0 ) { def @r=basering; }
164   if( size(#)==1 ) { def @r=#[1]; }
165   setring @r;
166   ideal i = ideal(@r); int @q = size(i);
167   if( @q!=0 )
168      { string @s = "Rnew1"; }
169   else
170      { string @s = "Rnew"; }
171   string @newring = @s+"=("+charstr(@r)+"),(";
172   if( vars[size(vars)-1]=="(" and vars[size(vars)]==")" )
173   {
174      @newring = @newring+vars[1,size(vars)-2]+"(1.."+string(nvars(@r))+")";
175   }
176   else { @newring = @newring+vars; }
177   string ords=ordstr(@r);
178   int l=size(ords);
179   int l1,l2;
180   while(l>0)
181   {
182     if (ords[l]=="(") { l1=l; break; }
183     if (ords[l]==")") { l2=l; }
184     l--;
185   }
186   string last_ord=string(ords[l1-3..l1-1]);
187   if ((last_ord[1]!="w")
188   && (last_ord[1]!="W")
189   && (last_ord[2]!="M"))
190   {
191     if (l2==size(ords)) { ords=string(ords[1..l1-1]); }
192     else { ords=string(ords[1..l1-1])+string(ords[l2+1..size(ords)]); }
193   }
194   @newring = @newring+"),("+ords+");";
195   execute("ring "+@newring);
196   if( @q!=0 )
197   {
198      map phi = @r,maxideal(1);
199      ideal i = phi(i);
200      attrib(i,"isSB",1);         //*** attrib funktioniert ?
201      qring Rnew=i;
202   }
203   return(Rnew);
204}
205example
206{  "EXAMPLE:"; echo = 2;
207   ring r=0,(x,y,u,v),(dp(2),ds);
208   ideal i = x^2,y^2-u^3,v;
209   qring Q = std(i);
210   setring(r);
211   def R=changevar("A()"); R; "";
212   def Q'=changevar("a,b,c,d",Q); setring Q'; Q';
213   kill R,Q,Q';
214}
215///////////////////////////////////////////////////////////////////////////////
216
217proc defring (string s2, int n, string s3, string s4)
218"USAGE:   defring(ch,n,va,or);  ch,va,or=strings, n=integer
219RETURN:  ring R with characteristic 'ch', ordering 'or' and n variables with
220         names derived from va.
221         If va is a single letter, say va=\"a\", and if n<=26 then a and the
222         following n-1 letters from the alphabet (cyclic order) are taken as
223         variables. If n>26 or if va is a single letter followed by a bracket,
224         say va=\"T(\", the variables are T(1),...,T(n).
225NOTE:    This proc is useful for defining a ring in a procedure.
226         This proc uses 'execute' or calls a procedure using 'execute'.
227EXAMPLE: example defring; shows an example
228"
229{
230   string @newring = "ring newring =("+s2+"),(";
231   if( n>26 or s3[2]=="(" ) { string @v = s3[1]+"(1.."+string(n)+")"; }
232   else { string @v = A_Z(s3,n); }
233   @newring=@newring+@v+"),("+s4+");";
234   execute(@newring);
235   return(newring);
236}
237example
238{ "EXAMPLE:"; echo = 2;
239   def r=defring("0",5,"u","ls"); r; setring r;"";
240   def R=defring("2,A",10,"x(","dp(3),ws(1,2,3),ds"); R; setring R;
241   kill R,r;
242}
243///////////////////////////////////////////////////////////////////////////////
244
245proc defrings (int n, list #)
246"USAGE:   defrings(n,[p]);  n,p integers
247RETURN:  ring R with characteristic p [default: p=32003], ordering ds and n
248         variables x,y,z,a,b,...if n<=26 (resp. x(1..n) if n>26)
249NOTE:    This proc uses 'execute' or calls a procedure using 'execute'.
250EXAMPLE: example defrings; shows an example
251"
252{
253   int p;
254   if (size(#)==0) { p=32003; }
255   else { p=#[1]; }
256   if (n >26)
257   {
258      string s="ring S ="+string(p)+",x(1.."+string(n)+"),ds;";
259   }
260   else
261   {
262      string s="ring S ="+string(p)+",("+A_Z("x",n)+"),ds;";
263   }
264   execute(s);
265   dbprint(printlevel-voice+2,"
266// 'defrings' created a ring. To see the ring, type (if the name R was
267// assigned to the return value):
268    show R;
269// To make the ring the active basering, type
270    setring R; ");
271   return(S);
272}
273example
274{ "EXAMPLE:"; echo = 2;
275   def S5=defrings(5,0); S5; "";
276   def S30=defrings(30); S30;
277   kill S5,S30;
278}
279///////////////////////////////////////////////////////////////////////////////
280
281proc defringp (int n,list #)
282"USAGE:   defringp(n,[p]);  n,p=integers
283RETURN:  ring R with characteristic p [default: p=32003], ordering dp and n
284         variables x,y,z,a,b,...if n<=26 (resp. x(1..n) if n>26)
285NOTE:    This proc uses 'execute' or calls a procedure using 'execute'.
286EXAMPLE: example defringp; shows an example
287"
288{
289   int p;
290   if (size(#)==0) { p=32003; }
291   else { p=#[1]; }
292   if (n >26)
293   {
294      string s="ring P="+string(p)+",x(1.."+string(n)+"),dp;";
295   }
296   else
297   {
298     string s="ring P="+string(p)+",("+A_Z("x",n)+"),dp;";
299   }
300   execute(s);
301   dbprint(printlevel-voice+2,"
302// 'defringp' created a ring. To see the ring, type (if the name R was
303// assigned to the return value):
304    show R;
305// To make the ring the active basering, type
306    setring R; ");
307   return(P);
308}
309example
310{ "EXAMPLE:"; echo = 2;
311   def P5=defringp(5,0); P5; "";
312   def P30=defringp(30); P30;
313   kill P5,P30;
314}
315///////////////////////////////////////////////////////////////////////////////
316
317proc extendring (int n, string va, string o, list #)
318"USAGE:   extendring(n,va,o[,iv,i,r]);  va,o=strings, n,i=integers, r=ring,
319          iv=intvec of positive integers or iv=0
320RETURN:  ring R, which extends the ring r by adding n new variables in front
321         of (resp. after, if i!=0) the old variables.
322         [default: (i,r)=(0,basering)].
323@*       -- The characteristic is the characteristic of r.
324@*       -- The new vars are derived from va. If va is a single letter, say
325            va=\"T\", and if n<=26 then T and the following n-1 letters from
326            T..Z..T (resp. T(1..n) if n>26) are taken as additional variables.
327            If va is a single letter followed by a bracket, say va=\"x(\",
328            the new variables are x(1),...,x(n).
329@*       -- The ordering is the product ordering of the ordering of r and of an
330            ordering derived from `o` [and iv].
331@*        -  If o contains a 'c' or a 'C' in front resp. at the end, this is
332            taken for the whole ordering in front, resp. at the end. If o does
333            not contain a 'c' or a 'C' the same rule applies to ordstr(r).
334@*        -  If no intvec iv is given, or if iv=0, o may be any allowed ordstr,
335            like \"ds\" or \"dp(2),wp(1,2,3),Ds(2)\" or \"ds(a),dp(b),ls\" if
336            a and b are globally (!) defined integers and if a+b+1<=n.
337            If, however, a and b are local to a proc calling extendring, the
338            intvec iv must be used to let extendring know the values of a and b
339@*        -  If a non-zero intvec iv is given, iv[1],iv[2],... are taken for the
340            1st, 2nd,... block of o, if o contains no substring \"w\" or \"W\"
341            i.e. no weighted ordering (in the above case o=\"ds,dp,ls\"
342            and iv=a,b).
343            If o contains a weighted ordering (only one (!) weighted block is
344            allowed) iv[1] is taken as size for the weight-vector, the next
345            iv[1] values of iv are taken as weights and the remaining values of
346            iv as block size for the remaining non-weighted blocks.
347            e.g. o=\"dp,ws,Dp,ds\", iv=3,2,3,4,2,5 creates the ordering
348            dp(2),ws(2,3,4),Dp(5),ds
349NOTE:    This proc is useful for adding deformation parameters.
350         This proc uses 'execute' or calls a procedure using 'execute'.
351         If you use it in your own proc, it may be advisable to let the local
352         names of your proc start with a @
353EXAMPLE: example extendring; shows an example
354"
355{
356//--------------- initialization and place c/C of ordering properly -----------
357   string @o1,@o2,@ro,@wstr,@v,@newring;
358   int @i,@w,@ii,@k;
359   intvec @iv,@iw;
360   if( find(o,"c")+find(o,"C") != 0)
361   {
362      @k=1;
363      if( o[1]=="c" or o[1]=="C" ) { @o1=o[1,2]; o=o[3..size(o)]; }
364      else                         { @o2=o[size(o)-1,2]; o=o[1..size(o)-2]; }
365   }
366   if( size(#)==0 ) { #[1]=0; }
367   if( typeof(#[1])!="intvec" )
368   {
369     if( size(#)==1 ) { @i=#[1]; def @r=basering; }
370     if( size(#)==2 ) { @i=#[1]; def @r=#[2]; }
371     if( o[size(o)]!=")" and find(o,",")==0 ) { o=o+"("+string(n)+")"; }
372   }
373   else
374   {
375     @iv=#[1];
376     if( size(#)==2 ) { @i=#[2]; def @r=basering; }
377     if( size(#)==3 ) { @i=#[2]; def @r=#[3]; }
378     if( @iv==0 && o[size(o)]!=")" && find(o,",")==0 ) {o=o+"("+string(n)+")";}
379   }
380   @ro=ordstr(@r);
381   if( @ro[1]=="c" or @ro[1]=="C" )
382      { @v=@ro[1,2]; @ro=@ro[3..size(@ro)]; }
383   else
384      { @wstr=@ro[size(@ro)-1,2]; @ro=@ro[1..size(@ro)-2]; }
385   if( @k==0) { @o1=@v; @o2=@wstr; }
386//----------------- prepare ordering if an intvec is given --------------------
387   if( typeof(#[1])=="intvec" and #[1]!=0 )
388   {
389      @k=n;                             //@k counts no of vars not yet ordered
390      @w=find(o,"w")+find(o,"W");o=o+" ";
391      if( @w!=0 )
392      {
393         @wstr=o[@w..@w+1];
394         o=o[1,@w-1]+"@"+o[@w+2,size(o)];
395         @iw=@iv[2..@iv[1]+1];
396         @wstr=@wstr+"("+string(@iw)+")";
397         @k=@k-@iv[1];
398         @iv=@iv[@iv[1]+2..size(@iv)];
399         @w=0;
400      }
401      for( @ii=1; @ii<=size(@iv); @ii=@ii+1 )
402      {
403         if( find(o,",",@w+1)!=0 )
404         {
405            @w=find(o,",",@w+1);
406            if( o[@w-1]!="@" )
407            {
408               o=o[1,@w-1]+"("+string(@iv[@ii])+")"+o[@w,size(o)];
409               @w=find(o,",",@w+1);
410               @k=@k-@iv[@ii];
411            }
412            else { @ii=@ii-1; }
413         }
414      }
415      @w=find(o,"@");
416      if( @w!=0 ) { o=o[1,@w-1] + @wstr + o[@w+1,size(o)]; }
417      if( @k>0 and o[size(o)]!=")" ) { o=o+"("+string(@k)+")"; }
418   }
419//------------------------ prepare string of new ring -------------------------
420   @newring = "ring na =("+charstr(@r)+"),(";
421   if( n>26 or va[2]=="(" ) { @v = va[1]+"(1.."+string(n)+")"; }
422   else                     { @v = A_Z(va,n); }
423   if( @i==0 )
424   {
425      @v=@v+","+varstr(@r);
426      o=@o1+o+","+@ro+@o2;
427   }
428   else
429   {
430      @v=varstr(@r)+","+@v;
431      o=@o1+@ro+","+o+@o2;
432   }
433   @newring=@newring+@v+"),("+o+");";
434//---------------------------- execute and export -----------------------------
435   execute(@newring);
436   dbprint(printlevel-voice+2,"
437// 'extendring' created a new ring.
438// To see the ring, type (if the name 'R' was assigned to the return value):
439     show(R);
440");
441
442   return(na);
443}
444example
445{ "EXAMPLE:"; echo = 2;
446   ring r=0,(x,y,z),ds;
447   show(r);"";
448   // blocksize is derived from no of vars:
449   int t=5;
450   def R1=extendring(t,"a","dp");         //t global: "dp" -> "dp(5)"
451   show(R1); setring R1; "";
452   def R2=extendring(4,"T(","c,dp",1,r);    //"dp" -> "c,..,dp(4)"
453   show(R2); setring R2; "";
454
455   // no intvec given, blocksize given: given blocksize is used:
456   def R3=extendring(4,"T(","dp(2)",0,r);   // "dp(2)" -> "dp(2)"
457   show(R3); setring R3; "";
458
459   // intvec given: weights and blocksize is derived from given intvec
460   // (no specification of a blocksize in the given ordstr is allowed!)
461   // if intvec does not cover all given blocks, the last block is used
462   // for the remaining variables, if intvec has too many components,
463   // the last ones are ignored
464   intvec v=3,2,3,4,1,3;
465   def R4=extendring(10,"A","ds,ws,Dp,dp",v,0,r);
466   // v covers 3 blocks: v[1] (=3) : no of components of ws
467   // next v[1] values (=v[2..4]) give weights
468   // remaining components of v are used for the remaining blocks
469   show(R4);
470   kill r,R1,R2,R3,R4;
471}
472///////////////////////////////////////////////////////////////////////////////
473
474proc fetchall (def R, list #)
475"USAGE:   fetchall(R[,s]);  R=ring/qring, s=string
476CREATE:  fetch all objects of ring R (of type poly/ideal/vector/module/number/matrix)
477         into the basering.
478         If no 2nd argument is present, the names are the same as in R. If,
479         say, f is a polynomial in R and the 2nd argument is the string \"R\", then f
480         is mapped to f_R etc.
481RETURN:  no return value
482NOTE:    As fetch, this procedure maps the 1st, 2nd, ... variable of R to the
483         1st, 2nd, ... variable of the basering.
484         The 2nd argument is useful in order to avoid conflicts of names, the
485         empty string is allowed
486CAUTION: fetchall does not work for locally defined names.
487         It does not work if R contains a map.
488SEE ALSO: imapall
489EXAMPLE: example fetchall; shows an example
490"
491{
492   list @L@=names(R);
493   int @ii@; string @s@;
494   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
495   for( @ii@=size(@L@); @ii@>0; @ii@-- )
496   {
497      execute("def "+@L@[@ii@]+@s@+"=fetch(R,`@L@[@ii@]`);");
498      execute("export "+@L@[@ii@]+@s@+";");
499   }
500   return();
501}
502example
503{  "EXAMPLE:"; echo=2;
504// The example is not shown since fetchall does not work in a procedure;
505// (and hence not in the example procedure). Try the following commands:
506//   ring R=0,(x,y,z),dp;
507//   ideal j=x,y2,z2;
508//   matrix M[2][3]=1,2,3,x,y,z;
509//   j; print(M);
510//   ring S=0,(a,b,c),ds;
511//   fetchall(R);       //map from R to S: x->a, y->b, z->c;
512//   names(S);
513//   j; print(M);
514//   fetchall(S,"1");   //identity map of S: copy objects, change names
515//   names(S);
516//   kill R,S;
517}
518///////////////////////////////////////////////////////////////////////////////
519
520proc imapall (def R, list #)
521"USAGE:   imapall(R[,s]);  R=ring/qring, s=string
522CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/matrix)
523         into the basering by applying imap to all objects of R.
524         If no 2nd argument is present, the names are the same as in R. If,
525         say, f is a polynomial in R and the 3rd argument is the string \"R\", then f
526         is mapped to f_R etc.
527RETURN:  no return value
528NOTE:    As imap, this procedure maps the variables of R to the variables with
529         the same name in the basering, the other variables are mapped to 0.
530         The 2nd argument is useful in order to avoid conflicts of names, the
531         empty string is allowed
532CAUTION: imapall does not work for locally defined names.
533         It does not work if R contains a map
534SEE ALSO: fetchall
535EXAMPLE: example imapall; shows an example
536"
537{
538   list @L@=names(R);
539   int @ii@; string @s@;
540   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
541   for( @ii@=size(@L@); @ii@>0; @ii@-- )
542   {
543         execute("def "+@L@[@ii@]+@s@+"=imap(R,`@L@[@ii@]`);");
544         execute("export "+@L@[@ii@]+@s@+";");
545   }
546   return();
547}
548example
549{  "EXAMPLE:"; echo = 2;
550// The example is not shown since imapall does not work in a procedure
551// (and hence not in the example procedure). Try the following commands:
552//   ring R=0,(x,y,z,u),dp;
553//   ideal j=x,y,z,u2+ux+z;
554//   matrix M[2][3]=1,2,3,x,y,uz;
555//   j; print(M);
556//   ring S=0,(a,b,c,x,z,y),ds;
557//   imapall(R);         //map from R to S: x->x, y->y, z->z, u->0
558//   names(S);
559//   j; print(M);
560//   imapall(S,"1");     //identity map of S: copy objects, change names
561//   names(S);
562//   kill R,S;
563}
564///////////////////////////////////////////////////////////////////////////////
565
566proc mapall (def R, ideal i, list #)
567"USAGE:   mapall(R,i[,s]);  R=ring/qring, i=ideal of basering, s=string
568CREATE:  map all objects of ring R (of type poly/ideal/vector/module/number/
569         matrix, map) into the basering by mapping the j-th variable of R to
570         the j-th generator of the ideal i. If no 3rd argument is present, the
571         names are the same as in R. If, say, f is a polynomial in R and the 3rd
572         argument is the string \"R\", then f is mapped to f_R etc.
573RETURN:  no return value.
574NOTE:    This procedure has the same effect as defining a map, say psi, by
575         map psi=R,i; and then applying psi to all objects of R. In particular,
576         maps from R to some ring S are composed with psi, creating thus a map
577         from the basering to S.
578         mapall may be combined with copyring to change vars for all objects.
579         The 3rd argument is useful in order to avoid conflicts of names, the
580         empty string is allowed.
581CAUTION: mapall does not work for locally defined names.
582EXAMPLE: example mapall; shows an example
583"
584{
585   list @L@=names(R); map @psi@ = R,i;
586   int @ii@; string @s@;
587   if( size(#) > 0 ) { @s@=@s@+"_"+#[1]; }
588   for( @ii@=size(@L@); @ii@>0; @ii@-- )
589   {
590      execute("def "+@L@[@ii@]+@s@+"=@psi@(`@L@[@ii@]`);");
591      execute("export "+@L@[@ii@]+@s@+";");
592   }
593   return();
594}
595example
596{  "EXAMPLE:"; echo = 2;
597// The example is not shown since mapall does not work in a procedure
598// (and hence not in the example procedure). Try the following commands:
599//   ring R=0,(x,y,z),dp;
600//   ideal j=x,y,z;
601//   matrix M[2][3]=1,2,3,x,y,z;
602//   map phi=R,x2,y2,z2;
603//   ring S=0,(a,b,c),ds;
604//   ideal i=c,a,b;
605//   mapall(R,i);         //map from R to S: x->c, y->a, z->b
606//   names(S);
607//   j; print(M); phi;    //phi maps R to S: x->c2, y->a2, z->b2
608//   ideal i1=a2,a+b,1;
609//   mapall(R,i1,\"\");     //map from R to S: x->a2, y->a+b, z->1
610//   names(S);
611//   j_; print(M_); phi_;
612//   changevar(\"T\",\"x()\",R);  //change vars in R and call result T
613//   mapall(R,maxideal(1));   //identity map from R to T
614//   names(T);
615//   j; print(M); phi;
616//   kill R,S,T;
617}
618///////////////////////////////////////////////////////////////////////////////
619
620proc ord_test (def r)
621"USAGE:   ord_test(r);  r ring/qring
622RETURN:  int 1 (resp. -1, resp. 0) if ordering of r is global (resp. local,
623         resp. mixed)
624SEE ALSO: attrib
625EXAMPLE: example ord_test; shows an example
626"
627{
628   if (typeof(r) != "ring")
629   {
630      ERROR("ord_test requires a ring/qring as input");
631   }
632   if (attrib(r,"global")==1) { return(1);}
633   def BAS = basering;
634   setring r;
635   poly f;
636   int n,o,u = nvars(r),1,1;
637   int ii;
638   for ( ii=1; ii<=n; ii++ )
639   {
640      f = 1+var(ii);
641      o = o*(lead(f) == var(ii));
642      u = u*(lead(f) == 1);
643   }
644   setring BAS;
645   if ( o==1 ) { return(1); }
646   if ( u==1 ) { return(-1); }
647   else { return(0); }
648}
649example
650{ "EXAMPLE:"; echo = 2;
651   ring R = 0,(x,y),dp;
652   ring S = 0,(u,v),ls;
653   ord_test(R);
654   ord_test(S);
655   ord_test(R+S);
656}
657///////////////////////////////////////////////////////////////////////////////
658
659proc ringtensor (list #)
660"USAGE:   ringtensor(r1,r2,...);  r1,r2,...=rings
661RETURN:  ring R whose variables are the variables from all rings r1,r2,...
662         and whose monomial ordering is the block (product) ordering of the
663         respective monomial orderings of r1,r2,... . Hence, R
664         is the tensor product of the rings r1,r2,... with ordering matrix
665         equal to the direct sum of the ordering matrices of r1,r2,...
666NOTE:    The characteristic of the new ring will be p if one ring has
667         characteristic p. The names of variables in the rings r1,r2,...
668         must differ.
669         The procedure works also for quotient rings ri, if the characteristic
670         of ri is compatible with the characteristic of the result
671         (i.e. if imap from ri to the result is implemented)
672SEE ALSO: ring operations
673EXAMPLE: example ringtensor; shows an example
674"
675{
676   int @i;
677   int @n = size(#);
678   if (@n<=1) { ERROR("at least 2 rings required"); }
679   def @s=#[1]+#[2];
680   for (@i=3; @i<=@n;@i++)
681   {
682     def @ss=@s+#[@i];
683     kill @s;
684     def @s=@ss;
685     kill @ss;
686   }
687   dbprint(printlevel-voice+2,"
688// 'ringtensor' created a ring. To see the ring, type (if the name R was
689// assigned to the return value):
690    show(R);
691// To make the ring the active basering, type
692    setring R; ");
693   return(@s);
694}
695example
696{ "EXAMPLE:"; echo = 2;
697   ring r=32003,(x,y,u,v),dp;
698   ring s=0,(a,b,c),wp(1,2,3);
699   ring t=0,x(1..5),(c,ls);
700   def R=ringtensor(r,s,t);
701   type R;
702   setring s;
703   ideal i = a2+b3+c5;
704   def S=changevar("x,y,z");       //change vars of s
705   setring S;
706   qring qS =std(fetch(s,i));      //create qring of S mod i (mapped to S)
707   def T=changevar("d,e,f,g,h",t); //change vars of t
708   setring T;
709   qring qT=std(d2+e2-f3);         //create qring of T mod d2+e2-f3
710   def Q=ringtensor(s,qS,t,qT);
711   setring Q; type Q;
712   kill R,S,T,Q;
713}
714///////////////////////////////////////////////////////////////////////////////
715
716proc ringweights (def P)
717"USAGE:   ringweights(P); P=name of an existing ring (true name, not a string)
718RETURN:  intvec consisting of the weights of the variables of P, as they
719         appear when typing P;.
720NOTE:    This is useful when enlarging P but keeping the weights of the old
721         variables.
722EXAMPLE: example ringweights; shows an example
723"
724{
725   int i;
726   intvec rw;
727//------------------------- find weights  -------------------------
728   for(i=nvars(P);i>0;i--)
729   { rw[i]=ord(var(i)); }
730   return(rw);
731}
732example
733{"EXAMPLE:";  echo = 2;
734  ring r0 = 0,(x,y,z),dp;
735  ringweights(r0);
736  ring r1 = 0,x(1..5),(ds(3),wp(2,3));
737  ringweights(r1);"";
738  // an example for enlarging the ring, keeping the first weights:
739  intvec v = ringweights(r1),6,2,3,4,5;
740  ring R = 0,x(1..10),(a(v),dp);
741  ordstr(R);
742}
743///////////////////////////////////////////////////////////////////////////////
744proc preimageLoc(string R_name,string phi_name,string Q_name )
745"USAGE: preimageLoc ( ring_name, map_name, ideal_name );
746        all input parameters of type string
747RETURN:  ideal
748PURPOSE: compute the preimage of an ideal under a given map for non-global
749         orderings.
750         The 2nd argument has to be the name of a map from the basering to
751         the given ring (or the name of an ideal defining such a map), and
752         the ideal has to be an ideal in the given ring.
753SEE ALSO: preimage
754KEYWORDS: preimage under a map between local rings, map between local rings, map between local and global rings
755EXAMPLE: example preimageLoc ; shows an example
756"{
757  def S=basering;
758  int i;
759  string newRing,minpoly_string;
760  if(attrib(S,"global")!=1)
761  {
762    if(size(ideal(S))>0) /*qring*/
763    {
764      ideal I=ideal(S);
765      newRing="ring S0=("+charstr(S)+"),("+varstr(S)+"),dp;";
766      minpoly_string=string(minpoly);
767      execute(newRing);
768      execute("minpoly="+minpoly_string+";");
769      ideal I=imap(S,I);
770      list pr=primdecGTZ(I);
771      newRing="ring SL=("+charstr(S)+"),("+varstr(S)+"),("+ordstr(S)+");";
772      execute(newRing);
773      execute("minpoly="+minpoly_string+";");
774      list pr=imap(S0,pr);
775      ideal I0=std(pr[1][1]);
776      for(i=2;i<=size(pr);i++)
777      {
778         I0=intersect(I0,std(pr[i][1]));
779      }
780      setring S0;
781      ideal I0=imap(SL,I0);
782      qring S1=std(I0);
783    }
784    else
785    {
786      def S1=S;
787    }
788  }
789  else
790  {
791    def S1=S;
792  }
793  def @R=`R_name`;
794  setring @R;
795  def @phi=`phi_name`;
796  ideal phiId=ideal(@phi);
797  def Q=`Q_name`;
798  if(attrib(@R,"global")!=1)
799  {
800    if(size(ideal(@R))>0) /*qring*/
801    {
802      ideal J=ideal(@R);
803      newRing="ring R0=("+charstr(@R)+"),("+varstr(@R)+"),dp;";
804      minpoly_string=string(minpoly);
805      execute(newRing);
806      execute("minpoly="+minpoly_string+";");
807      ideal J=imap(@R,J);
808      list pr=primdecGTZ(J);
809      newRing="ring RL=("+charstr(@R)+"),("+varstr(@R)+"),("+ordstr(@R)+");";
810      execute(newRing);
811      execute("minpoly="+minpoly_string+";");
812      list pr=imap(R0,pr);
813      ideal J0=std(pr[1][1]);
814      for(i=2;i<=size(pr);i++)
815      {
816         J0=intersect(J0,std(pr[i][1]));
817      }
818      setring R0;
819      ideal J0=imap(RL,J0);
820      qring R1=std(J0);
821      ideal Q=imap(@R,Q);
822      map @phi=S1,imap(@R,phiId);
823    }
824    else
825    {
826      def R1=@R;
827    }
828  }
829  else
830  {
831    def R1=@R;
832  }
833  setring S1;
834  ideal preQ=preimage(R1,@phi,Q);
835  setring S;
836  ideal prQ=imap(S1,preQ);
837  return(prQ);
838}
839example
840{ "EXAMPLE:"; echo=2;
841  ring S =0,(x,y,z),dp;
842  ring R0=0,(x,y,z),ds;
843  qring R=std(x+x2);
844  map psi=S,x,y,z;
845  ideal null;
846  setring S;
847  ideal nu=preimageLoc("R","psi","null");
848  nu;
849}
850
851//////////////////////////////////////////////////////////////////////////////
852/* moved here from the nctools.lib */
853///////////////////////////////////////////////////////////////////////////////
854proc rootofUnity(int n)
855"USAGE:  rootofUnity(n); n an integer
856RETURN:  number
857PURPOSE: compute the minimal polynomial for the n-th primitive root of unity
858NOTE: works only in field extensions by one element
859EXAMPLE: example rootofUnity; shows examples
860"
861{
862  if ( npars(basering) !=1 )
863  {
864    ERROR(" the procedure works only with one ring parameter variable");
865  }
866  if (n<0) {  ERROR(" cannot compute ("+string(n)+")-th primitive root of unity"); }
867  if (n==0) { return(number(0));}
868  number mp = par(1);
869  if (n==1) { return(mp-1); }
870  if (n==2) { return(mp+1); }
871  def OldRing = basering;
872  string CH = charstr(basering);
873  string MCH;
874  int j=1;
875  while ( (CH[j] !=",") && (j<=size(CH)))
876  {
877    MCH=MCH+CH[j]; j++;
878  }
879  string SR = "ring @@rR="+MCH+","+parstr(basering)+",dp;";
880  execute(SR);
881  poly @t=var(1)^n-1; // (x^2i-1)=(x^i-1)(x^i+1)
882  list l=factorize(@t);
883  ideal @l=l[1];
884  list @d;
885  int s=size(@l);
886  int d=deg(@l[s]);
887  int cnt=1;
888  poly res;
889  for (j=s-1; j>=1; j--)
890  {
891    if ( deg(@l[j]) > d) { d=deg(@l[j]); }
892  }
893  for (j=1; j<=s; j++)
894  {
895    if ( deg(@l[j]) == d) { @d[cnt]=@l[j]; cnt++; }
896  }
897
898  j=1;
899  int i;
900  number pw;
901
902  int @sized = size(@d);
903
904  if (@sized==1)
905  {
906       setring OldRing;
907       list @rl = imap(@@rR,@d);
908       mp = number(@rl[1]);
909       kill @@rR;
910       return(mp);
911  }
912  def @rng;
913
914  setring OldRing;
915
916  list rl = ringlist( OldRing);
917  while ( j<=@sized )
918  {
919     ASSUME(0, n%2 ==0);
920     setring OldRing;
921     @rng = ring(rl);
922     setring @rng;
923     list @rl = imap(@@rR,@d);
924     number mp = leadcoef( @rl[j] );
925     minpoly = mp;
926     number mp = minpoly;
927     number pw = par(1)^(n div 2);
928     if ( (pw != 1) || n==1 )  {  break;  }
929     j = j+1;
930  }
931  setring OldRing;
932  list @rl=imap(@@rR,@d);
933  mp = leadcoef( @rl[j] );
934  kill @@rR;
935  return(mp);
936}
937example
938{
939  "EXAMPLE:";echo=2;
940  ring r = (0,q),(x,y,z),dp;
941  rootofUnity(6);
942  rootofUnity(7);
943  minpoly = rootofUnity(8);
944  r;
945}
946
947proc isQuotientRing(def rng )
948"USAGE: isQuotientRing ( rng );
949RETURN:  1 if rng is a quotient ring, 0 otherwise.
950PURPOSE: check if typeof a rng "qring"
951KEYWORDS: qring ring ideal 'factor ring'
952EXAMPLE: example isQuotientRing ; shows an example
953"
954{
955    if ( defined(basering) )  {   def BAS=basering;  }
956    else { return (0); }
957
958    //access to quotient ideal will fail, if basering and rng differs.
959    setring rng;
960    int result =  ( size(ideal(rng)) != 0);
961
962    setring BAS;
963    return (result);
964}
965example
966{
967  "EXAMPLE:";echo=2;
968  ring rng = 0,x,dp;
969  isQuotientRing(rng); //no
970  // if a certain method does not support quotient rings,
971  // then a parameter test could be performed:
972   ASSUME( 0, 0==isQuotientRing(basering));
973
974  qring q= ideal(x);  // constructs rng/ideal(x)
975  isQuotientRing(q);  // yes
976}
977
978static proc testIsQuotientRing()
979{
980   ring rng7 = 7, x, dp;
981
982   ring rng = real,x,dp;
983   ASSUME(0, 0== isQuotientRing(rng) ) ;
984   ASSUME(0, 0== isQuotientRing(rng7) ) ;
985   ASSUME(0, char(basering)==0); // check that basering was not changed
986
987   qring qrng = 1;
988   ASSUME(0, isQuotientRing(qrng) ) ;
989
990   ring rng2 = integer,x,dp;
991   ASSUME(0, 0 == isQuotientRing(rng2) ) ;
992
993   qring qrng2=0;
994   ASSUME(0, not isQuotientRing(qrng2) ) ;
995
996   ring rng3 = 0,x,dp;
997   ASSUME(0, 0 == isQuotientRing(rng3) ) ;
998
999   qring qrng3=1;
1000   ASSUME(0, isQuotientRing(qrng3) ) ;
1001}
1002
1003proc hasFieldCoefficient(def rng )
1004"USAGE: hasFieldCoefficient ( rng );
1005RETURN:  1 if the coefficients form  (and are considered to be) a field, 0 otherwise.
1006KEYWORDS: ring coefficients
1007EXAMPLE: example hasFieldCoefficient; shows an example
1008SEE ALSO: attrib
1009"
1010{
1011  return (attrib(rng,"ring_cf")==0);
1012}
1013example
1014{
1015  "EXAMPLE:";echo=2;
1016  ring rng = integer,x,dp;
1017  hasFieldCoefficient(rng); //no
1018  // if a certain method supports only rings with integer coefficients,
1019  // then a parameter test could be performed:
1020  ring rng2 = 0, x, dp;
1021  hasFieldCoefficient(rng2);  // yes
1022}
1023
1024proc hasAlgExtensionCoefficient(def rng )
1025"USAGE: hasAlgExtensionCoefficient ( rng );
1026RETURN:  1 if the coeffcients are an algebraic extension, 0 otherwise.
1027KEYWORDS: ring coefficients
1028EXAMPLE: example hasAlgExtensionCoefficient; shows an example
1029"
1030{
1031  return(attrib(rng,"cf_class")==7);
1032}
1033example
1034{
1035  "EXAMPLE:";echo=2;
1036  ring rng = integer,x,dp;
1037  hasAlgExtensionCoefficient(rng); //no
1038  ring rng2 = (0,a), x, dp; minpoly=a2-1;
1039  hasAlgExtensionCoefficient(rng2);  // yes
1040  ring rng3=(49,a),x,dp;
1041  hasAlgExtensionCoefficient(rng3);  // no
1042}
1043
1044proc hasTransExtensionCoefficient(def rng )
1045"USAGE: hasTransExtensionCoefficient ( rng );
1046RETURN:  1 if the coeffcients are rational functions, 0 otherwise.
1047KEYWORDS: ring coefficients
1048EXAMPLE: example hasTransExtensionCoefficient; shows an example
1049"
1050{
1051  return(attrib(rng,"cf_class")==8);
1052}
1053example
1054{
1055  "EXAMPLE:";echo=2;
1056  ring rng = integer,x,dp;
1057  hasTransExtensionCoefficient(rng); //no
1058  ring rng2 = (0,a), x, dp;
1059  hasTransExtensionCoefficient(rng2);  // yes
1060  ring rng3=(49,a),x,dp;
1061  hasTransExtensionCoefficient(rng3);  // no
1062}
1063
1064proc hasGFCoefficient(def rng )
1065"USAGE: hasGFCoefficient ( rng );
1066RETURN:  1 if the coeffcients are of the form GF(p,k), 0 otherwise.
1067KEYWORDS: ring coefficients
1068EXAMPLE: example hasGFCoefficient; shows an example
1069"
1070{
1071  //return((charstr(rng)!=string(char(rng))) &&
1072  //(npars(rng)==1) &&
1073  //(find(charstr(rng),string(char(rng)))!=1) &&
1074  //(charstr(basering)<>"real")&&
1075  //(charstr(basering)<>"complex") );
1076  return(attrib(rng,"cf_class")==4);
1077}
1078example
1079{
1080  "EXAMPLE:";echo=2;
1081  ring r1 = integer,x,dp;
1082  hasGFCoefficient(r1);
1083  ring r2 = (4,a),x,dp;
1084  hasGFCoefficient(r2);
1085  ring r3 = (2,a),x,dp;
1086  minpoly=a2+a+1;
1087  hasGFCoefficient(r2);
1088}
1089
1090proc hasZp_aCoefficient(def rng )
1091"USAGE: hasZp_aCoefficient ( rng );
1092RETURN:  1 if the coeffcients are of the form Zp_a(p,k), 0 otherwise.
1093KEYWORDS: ring coefficients
1094EXAMPLE: example hasZp_aCoefficient; shows an example
1095"
1096{
1097  return((attrib(rng,"cf_class")==7) and (char(rng)>0));
1098}
1099example
1100{
1101  "EXAMPLE:";echo=2;
1102  ring r1 = integer,x,dp;
1103  hasZp_aCoefficient(r1);
1104  ring r2 = (4,a),x,dp;
1105  hasZp_aCoefficient(r2);
1106  ring r3 = (2,a),x,dp;
1107  minpoly=a2+a+1;
1108  hasZp_aCoefficient(r2);
1109}
1110
1111proc hasZpCoefficient(def rng )
1112"USAGE: hasZpCoefficient ( rng );
1113RETURN:  1 if the coeffcients are of the form ZZ/p, 0 otherwise.
1114KEYWORDS: ring coefficients
1115EXAMPLE: example hasZpCoefficient; shows an example
1116"
1117{
1118  return(attrib(rng,"cf_class")==1);
1119}
1120example
1121{
1122  "EXAMPLE:";echo=2;
1123  ring r1 = integer,x,dp;
1124  hasZpCoefficient(r1);
1125  ring r2 = 7,x,dp;
1126  hasZpCoefficient(r2);
1127}
1128
1129proc hasQQCoefficient(def rng )
1130"USAGE: hasQQCoefficient ( rng );
1131RETURN:  1 if the coeffcients are QQ, 0 otherwise.
1132KEYWORDS: ring coefficients
1133EXAMPLE: example hasQQCoefficient; shows an example
1134"
1135{
1136  return(attrib(rng,"cf_class")==2);
1137}
1138example
1139{
1140  "EXAMPLE:";echo=2;
1141  ring r1 = integer,x,dp;
1142  hasQQCoefficient(r1);
1143  ring r2 = QQ,x,dp;
1144  hasQQCoefficient(r2);
1145}
1146
1147proc hasGlobalOrdering (def rng)
1148"USAGE: hasGlobalOrdering ( rng );
1149RETURN:  1 if rng has a global monomial ordering, 0 otherwise.
1150KEYWORDS: monomial ordering
1151EXAMPLE: example hasGlobalOrdering; shows an example
1152"
1153{
1154  return (attrib(rng,"global")==1);
1155}
1156example
1157{
1158  ring rng = integer,x,dp;
1159  hasGlobalOrdering(rng); //yes
1160  ring rng2 = 0, x, ds;
1161  hasGlobalOrdering(rng2);  // no
1162}
1163
1164proc hasCommutativeVars (def rng)
1165"USAGE: hasCommutativeVars ( rng );
1166RETURN:  1 if rng is a commutative polynomial ring, 0 otherwise.
1167KEYWORDS: plural
1168EXAMPLE: example hasCommutativeVars; shows an example
1169"
1170{
1171  list rl=ringlist(rng);
1172  return (size(rl)==4);
1173}
1174example
1175{
1176 ring r=0,(x,y,z),dp;
1177 hasCommutativeVars(r);
1178}
1179
1180proc hasNumericCoeffs(def rng)
1181"USAGE: hasNumericCoeffs ( rng );
1182RETURN:  1 if rng has inexact coeffcients, 0 otherwise.
1183KEYWORDS: floating point
1184EXAMPLE: example hasNumericCoeffs; shows an example
1185"
1186{
1187  return((attrib(rng,"cf_class")==3) /*real*/
1188  or     (attrib(rng,"cf_class")==5) /*gmp real*/
1189  or     (attrib(rng,"cf_class")==9) /*gmp complex*/);
1190}
1191example
1192{
1193  "EXAMPLE:";echo=2;
1194  ring r1 = integer,x,dp;
1195  hasNumericCoeffs(r1);
1196  ring r2 = complex,x,dp;
1197  hasNumericCoeffs(r2);
1198}
1199
1200
1201proc isSubModule(def I,def J)
1202"USAGE: isSubModule(I,J): I, J: ideal or module
1203RETURN: 1 if module(I) is in module(J), 0 otherwise
1204EXAMPLE: isSubModule; shows an example
1205{
1206  if (attrib(J,"isSB"))
1207  { return(size(reduce(I,J,5))==0); }
1208  else
1209  { return(size(reduce(I,groebner(J),5))==0); }
1210}
1211example
1212{
1213  "EXAMPLE:"; echo = 2;
1214  ring r=0,x,dp;
1215  ideal I1=x2;
1216  ideal I2=x3;
1217  isSubModule(I1, I2);
1218  isSubModule(I2, I1);
1219}
1220
1221proc hasMixedOrdering()
1222"USAGE:  hasMixedOrdering();
1223RETURN:  1 if ordering of basering is mixed, 0 else
1224EXAMPLE: example hasMixedOrdering(); shows an example
1225"
1226{
1227   int i,p,m;
1228   for(i = 1; i <= nvars(basering); i++)
1229   {
1230      if(var(i) > 1)
1231      {
1232         p++;
1233      }
1234      else
1235      {
1236         m++;
1237      }
1238   }
1239   if((p > 0) && (m > 0)) { return(1); }
1240   return(0);
1241}
1242example
1243{ "EXAMPLE:"; echo = 2;
1244   ring R1 = 0,(x,y,z),dp;
1245   hasMixedOrdering();
1246   ring R2 = 31,(x(1..4),y(1..3)),(ds(4),lp(3));
1247   hasMixedOrdering();
1248   ring R3 = 181,x(1..9),(dp(5),lp(4));
1249   hasMixedOrdering();
1250}
1251
1252proc changeordTo(def r,string o)
1253"USAGE:  changeordTo(ring, string s);
1254RETURN:  a ring with the oderinging changed to the (simple) ordering s
1255EXAMPLE: example changeordTo(); shows an example
1256"
1257{
1258  list rl=ringlist(r);
1259  rl[3]=list(list("C",0),list(o,1:nvars(r)));
1260  def rr=ring(rl);
1261  return(rr);
1262}
1263example
1264{
1265  "EXAMPLE:"; echo = 2;
1266  ring r=0,(x,y),lp;
1267  def rr=changeordTo(r,"dp");
1268  rr;
1269}
1270
1271proc addvarsTo(def r,list vars,int blockorder)
1272"USAGE:  addvarsTo(ring,list_of_strings, int);
1273         int may be: 0:ordering: dp
1274                     1:ordering dp,dp
1275                     2:oring.ordering,dp
1276RETURN:  a ring with the addtional variables
1277EXAMPLE: example addvarsTo(); shows an example
1278"
1279{
1280  list rl=ringlist(r);
1281  int n=nvars(r);
1282  rl[2]=rl[2]+vars;
1283  if (blockorder==0)
1284  {
1285    rl[3]=list(list("C",0),list("dp",1:(nvars(r)+size(vars))));
1286  }
1287  else
1288  {
1289    if (blockorder==2)
1290    {
1291      rl[3]=rl[3]+list(list("dp",1:size(vars)));
1292    }
1293    else
1294    {
1295      rl[3]=list(list("C",0),list("dp",1:nvars(r)),list("dp",1:size(vars)));
1296    }
1297  }
1298  def rr=ring(rl);
1299  return(rr);
1300}
1301example
1302{
1303  "EXAMPLE:"; echo = 2;
1304  ring r=0,(x,y),lp;
1305  def rr=addvarsTo(r,list("a","b"),0);
1306  rr; kill rr;
1307  def rr=addvarsTo(r,list("a","b"),1);
1308  rr; kill rr;
1309  def rr=addvarsTo(r,list("a","b"),2);
1310  rr;
1311}
1312proc addNvarsTo(def r,int N,string n,int blockorder)
1313"USAGE:  addNvarsTo(ring,int N, string name, int b);
1314         b may be: 0:ordering: dp
1315                   1:ordering dp,dp
1316                   2:oring.ordering,dp
1317RETURN:  a ring with N addtional variables
1318EXAMPLE: example addNvarsTo(); shows an example
1319"
1320{
1321  list v;
1322  for(int i=N;i>0;i--) { v[i]=n+"("+string(i)+")"; }
1323  return(addvarsTo(r,v,blockorder));
1324}
1325example
1326{
1327  "EXAMPLE:"; echo = 2;
1328  ring r=0,(x,y),lp;
1329  def rr=addNvarsTo(r,2,"@",0);
1330  rr; kill rr;
1331  def rr=addNvarsTo(r,2,"@",1);
1332  rr; kill rr;
1333  def rr=addNvarsTo(r,2,"@",2);
1334  rr;
1335}
Note: See TracBrowser for help on using the repository browser.