source: git/Singular/LIB/fastsolv.lib @ cc9598

fieker-DuValspielwiese
Last change on this file since cc9598 was 3d124a7, checked in by Olaf Bachmann <obachman@…>, 27 years ago
This commit was generated by cvs2svn to compensate for changes in r191, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@192 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 9.8 KB
Line 
1// $ID$
2// ====================================================================
3//  library fast.lib
4//
5// ====================================================================
6
7proc Tsimplify
8USAGE:    simplify(id,n);  id ideal, n integer
9RETURNS:  list of two ideals the first containing the simplified
10          elements, the second the variables which already have
11          been eliminated
12ASSUME:   basering has ordering dp, the elimination of the variables
13          n+1,... is not supported
14EXAMPLE:  example simplify; shows an example
15
16{
17  def bsr=basering;
18  int @n, @m, @k;
19  option (redSB);
20  ideal @i = interred(#[1]);
21  ideal @j, @im, @va;
22  for (@n=1;@n<=size(@i);@n=@n+1)
23  {
24    if (deg(@i[@n])==1)
25    {
26      @k=0;
27      for (@m=#[2]+1;@m<=nvars(basering);@m=@m+1)
28      {
29        if (lead(@i[@n])/var(@m)!=0)
30        {
31          @k=1;
32          break;
33        }
34      }
35      if (@k==0)
36      {
37        @va=@va+lead(@i[@n]);
38        @i[@n]=0;
39      }
40    }
41  }
42  @i=@i+@j;
43  map @phi;
44  for (@m=1;@m<=#[2];@m=@m+1)
45  {
46    for (@n=size(@i);@n>=1;@n=@n-1)
47    {
48      if (deg(@i[@n]/var(@m))==0)
49      {
50        @im = maxideal(1);
51        @im[@m]=(-1/coeffs(@i[@n],var(@m))[2,1])*(@i[@n]-coeffs(@i[@n],var(@m))[2,1]*var(@m));
52        @phi = basering,@im;
53        @i=@phi(@i);
54        @i=@i+@j;
55        @va=@va+var(@m);
56        break;// hier muesste evt. sorgfaeltiger ausgewaehlt werden
57      }
58    }
59  }
60  @i=interred(@i);
61  option(noredSB);
62  return(@i,@va);
63}
64example
65{
66   ring s=181,(x,y,z,t,u,v,w,a,b,c,d,f,e),dp;
67   ideal j=
68            w2+f2-1,
69            x2+t2+a2-1,
70            y2+u2+b2-1,
71            z2+v2+c2-1,
72            d2+e2-1,
73            f4+2u,
74            wa+tf,
75            xy+tu+ab,
76            yz+uv+bc,
77            cd+ze,
78            x+y+z+e+1,
79            t+u+v+f-1,
80            w+a+b+c+d;
81    list l=Tsimplify(j,10);
82    l;
83}
84
85
86proc simplifyInBadRings
87USAGE:    simplify(id,n);  id ideal, n product of the variables
88          to be eliminated later
89RETURNS:  list of two ideals the first containing the simplified
90          elements, the second the variables which already have
91          been eliminated
92EXAMPLE:  example simplify; shows an example
93
94{
95  int @i,@j;
96  string @es=",(";
97  string @ns="),dp;";
98  for (@i=1;@i<=nvars(basering);@i=@i+1)
99  {
100    if (deg(#[2]/var(@i))>=0)
101    {
102      @es=@es+varstr(@i)+",";
103      @j=@j+1;
104    }
105    else
106    {
107      @ns=","+varstr(@i)+@ns;
108    }
109  }
110  string @s=@es[1,size(@es)-1]+@ns;
111  @ns=nameof(basering);
112  ideal i=#[1];
113  execute "ring @gnir ="+charstr(basering)+@s;
114  ideal @laedi=imap(`@ns`,i);
115  list @l=Tsimplify(@laedi,@j);
116  ideal @l1, @l2=@l[1], @l[2];
117  execute "setring "+@ns+";";
118  return(imap(@gnir,@l1),imap(@gnir,@l2));
119}
120example
121{
122   ring s=0,(e,f,x,y,z,t,u,v,w,a,b,c,d),dp;
123   ideal j=
124            w2+f2-1,
125            x2+t2+a2-1,
126            y2+u2+b2-1,
127            z2+v2+c2-1,
128            d2+e2-1,
129            f4+2u,
130            wa+tf,
131            xy+tu+ab,
132            yz+uv+bc,
133            cd+ze,
134            x+y+z+e+1,
135            t+u+v+f-1,
136            w+a+b+c+d;
137    list l=simplifyInBadRings(j,xyztuvwabc);
138    l;
139}
140
141
142proc fastElim
143USAGE:    fastelim(id,v);  id ideal, v Product of variables to
144          be eliminated.
145RETURNS:  list of two ideals the first containing the simplified
146          elements, the second the variables which already have
147          been eliminated
148EXAMPLE:  example fastElim; shows an example.
149{
150   string @oldgnir = nameof(basering);  // Namen des alten Baserings merken
151   string @varnames;
152   int @i;
153   poly @testpoly=1;      // Variablen, die schon eliminiert sind (nach Simplify)
154   poly @elimvarspoly=#[2]; // Variablen, die noch eliminiert werden sollen
155
156   // das Ideal vereinfachen. Beachte: l[1] erzeugt nicht mehr id!
157   list @l=simplifyInBadRings(#[1],#[2]);
158   ideal @a, @b = @l[1], @l[2];
159
160   // ------------------------------------------------------------
161   // in einen Ring abbilden, der die in (2) angegebenen Variablen
162   // nicht mehr enthaelt.
163   // ------------------------------------------------------------
164
165
166   // Aus dem von simplifyInBadRings zurueckgegebenen Ideal(2), das die
167   // Variablen anthealt, die eliminiert sind, ein Polynom bauen:
168   for (@i=1; @i<=size(@b); @i=@i+1)
169   {
170     @testpoly=@testpoly*@b[@i];
171     @elimvarspoly = subst(@elimvarspoly, @b[@i], 1);
172   }
173
174   //Wenn keine Variablen mehr uebrig sind, sind wir fertig:
175   if (@elimvarspoly==1)
176   {
177     // Falls das 4. Argument 1 ist, eine minimale Basis berechnen
178     if (#[4]==1)
179     {
180       mres(@a,1,@a0);
181       @a=@a0(1);
182     }
183     return(@a);
184   }
185
186   // Anhand dieses Polynoms ueberpruefen, welche Variablen unser
187   // neuer Ring braucht: @varnames
188   for (@i=1; @i<=nvars(basering); @i=@i+1)
189   {
190     if (@testpoly/var(@i)==0)
191     {
192       @varnames=@varnames + nameof(var(@i)) + ",";
193     }
194   }
195   @varnames=@varnames[1, size(@varnames)-1];
196
197   // Den neuen Ring erzeugen und das Ideal a darin abbilden:
198   execute("ring @r1=" + charstr(basering) + ",(" + @varnames + ")," + "dp;" );
199   ideal @a=imap(`@oldgnir`, @a);
200   list #=imap(`@oldgnir`,#);
201
202   // Nun die beste Reihenfolge fuer die Variablen berechnen:
203   string @orderedvars=string(maxideal(1));
204   if (#[3]==1)
205   {
206      poly @elimvarspoly=imap(`@oldgnir`,@elimvarspoly);
207      intvec @v= valvars(@a,#[5], @elimvarspoly,#[6]);
208      @v;
209      @orderedvars=string(sort1(maxideal(1),@v));
210   }
211
212   // In einen Ring wechseln, der diese Reihenfolge beruecksichtig:
213   execute("ring @r2=" + charstr(basering) + ",(" + @orderedvars + ",@homo),dp;" );
214   ideal @a= imap(@r1, @a);
215   kill @r1;
216
217   //das ideal homogenisieren
218   @a=homog(@a,@homo);
219
220   // Die Variablen holen, die wirklich noch zu eliminieren sind, und
221   // danach eliminate aufrufen.
222   poly @elimvarspoly= imap(`@oldgnir`, @elimvarspoly);
223   ideal @b=eliminate(@a, @elimvarspoly);
224
225   // Falls das 4. Argument 1 ist, eine minimale Basis berechnen
226   if (#[4]==1)
227   {
228     mres(@b,1,@b0);
229     @b=@b0(1);
230   }
231
232   // dehomogenisieren (@homo=1) und zurueck in den alten Ring
233   @b=subst(@b,@homo,1);
234   execute "setring "+@oldgnir+";";
235   return(imap(@r2,@b));
236}
237example
238{
239   ring s=31991,(e,f,x,y,z,t,u,v,w,a,b,c,d),dp;
240   ideal j=
241            w2+f2-1,
242            x2+t2+a2-1,
243            y2+u2+b2-1,
244            z2+v2+c2-1,
245            d2+e2-1,
246            f4+2u,
247            wa+tf,
248            xy+tu+ab,
249            yz+uv+bc,
250            cd+ze,
251            x+y+z+e+1,
252            t+u+v+f-1,
253            w+a+b+c+d;
254   fastElim(j,xyztuvwabcd,1,0,0,0);
255}
256
257
258proc sort1
259{
260  intvec @i=#[2];
261  int @ii=size(@i);
262  int @j;
263  string @s=string(typeof(#[1]))+" @m;";
264  execute(@s);
265  for (@j=1;@j<=@ii;@j=@j+1)
266  {
267    @m[@j] = #[1][@i[@j]];
268  }
269  return(@m);
270}
271
272
273proc valvars
274
275USAGE:    valvars(id, [n1, [m, [n2]]]); id (poly|ideal|vector|module);
276                                        m monom; n1,n2 int
277RETURNS:  an intvec describing the permutation such that the permuted
278          ringvariables are ordered with respect to inreasing complexity
279          [resp. decreasing complexity if n1 is present and non-zero].
280          If m is present, the variables occuring in m are sorted in one
281          block before all variables not occuring in m. n2 controls the
282          order of this block as n1 does for the other one.
283          A variable x is more complex than y (with respect to id) if, in the
284          input, either the maximal occuring power of x is bigger than that
285          of y or both are equal and the coefficient of x to this power
286          contains more monomials than that of y.
287EXAMPLE:  example valvars; shows an example
288
289{
290  int     @order1, @order2,     // order of vars not to elim resp. to elim
291          @i1,                  // runs through all variables
292          @i2,                  // # of vars to elim already found
293          @N, @M,               // N = total # of vars, M = # of vars to elim
294          @i, @j, @k, @size, @degree;
295  intvec  @varvec, @degvec, @sizevec;
296  poly    @m;
297  ideal   @id;
298  matrix  @C;
299
300  @id = matrix( #[1] ); @m = 0;
301  @N = nvars( basering ); @M = 0;
302  @order1 = 1; @order2 = 1;
303  if ( size(#) >= 4 )
304    { @order2 = not( #[4] ) * 2 - 1; }
305  if ( size(#) >= 3 )
306    { @m = #[3]; @M = deg( #[3] ); }
307  if ( size(#) >= 2 )
308    { @order1 = not( #[2] ) * 2 - 1; }
309
310  @i2 = 0;
311  for ( @i1 = 1; @i1 <= @N; @i1++ )
312  {
313    // get valuation of current variable.
314    @C = coeffs( @id, var( @i1 ));
315    @degree = nrows( @C );
316    @size = 0;
317    for ( @j = ncols( @C ); @j >= 1; @j-- )
318      { @size = @size + size( @C[ @degree, @j ] ); }
319
320    // mind order and calculate limits for search
321    if ( @M and size( @m / var( @i1 )))
322    {
323      @degree = @degree * @order2; @size = @size * @order2;
324      @i2++;
325      @i = @i2; @j = 1;
326    }
327    else
328    {
329      @degree = @degree * @order1; @size = @size * @order1;
330      @i = @i1 - @i2 + @M; @j = @M+1;
331    }
332
333    // look where we have to insert the variable
334    // "start = " + string( @j ) + ", end = " + string( @i );
335    @degvec[ @i ] = @degree + 1; @sizevec[ @i ] = @size + 1;
336    while ( @degvec[ @j ] < @degree )
337      { @j++; }
338    while ( @degvec[ @j ] == @degree and @sizevec[ @j ] < @size )
339      { @j++; }
340
341    // now shift the variables behind the current one back
342    // "inserting at " + string( @j );
343    for ( @k = @i-1; @k >= @j; @k-- )
344    {
345      @varvec[ @k+1 ] = @varvec[ @k ];
346      @degvec[ @k+1 ] = @degvec[ @k ];
347      @sizevec[ @k+1 ] = @sizevec[ @k ];
348    }
349    @varvec[ @j ] = @i1;             // print( @varvec );
350    @degvec[ @j ] = @degree;         // print( @degvec );
351    @sizevec[ @j ] = @size;          // print( @sizevec );
352  }
353
354  return( @varvec );
355}
356example
357{
358  echo = 1; ring @r=0,(a,b,c,x,y,z),lp;
359  poly @f=a3+b4+xyz2+xyz+yz+1;
360  valvars( @f );
361  valvars( @f, 1 );
362  valvars( @f, 0, abc );
363  valvars( @f, 0, xyz );
364  valvars( @f, 0, abc, 1 );
365  valvars( @f, 1, abc, 1 );
366  ideal @i=@f,z5,y5,-y5;
367  valvars( @i );
368  valvars( @i, 0, abcxyz );
369  kill @r; echo = 0;
370}
Note: See TracBrowser for help on using the repository browser.