source: git/Singular/LIB/findiff.lib @ 1d5227

fieker-DuValspielwiese
Last change on this file since 1d5227 was ea87a9, checked in by Hans Schoenemann <hannes@…>, 14 years ago
tabs and spaces git-svn-id: file:///usr/local/Singular/svn/trunk@13403 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 40.3 KB
Line 
1//
2//
3//////////////////////////////////////////////////////////////////////////////
4version="$Id$";
5category="Teaching";
6info="
7LIBRARY:  findiff.lib    procedures to compute finite difference schemes for
8                         linear differential equations
9AUTHOR:                  Christian Dingler
10
11NOTE:
12 @texinfo
13 Using @code{qepcad}/@code{qepcadsystem} from this
14 library requires the program @code{qepcad} to be installed.
15 You can download @code{qepcad} from
16 @uref{http://www.usna.edu/Users/cs/qepcad/INSTALL/IQ.html}
17 @end texinfo
18
19PROCEDURES:
20 visualize(f);        shows a scheme in index-notation
21 u(D[,#]);        gives some vector; depends on @derivatives
22 scheme([v1,..,vn]);      computes the finite difference scheme defined by v1,..,vn
23 laxfrT(Ut,U,space);      Lax-Friedrich-approximation for the time-direction
24 laxfrX(Ux,U,space);      Lax-Friedrich-approximation for the space-direction
25 forward(U1,U2,VAR);      forward-approximation
26 backward(U1,U2,VAR);      backward-approximation
27 central1st(U1,U2,VAR);      central-approximation of first order
28 central2nd(U1,U2,VAR);      central-approximation of second order
29 trapezoid(U1,U2,VAR);      trapezoid-approximation
30 midpoint(U1,U2,VAR);      midpoint-approximation
31 pyramid(U1,U2,VAR);      pyramid-approximation
32 setinitials(variable,der[,#]);    constructs and sets the basering for further computations
33 errormap(f);        performs the Fouriertransformation of a poly
34 matrixsystem(Matrices,Approx);    gives the scheme of a pde-system as one matrix
35 timestep(M);        gives the several timelevels of a scheme derived from a pde-system
36 fouriersystem(Matrices,Approx);  performs the Fouriertransformation of a matrix scheme
37 PartitionVar(f,n);      partitions a poly into the var(n)-part and the rest
38 ComplexValue(f);      computes the complex value of f, var(1) being the imaginary unit
39 VarToPar(f);        substitute var(i) by par(i)
40 ParToVar(f);        substitute par(i) by var(i)
41 qepcad(f);        ask QEPCAD for equivalent constraints to f<1
42 qepcadsystem(l);      ask QEPCAD for equivalent constraints to all eigenvals of some matrices being <1
43
44
45";
46LIB "ring.lib";
47LIB "general.lib";
48LIB "standard.lib";
49LIB "linalg.lib";
50LIB "matrix.lib";
51LIB "poly.lib";
52LIB "teachstd.lib";
53LIB "qhmoduli.lib";
54///////////////////////////////////////////////////////////////////////
55static proc getit(module M)
56{
57  int nderiv=pos(U,@derivatives);
58  def M2=groebner(M);
59  module N1=gen(nderiv);
60  def N2=intersect(M2,N1);
61  def S=N2[1][nderiv];
62  return(S);
63}
64///////////////////////////////////////////////////////////////////////
65proc visualize(poly f)
66"USAGE:   visualize(f); f of type poly.
67RETURN:  type string; translates the polynomial form of a finite difference scheme into an indexed one as often seen in literature
68EXAMPLE: example visualize; shows an example
69"
70{
71  def n=size(f);
72  string str;
73  intvec v;
74  if (n>0)
75  {
76    int i;
77    int j;
78    for(i=1;i<=n;i++)
79    {
80      intvec w=leadexp(f);
81      for(j=1;j<=size(@variables);j++)
82      {
83        v[j]=w[j+1];
84      }
85      if(i==1)
86      {
87        str=print(leadcoef(f),"%s")+"*"+"U("+print(v,"%s")+")";
88      }
89      else
90      {
91        str=str+"+"+print(leadcoef(f),"%s")+"*"+"U("+print(v,"%s")+")";
92      }
93      kill w;
94      f=f-lead(f);
95    }
96  }
97  return(str);
98}
99example
100{
101"EXAMPLE:";echo=2;
102 list D="Ux","Ut","U";
103 list P="a";
104 list V="t","x";
105 setinitials(V,D,P);
106 scheme(u(Ut)+a*u(Ux),trapezoid(Ux,U,x),backward(Ut,U,t));
107 visualize(_);
108}
109
110///////////////////////////////////
111static proc imageideal()
112{
113
114  def n=size(@variables)-1;
115  ideal IDEAL=var(1),var(2);
116  int j;
117  for(j=1;j<=n;j++)
118  {
119    ideal II=var(2+j+n)+var(1)*var(2+2*n+j);
120    IDEAL=IDEAL+II;
121    kill II;
122  }
123  return(IDEAL);
124}
125/////////////////////////////////////
126proc u(D,list #)
127"USAGE:   u(D[,#]); D a string that occurs in the list of @derivatives, # an optional list of integers.
128RETURN:  type vector; gives the vector, that corresponds with gen(n)*m, where m is the monomial defined by #
129EXAMPLE: example u; shows an example
130"
131{
132  def n=size(#);
133  def nv=nvars(basering)-1;
134  int nn;
135  if(nv<=n)
136  {
137    nn=nv;
138  }
139  else
140  {
141    nn=n;
142  }
143  int index=pos(D,@derivatives);
144  poly g=1;
145  if(nn>=1)
146  {
147    int j;
148    for(j=1;j<=nn;j++)
149    {
150      int nnn;
151      nnn=int(#[j]);
152      g=var(1+j)**nnn*g;
153      kill nnn;
154    }
155    return(gen(index)*g);
156  }
157  else
158  {
159    return(gen(index)*g);
160  }
161}
162example
163{
164  "EXAMPLE:";echo=2;
165  list D="Ux","Uy","Ut","U";
166  list P="a","b";
167  list V="t","x","y";
168  setinitials(V,D,P);
169  u(Ux);
170  u(Ux,2,3,7);
171  u(Uy)+u(Ut)-u(Ux);
172  u(U)*234-dx*dt*dy*3*u(Uy);
173}
174
175/////////////////////////////////////////////////////////
176static proc pos(string D,list L)
177{
178  int j;
179  int index=-1;
180  def n=size(L);
181  for(j=1;j<=n;j++)
182  {
183    if(D==L[j])
184    {
185      index=j;
186    }
187  }
188  return(index);
189}
190///////////////////////////////////
191static proc re(list L)
192{
193  def n=size(L);
194  int j;
195  for(j=1;j<=n;j++)
196  {
197    string s="string "+print(L[j],"%s")+"="+"nameof("+print(L[j],"%s")+")"+";";
198    execute(s);
199    kill s;
200    exportto(Top,`L[j]`);
201  }
202}
203///////////////////////////////////////////////
204proc scheme(list #)
205"USAGE:    scheme([v1,..,vn]); v1,..,vn of type vector
206RETURN:   type poly; performs substitutions by the means of Groebner Basis computation of the module generated by the input vectors, then intersects the intermediate result with the suitable component in order to get a finite difference scheme;
207NOTE:     works only for a single pde, for the case of a system use matrixsystem
208EXAMPLE:  example scheme; shows an example
209"
210{
211  def N=size(#);
212  if(N==0)
213  {
214    if(defined(M)==1)
215    {
216      kill M;
217      module M;
218    }
219    else
220    {
221      module M;
222    }
223  }
224  else
225  {
226    int j;
227    if(defined(M)==1)
228    {
229      kill M;
230      module M;
231      for(j=1;j<=N;j++)
232      {
233        M=M+#[j];
234      }
235    }
236    else
237    {
238      module M;
239      for(j=1;j<=N;j++)
240      {
241        M=M+#[j];
242      }
243    }
244  }
245  def S=getit(M);
246  matrix mat[1][1]=S;
247  list l=timestep(mat);
248  poly f=l[2][1,1];
249  return(f);
250}
251example
252{
253  "EXAMPLE:";echo=2;
254  list D="Ux","Ut","U";
255  list P="a";
256  list V="t","x";
257  setinitials(V,D,P);
258  def s1=scheme(u(Ut)+a*u(Ux),backward(Ux,U,x),forward(Ut,U,t));
259  s1;
260}
261////////////////////////
262static proc diffpar(poly ff)
263{
264  def gg=print(ff,"%s");
265  def str="d"+gg;
266  return(`str`);
267}
268////////////////////////
269proc laxfrT(string Ut, string U, poly space)
270"USAGE:   laxfrT(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
271RETURN:   type vector; gives a predefined approximation of the Lax-Friedrich-approximation for the derivation in the timevariable as often used in literature;
272NOTE:     see also laxfrX,setinitials,scheme; WARNING: laxfrT is not to be interchanged with laxfrX
273EXAMPLE:  example laxfrT; shows an example
274"
275{
276  poly time=var(2);
277  poly dtime=diffpar(time);
278  poly dspace=diffpar(space);
279  def v=dtime*space*u(Ut)-time*space*u(U)+1/2*(space**2*u(U)+u(U));
280  return(v);
281}
282example
283{
284  "EXAMPLE:";echo=2;
285  list D="Ux","Ut","U";
286  list P="a";
287  list V="t","x";
288  setinitials(V,D,P);
289  laxfrT(Ux,U,x);
290}
291////////////////////////
292proc laxfrX(string Ux, string U, poly space)
293"USAGE:   laxfrX(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
294RETURN:   type vector; gives a predefined approximation of the Lax-Friedrich-approximation for the derivation in one of the spatial variables as often used in literature;
295NOTE:     see also laxfrT,setinitials,scheme; WARNING: laxfrT is not to be interchanged with laxfrX
296EXAMPLE:  example laxfrX; shows an example
297"
298{
299  poly dspace=diffpar(space);
300  def v=2*dspace*space*u(Ux)-(space**2-1)*u(U);
301  return(v);
302}
303example
304{
305  "EXAMPLE:";echo=2;
306  list D="Ux","Ut","U";
307  list P="a";
308  list V="t","x";
309  setinitials(V,D,P);
310  laxfrX(Ux,U,x);
311}
312////////////////////////
313proc forward(string U1,string U2,poly VAR)
314"USAGE:   forward(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
315RETURN:   type vector; gives a predefined approximation of the forward approximation as often used in literature;
316NOTE:     see also laxfrT,setinitials,scheme;
317EXAMPLE:  example forward; shows an example
318"
319{
320  if(pos(U1,@derivatives)<pos(U2,@derivatives))
321    {
322      def V1=U1;
323      def V2=U2;
324    }
325  else
326    {
327      def V1=U2;
328      def V2=U1;
329    }
330  def v=diffpar(VAR)*u(V1)+u(V2)-VAR*u(V2);
331  return(v);
332}
333example
334{
335  "EXAMPLE:";echo=2;
336  list D="Ut","Ux","Uy","U";
337  list V="t","x","y";
338  list P="a","b";
339  setinitials(V,D,P);
340  forward(Ux,U,x);
341  forward(Uy,U,y);
342  forward(Ut,U,t);
343}
344///////////////////////
345proc backward(string U1,string U2,poly VAR)
346"USAGE:   backward(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
347RETURN:   type vector; gives a predefined approximation of the backward approximation as often used in literature;
348NOTE:     see also forward,laxfrT,setinitials,scheme;
349EXAMPLE:  example backward; shows an example
350"
351{
352  if(pos(U1,@derivatives)<pos(U2,@derivatives))
353    {
354      def V1=U1;
355      def V2=U2;
356    }
357  else
358    {
359      def V1=U2;
360      def V2=U1;
361    }
362  def v=diffpar(VAR)*VAR*u(V1)+u(V2)-VAR*u(V2);
363  return(v);
364}
365example
366{
367  "EXAMPLE:";echo=2;
368  list D="Ut","Ux","Uy","U";
369  list V="t","x","y";
370  list P="a","b";
371  setinitials(V,D,P);
372  backward(Ux,U,x);
373  backward(Uy,U,y);
374  backward(Ut,U,t);
375}
376/////////////////////////////
377proc central1st(string U1,string U2,poly VAR)
378"USAGE:   central1st(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
379RETURN:   type vector; gives a predefined approximation of the first-order-central-approximation as often used in literature;
380NOTE:     see also forward,laxfrT,setinitials,scheme;
381EXAMPLE:  example central1st; shows an example
382"
383{
384  if(pos(U1,@derivatives)<pos(U2,@derivatives))
385    {
386      def V1=U1;
387      def V2=U2;
388    }
389  else
390    {
391      def V1=U2;
392      def V2=U1;
393    }
394  def v=2*diffpar(VAR)*VAR*u(V1)+u(V2)-VAR**2*u(V2);
395  return(v);
396}
397example
398{
399  "EXAMPLE:";echo=2;
400  list D="Ut","Ux","Uy","U";
401  list V="t","x","y";
402  list P="a","b";
403  setinitials(V,D,P);
404  central1st(Ux,U,x);
405  central1st(Uy,U,y);
406}
407////////////////////////////////
408proc central2nd(string U1,string U2,poly VAR)
409"USAGE:   central2nd(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
410RETURN:   type vector; gives a predefined approximation of the second-order-central-approximation as often used in literature;
411NOTE:     see also forward,laxfrT,setinitials,scheme;
412EXAMPLE:  example central2nd; shows an example
413"
414{
415  if(pos(U1,@derivatives)<pos(U2,@derivatives))
416    {
417      def V1=U1;
418      def V2=U2;
419    }
420  else
421    {
422      def V1=U2;
423      def V2=U1;
424    }
425  def v=diffpar(VAR)**2*VAR*u(V1)-(VAR**2*u(V2)-2*VAR*u(V2)+u(V2));
426  return(v);
427}
428example
429{
430  "EXAMPLE:";echo=2;
431  list D="Uxx","Ux","Utt","Ut","U";
432  list P="lambda";
433  list V="t","x";
434  setinitials(V,D,P);
435  central2nd(Uxx,U,x);
436  central2nd(Utt,U,t);
437}
438/////////////////////////////////
439proc trapezoid(string U1,string U2,poly VAR)
440"USAGE:   trapezoid(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
441RETURN:   type vector; gives a predefined approximation of the trapezoid-approximation as often used in literature;
442NOTE:     see also forward,laxfrT,setinitials,scheme;
443EXAMPLE:  example trapezoid; shows an example
444"
445{
446  if(pos(U1,@derivatives)<pos(U2,@derivatives))
447    {
448      def V1=U1;
449      def V2=U2;
450    }
451  else
452    {
453      def V1=U2;
454      def V2=U1;
455    }
456  def v=1/2*diffpar(VAR)*(VAR+1)*u(V1)+(1-VAR)*u(V2);
457  return(v);
458}
459example
460{
461  "EXAMPLE:";echo=2;
462  list D="Uxx","Ux","Utt","Ut","U";
463  list P="lambda";
464  list V="t","x";
465  setinitials(V,D,P);
466  trapezoid(Uxx,Ux,x);
467  trapezoid(Ux,U,x);
468}
469///////////////////////////////////
470proc midpoint(string U1,string U2,poly VAR)
471"USAGE:   midpoint(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
472RETURN:   type vector; gives a predefined approximation of the midpoint-approximation as often used in literature;
473NOTE:     see also forward,laxfrT,setinitials,scheme;
474EXAMPLE:  example midpoint; shows an example
475"
476{
477  if(pos(U1,@derivatives)<pos(U2,@derivatives))
478    {
479      def V1=U1;
480      def V2=U2;
481    }
482  else
483    {
484      def V1=U2;
485      def V2=U1;
486    }
487  def v=2*diffpar(VAR)*VAR*u(V1)+(1-VAR**2)*u(V2);
488  return(v);
489}
490example
491{
492  "EXAMPLE:";echo=2;
493  list D="Uxx","Ux","Utt","Ut","U";
494  list P="lambda";
495  list V="t","x";
496  setinitials(V,D,P);
497  midpoint(Ux,U,x);
498}
499//////////////////////////////////////
500proc pyramid(string U1,string U2,poly VAR)
501"USAGE:   pyramid(U1,U2,var); U1, U2 are the names of occuring derivatives, var is a variable in the basering;
502RETURN:   type vector; gives a predefined approximation of the pyramid-approximation as often used in literature;
503NOTE:     see also forward,laxfrT,setinitials,scheme;
504EXAMPLE:  example pyramid; shows an example
505"
506{
507  if(pos(U1,@derivatives)<pos(U2,@derivatives))
508    {
509      def V1=U1;
510      def V2=U2;
511    }
512  else
513    {
514      def V1=U2;
515      def V2=U1;
516    }
517  def v=1/3*diffpar(VAR)*(VAR**2+VAR+1)*u(V1)+(VAR-VAR**3)*u(V2);
518  return(v);
519}
520example
521{
522  "EXAMPLE:";echo=2;
523  list D="Uxx","Ux","Utt","Ut","U";
524  list P="lambda";
525  list V="t","x";
526  setinitials(V,D,P);
527  pyramid(Ux,U,x);
528}
529//////////////////////////////////////////////
530proc setinitials(list variable, list der,list #)
531"USAGE:  setinitials(V,D[,P]); V,D,P are lists with strings as elements
532RETURN:  no return value: sets the dependence order of the occuring derivatives, constructs the suitable ring to compute in containing user chosen parameters, sets new basering
533NOTE:    P is optional, used to introduce some additional parameters into the ring. The SINE and COSINE values needed for the fouriertransformation  are symbolically introduced under the names string(c)+nameof(variable), i.e. if x is any spatial variable then cx:=cosine(dx*ksi), when regarding the fouriertransform after ksi (for sine respectively). Artificial parameters I,T,Px,Py are introduced for the later eigenvalue analysis -> variables can be transformed into parameters of similar name
534EXAMPLE: example setinitials; shows an example
535"
536{
537  def LV=variable;
538  def @variables=variable;
539  def @derivatives=der;
540  exportto(Top,@variables);
541  exportto(Top,@derivatives);
542  re(der);
543  int j;
544  string dvar="d"+print(LV[1],"%s");
545  dvar=dvar+","+"d"+print(LV[2],"%s");
546  string pvar="P"+print(LV[2],"%s");
547  string COS="C"+print(LV[2],"%s");
548  string SIN="S"+print(LV[2],"%s");
549  for(j=3;j<=size(LV);j++)
550    {
551      dvar=dvar+","+"d"+print(LV[j],"%s");
552      pvar=pvar+","+"P"+print(LV[j],"%s");
553      COS=COS+","+"C"+print(LV[j],"%s");
554      SIN=SIN+","+"S"+print(LV[j],"%s");
555    }
556  string scf="(0,"+"I,"+"T,"+pvar+","+COS+","+SIN+","+print(#,"%s")+","+dvar+")";  //coefficient_field
557  string svars="(i";
558  kill j;
559  int j;
560  for(j=1;j<=size(LV);j++)
561    {
562      svars=svars+","+print(LV[j],"%s");
563    }
564  string cosine;
565  string sine;
566  kill j;
567  int j;
568  cosine="c"+print(LV[2],"%s");
569  sine="s"+print(LV[2],"%s");
570  for(j=3;j<=size(LV);j++)
571    {
572      cosine=cosine+","+"c"+print(LV[j],"%s");
573      sine=sine+","+"s"+print(LV[j],"%s");
574    }
575  kill j;
576  string strvar=cosine+","+sine+")";
577  svars=svars+","+strvar;            ////variables
578  string sord="(c,lp)";         ////ordering
579  string sring="ring Q="+scf+","+svars+","+sord+";";
580  execute(sring);
581  ideal Id=i**2+1;
582  int j;
583  for(j=1;j<=size(LV)-1;j++)
584    {
585      ideal II=var(2+j+size(LV)-1)**2+var(2+j+2*(size(LV)-1))**2-1;
586      Id=Id+II;
587      kill II;
588    }
589  if(defined(basering)==1)
590    {
591      kill basering;
592    }
593  qring R=std(Id);
594  setring R;
595  export(R);
596  exportto(Top,basering);
597}
598example
599{
600  "EXAMPLE:"; echo = 2;
601  list D="Ut","Ux","Uy","U";
602  list V="t","x","y";
603  list P="alpha","beta","gamma";
604  setinitials(V,D,P);////does not show the ring, since there is no output
605  basering;///does show the ring
606}
607////////////////////////////
608proc errormap(poly f)
609"USAGE:    errormap(f); f of type poly
610RETURN:   type poly; performs the fouriertransformation of a single polynomial
611EXAMPLE:  example errormap; shows an example
612"
613{
614  ideal Id=imageideal();
615  map phi=R,Id;
616  def g=phi(f);
617  g=reduce(g,std(0));
618  return(g);
619}
620example
621{
622  "EXAMPLE";echo=2;
623  list D="Ux","Ut","U";
624  list P="a";
625  list V="t","x";
626  setinitials(V,D,P);
627  scheme(u(Ut)+a*u(Ux),central1st(Ux,U,x),backward(Ut,U,t));
628  errormap(_);
629}
630/////////////////////////////////////
631static proc stepmatrix(int n, poly f)
632{
633  int spavars=size(@variables)-1;
634  int range=n*spavars;
635  if(f==0)
636    {
637      return(unitmat(range));
638    }
639  matrix M[range][range];
640  int length=size(f);
641  intvec max=maxexp(f);
642  int i;
643  intvec shiftback;
644  intvec vzero;
645  intvec vmax;
646  intvec shiftforward;
647  for(i=1;i<=size(max);i++)
648    {
649     shiftback[i]=int(floor(max[i]/2));
650     vzero[i]=0;
651     vmax[i]=n-1;
652     shiftforward[i]=0;
653    }
654  kill i;
655  int i;
656  for(i=1;i<=range;i++)
657    {
658      poly g=f;
659    }
660  kill i;
661}
662//////////////////////////////////////
663static proc floor(n)
664{
665  number h1=numerator(n);
666  number h2=denominator(n);
667  return((h1- (h1 mod h2))/h2);
668}
669/////////////////////////////////////
670static proc maxexp(poly f)
671{
672  int length=size(f);
673  poly g=f;
674  intvec v;
675  int i;
676  for(i=1;i<size(@variables);i++)
677    {
678      v[i]=leadexp(g)[i+2];
679    }
680  while(g!=0)
681    {
682      int j;
683      for(j=1;j<size(@variables);j++)
684  {
685    v[j]=maximal(leadexp(g)[j+2],v[j]);
686    g=g-lead(g);
687  }
688      kill j;
689    }
690  return(v);
691}
692////////////////////////////////////
693static proc maximal(int n1,int n2)
694{
695  if(n1>n2)
696    {
697      return(n1);
698    }
699  else
700    {
701      return(n2);
702    }
703}
704////////////////////////////////////
705static proc minimal(int n1, int n2)
706{
707  return(-maximal(-n1,-n2));
708}
709////////////////////////////////////
710static proc MatrixEntry(int n, intvec v)
711{
712  int j;
713  int entry;
714  int spavar=size(@variables)-1;
715  for(j=1;j<=spavar;j++)
716    {
717      entry=entry+v[j]*n**(spavar-j);
718    }
719  entry=entry+1;
720  return(entry);
721}
722//////////////////////////////////
723static proc CompareVec(intvec ToTest, intvec Reference)//1 if ToTest>=Reference, 0 else
724{
725  int i;
726  for(i=1;i<=size(@variables)-1;i++)
727    {
728      if(ToTest[i+2]<Reference[i])
729  {
730    return(0);
731  }
732    }
733  return(1);
734}
735/////////////////////////////////
736static proc MaxVecZero(intvec ToTest, intvec Reference) //KGV, size=size(input)
737{
738  int length=size(ToTest);
739  int i;
740  intvec Maximum;
741  for(i=1;i<=length;i++)
742    {
743      Maximum[i]=maximal(ToTest[i],Reference[i]);
744    }
745  return(Maximum);
746}
747//////////////////////////////////
748proc matrixsystem(list Matrices,list Approx)
749"USAGE:   matrixsytem(M,A); where the M=Mt,M1,..,Mn is a list with square matrices of the same dimension as entries, and A=At,A1,..,An gives the corresponding approximations for the several variables (t,x1,..,xn) as vector. Intended to solve Mt*U_t + M1*U_x1+..+Mn*U_xn=0 as a linear sytem of partial differential equations numerically by a finite difference scheme;
750RETURN:   type matrix; gives back the matrices B1,B2 that represent the finite difference scheme, partitioned into different time levels in the form:  B1*U(t=N)=B2*U(t<N), where N is the maximal occurring degree (timelevel) of t.
751EXAMPLE:  example matrixsystem; shows an example
752"
753{
754  if(size(Matrices)>size(@variables) or size(Matrices)!=size(Approx))
755    {
756      ERROR("Check number of variables: it must hold  #(matrices)<= #(spatial variables)+1  !!! ");
757    }
758  if(size(Matrices)!=size(Approx))
759    {
760      ERROR("Every variable needs EXACTLY ONE approximation rule, i.e. #(first argument) =#(second argument) ! ");
761    }
762  ideal Mon=leadmonomial(Approx[1]);
763  int N=size(Matrices);
764  int i;
765  for(i=2;i<=N;i++)
766    {
767      Mon=Mon,leadmonomial(Approx[i]);
768    }
769  kill i;
770  poly LCM=lcm(Mon);
771  matrix M[nrows(Matrices[1])][ncols(Matrices[1])];
772  int i;
773  for(i=1;i<=size(Matrices);i++)
774    {
775      M=M+(LCM/leadmonomial(Approx[i]))*normalize(Approx[i])[size(@derivatives)]*Matrices[i];
776    }
777  kill i;
778  return(M);
779}
780example
781{
782  "EXAMPLE:";echo=2;
783  list D="Ut","Ux","Uy","U";
784  list V="t","x","y";
785  list P="a","b";
786  setinitials(V,D,P);
787  list Mat=unitmat(2),unitmat(2);
788  list Appr=forward(Ut,U,t),forward(Ux,U,x);
789  matrixsystem(Mat,Appr);
790}
791//////////////////////////////////
792proc timestep(matrix M)
793"USAGE:   timestep(M); M a square matrix with polynomials over the basering as entries;
794RETURN:   type list; gives two  matrices M1,M2 that are the splitting of M with respect to the degree of the variable t in the entries, where the first list-entry M1 consists of the polynomials of the highest timelevel and M2 of the lower levels in the form:  M=0  =>  M1=M2,    i.e. M1-M2=M
795NOTE:     intended to be used for the finite-difference-scheme-construction and partition into the several time steps
796EXAMPLE:  example timestep; shows an example
797"
798{
799  int N=nrows(M);
800  int i;
801  int maxdegT;
802  for(i=1;i<=N;i++)
803    {
804      int j;
805      for(j=1;j<=N;j++)
806  {
807    poly f=M[i,j];
808    int k;
809    for(k=1;k<=size(f);k++)
810      {
811        if(leadexp(M[i,j])[2]>maxdegT)
812    {
813      maxdegT=leadexp(M[i,j])[2];
814    }
815        f=f-lead(f);
816      }
817    kill f;
818    kill k;
819  }
820      kill j;
821    }
822  kill i;
823  matrix highT[nrows(M)][nrows(M)];
824  vector leftside=0;
825  int GenIndex=0;
826  int i;
827  for(i=1;i<=N;i++)
828    {
829      int j;
830      for(j=1;j<=N;j++)
831  {
832    poly f=M[i,j];
833    int k;
834    for(k=1;k<=size(f)+1;k++)
835      {
836        if(leadexp(f)[2]==maxdegT)
837    {
838      GenIndex++;
839      highT[i,j]=highT[i,j]+lead(f);
840      leftside=leftside+highT[i,j]*gen(GenIndex);
841    }
842        f=f-lead(f);
843      }
844    kill k;
845    kill f;
846  }
847      kill j;
848    }
849  kill i;
850  matrix tUpper=highT;
851  matrix tLower=-1*(M-tUpper);
852  tUpper=tUpper/content(leftside);
853  tLower=tLower/content(leftside);
854  list L=tUpper,tLower;
855  return(L);
856}
857example
858{
859  "EXAMPLE:"echo=2;
860  list D="Ut","Ux","Uy","U";
861  list V="t","x","y";
862  list P="a","b";
863  setinitials(V,D,P);
864  list Mat=unitmat(2),unitmat(2);
865  list Apr=forward(Ut,U,t),forward(Ux,U,x);
866  matrixsystem(Mat,Apr);
867  timestep(_);
868}
869//////////////////////////////////
870proc fouriersystem(list Matrices, list Approx)
871"USAGE:   fouriersystem(M,A); M a list of matrices, A a list of approximations;
872RETURN:   type list; each entry is some matrix obtained by performing the substitution of the single approximations into the system of pde's, partitioning the equation into the several timesteps and fouriertransforming these parts
873EXAMPLE:  example fouriersystem; shows an example
874"
875{
876  matrix M=matrixsystem(Matrices,Approx);
877  matrix T1=timestep(M)[1];
878  matrix T0=timestep(M)[2];
879  int i;
880  for(i=1;i<=nrows(M);i++)
881    {
882      int j;
883      for(j=1;j<=nrows(M);j++)
884  {
885    T1[i,j]=errormap(T1[i,j]);
886    T1[i,j]=VarToPar(T1[i,j]);
887    T0[i,j]=errormap(T0[i,j]);
888    T0[i,j]=VarToPar(T0[i,j]);
889  }
890      kill j;
891    }
892  kill i;
893  ideal EV1=eigenvals(T1)[1];
894  ideal EV0=eigenvals(T0)[1];
895  list L=list(T1,T0),list(EV1,EV0);
896  def N1=size(EV1);
897  def N0=size(EV0);
898  list CV1;
899  list CV0;
900  int i;
901  for(i=1;i<=N1;i++)
902  {
903  CV1[i]=VarToPar(EV1[i]);
904  if(content(CV1[i])==CV1[i])
905  {
906  CV1[i]=content(CV1[i]);
907  CV1[i]=VarToPar(ComplexValue(numerator(CV1[i])))/VarToPar(ComplexValue(denominator(CV1[i])));
908  }
909  }
910  kill i;
911  int i;
912  for(i=1;i<=N0;i++)
913  {
914  CV0[i]=VarToPar(EV0[i]);
915  if(content(CV0[i])==CV0[i])
916  {
917  CV0[i]=content(CV0[i]);
918  CV0[i]=VarToPar(ComplexValue(numerator(CV0[i])))/VarToPar(ComplexValue(denominator(CV0[i])));
919  }
920  }
921  kill i;
922  list CV=list(CV1,CV0);
923  L=L,CV;
924  return(L);
925}
926example
927{
928  "EXAMPLE:"; echo = 2;
929  list D="Ut","Ux","Uy","U";
930  list V="t","x","y";
931  list P="a","b";
932  setinitials(V,D,P);
933  matrix M[2][2]=0,-a,-a,0;
934  list Mat=unitmat(2),M;
935  list Appr=forward(Ut,U,t),trapezoid(Ux,U,x);
936  def s=fouriersystem(Mat,Appr);s;
937}
938//////////////////////////////////
939proc PartitionVar(poly f,int n)
940"USAGE:   PartitionVar(f); f a poly in the basering;
941RETURN:   type poly; gives back a list L=f1,f2 obtained by the partition of f into two parts f1,f2 with deg_var_n(f1) >0  deg_var_n(f2)=0
942EXAMPLE:  example PartitionVar; shows an example
943"
944{
945  if(n>=nvars(basering))
946    {
947      ERROR("this variable does not exist in the current basering");
948    }
949  int i;
950  poly partition=0;
951  poly g=f;
952  for(i=1;i<=size(f);i++)
953    {
954      if(leadexp(g)[n]!=0)
955  {
956    partition=partition+lead(g);
957  }
958      g=g-lead(g);
959    }
960  list L=partition,f-partition;
961  return(L);
962}
963example
964{
965  "EXAMPLE:"; echo = 2;
966  list D="Ut","Ux","Uy","U";
967  list V="t","x","y";
968  list P="a","b";
969  setinitials(V,D,P);////does not show the ring, since there is no output
970  basering;///does show the ring
971  poly f=t**3*cx**2-cy**2*dt+i**3*sx;
972  PartitionVar(f,1); ////i is the first variable
973}
974//////////////////////////////////
975proc ComplexValue(poly f)
976"USAGE:   ComplexValue(f); f a poly in the basering;
977RETURN:   type poly; gives back the formal complex-value of f, where var(1) is redarded as the imaginary unit. Does only make sence, if the proc <setinitials> is executed before -> nvars <= npars
978EXAMPLE:  example ComplexValue; shows an example
979"
980{
981  poly g=ParToVar(f);
982  def L=PartitionVar(g,1);
983  poly f1=subst(L[1],var(1),1);
984  poly f2=L[2];
985  poly result=reduce(f1**2+f2**2,std(0));
986  return(result);
987}
988example
989{
990  "EXAMPLE:"; echo = 2;
991  list D="Ut","Ux","Uy","U";
992  list V="t","x","y";
993  list P="a","b";
994  setinitials(V,D,P);////does not show the ring, as there is  no output
995  basering;///does show the ring
996  poly f=t**3*cx**2-cy**2*dt+i**3*sx;
997  f;
998  VarToPar(f);
999}
1000//////////////////////////////////
1001proc VarToPar(poly f)
1002"USAGE:   VarToPar(f); f a poly in the basering;
1003RETURN:   type poly; gives back the poly obtained by substituting var(i) by par(i), for all variables. Does only make sence, if the proc <setinitials> is executed before -> nvars <= npars;
1004EXAMPLE:  example VarToPar; shows an example
1005"
1006{
1007  int N=nvars(basering);
1008  int i;
1009  def g=f;
1010  for(i=1;i<=N;i++)
1011    {
1012      g=subst(g,var(i),par(i));
1013    }
1014  return(g);
1015}
1016example
1017{
1018  "EXAMPLE:"; echo = 2;
1019  list D="Ut","Ux","Uy","U";
1020  list V="t","x","y";
1021  list P="a","b";
1022  setinitials(V,D,P);////does not show the ring, as there is  no output
1023  basering;///does show the ring
1024  poly f=t**3*cx**2-cy**2*dt+i**3*sx;
1025  f;
1026  VarToPar(f);
1027}
1028/////////////////////////////////////
1029proc ParToVar(poly f)
1030"USAGE:   ParToVar(f); f a poly in the basering;
1031RETURN:   type poly; gives back the poly obtained by substituting par(i) by var(i), for the first nvars(basering parameters. Does only make sence, if setinitials is executed before -> nvars <= npars. Is the opposite action to VarToPar, see example ParToVar;
1032EXAMPLE:  example ParToVar; shows an example
1033"
1034{
1035  int N=nvars(basering);
1036  int i;
1037  number g=number(VarToPar(f));
1038  number denom=denominator(g);
1039  g=denom*g;
1040  def gg=subst(g,par(1),var(1));
1041  for(i=2;i<=N;i++)
1042    {
1043      gg=subst(gg,par(i),var(i));
1044    }
1045  return(gg/denom);
1046}
1047example
1048{
1049  "EXAMPLE:"; echo = 2;
1050  list D="Ut","Ux","Uy","U";
1051  list V="t","x","y";
1052  list P="a","b";
1053  setinitials(V,D,P);////does not show the ring, as there is  no output
1054  basering;///does show the ring
1055  poly f=t**3*cx**2-cy**2*dt+i**3*sx/dt*dx;
1056  f;
1057  def g=VarToPar(f);
1058  g;
1059  def h=ParToVar(g);
1060  h==f;
1061}
1062/////////////////////////////////////////
1063proc qepcad(poly f)
1064"USAGE:   qepcad(f); f a poly in the basering;
1065RETURN:   type list; gives back some constraints that are equivalent to f<1 (computed by QEPCAD);
1066EXAMPLE:  example qepcad; shows an example
1067"
1068{
1069  system("sh","rm -f QEPCAD-out");
1070  system("sh","rm -f QEPCAD-in");
1071  if(denominator(content(f))==1)
1072  {
1073    poly g=f-1;
1074  }
1075  else
1076  {
1077    if(f==content(f))
1078    {
1079      poly g=f*denominator(content(f))-1*denominator(content(f));
1080      g=ParToVar(g);
1081      g=reduce(g,std(0));
1082    }
1083    else
1084    {
1085      poly g=cleardenom(f)-1/content(f);
1086      g=ParToVar(g);
1087      g=reduce(g,std(0));
1088    }
1089  }
1090  string in="QEPCAD-in";
1091  string out="QEPCAD-out";
1092  link l1=in;
1093  link l2=out;
1094  string s1="[trial]";    //description
1095  string s2=varlist();    //the variables
1096  string s3=nfreevars();  //number of free variables
1097  string s4=aquantor()+"["+writepoly(g)+rel()+"]."; //the input prenex formula
1098  string s5=projection();
1099  string s6=projection();
1100  string s7=choice();
1101  string s8=solution();
1102  write(l1,s1,s2,s3,s4,s5,s6,s7,s8);
1103  system("sh","qepcad < QEPCAD-in | qepcadfilter.pl > QEPCAD-out");
1104  string output=read(out);
1105  print(output,"%s");
1106  if(size(output)==0)
1107  {
1108    return("Try manually");    //maybe too few cells
1109  }
1110  if(find(output,"FALSE")!=0)
1111  {
1112    return("FALSE");
1113  }
1114  if(find(output,"WARNING")!=0)
1115  {
1116    return("WARNING! Try manually");
1117  }
1118  else
1119  {
1120    string strpolys=findthepoly(output);
1121    list lpolys=listpolynew(strpolys);
1122    return(lpolys);
1123  }
1124  system("sh","rm -f QEPCAD-out");
1125  system("sh","rm -f QEPCAD-in");
1126
1127}
1128example
1129{
1130  "EXAMPLE:"; echo = 2;
1131  list D="Ux","Ut","U";
1132  list P="a";
1133  list V="t","x";
1134  setinitials(V,D,P);
1135  def s1=scheme(u(Ut)+a*u(Ux),laxfrX(Ux,U,x),laxfrT(Ut,U,x));
1136  s1;
1137  def s2=errormap(s1);
1138  s2;
1139  def s3=ComplexValue(s2);s3;
1140  qepcad(s3);
1141}
1142///////////////////////////////////////////
1143proc qepcadsystem(list l)
1144"USAGE:   qepcadsytem(f); l a list;
1145RETURN:   type list; gives back some constraints that are equivalent to the eigenvalues of the matrices in the list l being < 1 (computed by QEPCAD);
1146EXAMPLE:  example qepcadsystem; shows an example
1147"
1148{
1149  system("sh","rm -f QEPCAD-out");
1150  system("sh","rm -f QEPCAD-in");
1151  string in="QEPCAD-in";
1152  string out="QEPCAD-out";
1153  link l1=in;
1154  link l2=out;
1155  string s1="[trial]";    //description
1156  string s2=varlist();    //the variables
1157  string s3=nfreevars();  //number of free variables
1158  string thepolys;
1159  int n2=size(l[2]);
1160  int count;
1161  int i;
1162  list lpolys;
1163  int j;
1164  for(j=1;j<=n2;j++)
1165  {
1166    count++;
1167    poly g2=ParToVar(l[2][j]);
1168    if(denominator(content(g2))==1)
1169    {
1170      lpolys[count]=writepoly(ParToVar(reduce(g2-1,std(0))))+rel();
1171    }
1172    else
1173    {
1174      if(g2==content(g2))
1175      {
1176        g2=g2*denominator(content(g2))-1*denominator(content(g2));
1177        g2=ParToVar(g2);
1178        g2=reduce(g2,std(0));
1179        lpolys[count]=writepoly(g2)+rel();
1180      }
1181      else
1182      {
1183        lpolys[count]=writepoly(reduce(ParToVar(cleardenom(g2)-1/content(g2)),std(0)))+rel();
1184      }
1185    }
1186    kill g2;
1187  }
1188  kill j;
1189  int k;
1190  for(k=1;k<=size(lpolys);k++)
1191  {
1192    thepolys=thepolys+lpolys[k];
1193    if(k<size(lpolys))
1194    {
1195      thepolys=thepolys+print(" /","s%")+print("\\ ","s%");
1196    }
1197  }
1198  string s4=aquantor()+"["+thepolys+"]."; //the input prenex formula
1199  string s5=projection();
1200  string s6=projection();
1201  string s7=choice();
1202  string s8=solution();
1203  write(l1,s1,s2,s3,s4,s5,s6,s7,s8);
1204  system("sh","qepcad < QEPCAD-in | qepcadfilter.pl > QEPCAD-out");
1205  string output=read(out);
1206  print(output,"%s");
1207  if(size(output)==0)
1208  {
1209    return("Try manually");    //maybe too few cells
1210  }
1211  if(find(output,"FALSE")!=0)
1212  {
1213    return("FALSE");
1214  }
1215  if(find(output,"WARNING")!=0)
1216  {
1217    return("WARNING! Try manually");
1218  }
1219  else
1220  {
1221    string strpolys=findthepoly(output);
1222    list llpolys=listpolynew(strpolys);
1223    return(llpolys);
1224  }
1225  system("sh","rm -f QEPCAD-out");
1226  system("sh","rm -f QEPCAD-in");
1227}
1228example
1229{
1230  "EXAMPLE:"; echo = 2;
1231  list D="Ut","Ux","Uy","U";
1232  list V="t","x","y";
1233  list P="a","b";
1234  setinitials(V,D,P);
1235  matrix M[2][2]=0,-a,-a,0;
1236  list Mat=unitmat(2),M;
1237  list Appr=forward(Ut,U,t),forward(Ux,U,x);
1238  //matrixsystem(Mat,Appr);
1239  //timestep(_);
1240  fouriersystem(Mat,Appr);
1241  qepcadsystem(_[2]);
1242}
1243///////////////////////////////////////////
1244static proc substbracketstar(string s)
1245{
1246  int i;
1247  int k;
1248  int index=1;
1249  string finish=s;
1250  for(k=1;k<=size(s);k++)
1251  {
1252    if(finish[1]=="(" or finish[1]=="*" or finish[1]==" ")
1253    {
1254      kill finish;
1255      index=index+1;
1256      string finish=s[index..size(s)];
1257    }
1258  }
1259  for(i=1;i<=size(finish);i++)
1260  {
1261    if(finish[i]=="*" or finish[i]=="(" or finish[i]== ")")
1262    {
1263      finish[i]=" ";
1264    }
1265  }
1266  return(finish);
1267}
1268
1269////////////////////////////////////
1270static proc distribution(string SUM, string MON)
1271{
1272  string sum=substbracketstar(SUM);
1273  string mon=substbracketstar(MON);
1274  string result;
1275  list signs;
1276  list p;
1277  int i;
1278  int j;
1279  int init;
1280  for(i=2;i<=size(sum);i++)
1281  {
1282    if(sum[i]=="+" or sum[i]=="-")
1283    {
1284      j++;
1285      p[j]=i;
1286    }
1287  }
1288  if(j==0)
1289  {
1290    if(sum[1]!="-")
1291    {
1292      result=sum+" "+" "+mon;
1293      result="+"+" "+result;
1294    }
1295    else
1296    {
1297      result=sum+" "+mon;
1298    }
1299  }
1300  else
1301  {
1302    int l;
1303    int anfang;
1304    if(sum[1]=="-")
1305    {
1306      result="-"+" "+result;
1307      anfang=2;
1308    }
1309    else
1310    {
1311      result="+"+" "+result;
1312      if(sum[1]=="+")
1313      {
1314        anfang=2;
1315      }
1316      else
1317      {
1318        anfang=1;
1319      }
1320    }
1321    for(l=1;l<=j;l++)
1322    {
1323      string a;
1324      int k;
1325      for(k=anfang;k<=p[l]-1;k++)
1326      {
1327        a=a+sum[k];
1328      }
1329      result=result+" "+a+" "+mon+" "+sum[p[l]];
1330      anfang=p[l]+1;
1331      kill a;
1332      kill k;
1333    }
1334    if(p[j]<size(sum))
1335    {
1336      int kk;
1337      string aa;
1338      for(kk=anfang;kk<=size(sum);kk++)
1339      {
1340        aa=aa+sum[kk];
1341      }
1342      result=result+" "+aa+" "+mon;
1343      kill aa;
1344      kill kk;
1345    }
1346    else
1347    {
1348      int kkk;
1349      string aaa;
1350      for(kkk=anfang;kkk<size(sum);kkk++)
1351      {
1352        aaa=aaa+sum[kkk];
1353      }
1354      result=result+" "+aaa+" "+mon;
1355      kill aaa;
1356      kill kkk;
1357    }
1358  }
1359  return(result);
1360}
1361/////////////////////////////////////////////////////////////////
1362static proc writepoly(poly f)
1363{
1364  poly g=f;
1365  string lc;
1366  string lm;
1367  string strpoly;
1368  string intermediate;
1369  int n=size(f);
1370  int i;
1371  for(i=1;i<=n;i++)
1372  {
1373
1374    lc=substbracketstar(string(leadcoef(g)));
1375    lm=substbracketstar(string(leadmonom(g)));
1376    intermediate=distribution(lc,lm);
1377    strpoly=strpoly+" "+intermediate;
1378    g=g-lead(g);
1379  }
1380  return(strpoly);
1381}
1382///////////////////////////////////////////////////////////////
1383static proc varlist()
1384{
1385  poly p1=par(2+size(@variables));
1386  p1=ParToVar(p1);
1387  string name=print(p1,"%s");
1388  string p="("+name+",";
1389  int i;
1390  for(i=3+size(@variables);i<=npars(basering);i++)
1391  {
1392    p1=ParToVar(par(i));
1393    name=substbracketstar(print(p1,"%s"));
1394    p=p+name+",";
1395  }
1396  p1=ParToVar(par(2));
1397  name=print(p1,"%s");
1398  p=p+name+")";
1399  return(p);
1400}
1401///////////////////////////////////////////////////////
1402static proc normalization()
1403{
1404  int n1=npars(basering)-size(@variables);
1405  int n2=npars(basering)-n1;
1406  string assumption="assume["+" "+substbracketstar(print(par(n1+1),"%s"))+" >0";
1407  int i;
1408  for(i=2;i<=n2;i++)
1409  {
1410    string s=" /\\"+" "+substbracketstar(print(par(n1+i),"%s"))+" >0";
1411    assumption=assumption+" "+s;
1412    kill s;
1413  }
1414  assumption=assumption+" ]"+newline+"go";
1415  return(assumption);
1416}
1417///////////////////////////////////////////////////////
1418static proc projection()
1419{
1420  string s="go";
1421  return(s);
1422}
1423///////////////////////////////////////////////////////
1424static proc choice()
1425{
1426  string s="go";
1427  return(s);
1428}
1429///////////////////////////////////////////////////////
1430static proc solution()
1431{
1432  string s="go";
1433  return(s);
1434}
1435///////////////////////////////////////////////////////
1436static proc nfreevars()
1437{
1438  int n=npars(basering)-size(@variables)-1;
1439  string no=print(n,"%s");
1440  return(no);
1441}
1442/////////////////////////////////////////////////////////
1443static proc aquantor()
1444{
1445  string s="(A "+print(var(2),"%s")+")";
1446  return(s);
1447}
1448////////////////////////////////////////////////////////
1449static proc rel()
1450{
1451  return("<0");
1452}
1453/////////////////////////////////////////////////////////
1454static proc rm()
1455{
1456  system("sh","rm -f dummy");
1457  system("sh","rm -f QEPCAD-in");
1458}
1459////////////////////////////////////////////////////////
1460static proc findthepoly(string word)
1461{
1462  int init=1;
1463  int index=find(word,newline);
1464  if(index==size(word) or index== 0)
1465  {
1466    return(word);
1467  }
1468  else
1469  {
1470    while(index<size(word))
1471    {
1472      init=index;
1473      index=find(word,newline,index+1);
1474    }
1475  }
1476  string thepoly=word[(init+1)..(size(word)-1)];
1477  return(thepoly);
1478}
1479//////////////////////////////////////////////////
1480static proc listpolynew(string thepoly)
1481{
1482  string p=thepoly;
1483  intvec v;
1484  p=TestAndDelete(p,"[")[1];
1485  p=TestAndDelete(p,"]")[1];    //remove the brackets
1486  string AND="/"+"\\";
1487  string OR="\\"+"/";
1488  list thesigns=AND,OR,"~","<==>","==>","<==";///these can occur in QEPCAD
1489  int i;
1490  for(i=1;i<=size(thesigns);i++)
1491  {
1492    list l=TestAndDelete(p,thesigns[i]);
1493    p=l[1];
1494    v=addintvec(v,l[2]);
1495    kill l;
1496  }
1497  intvec w=rightorder(v);
1498  int N=size(v);
1499  list lstrings;
1500  if(size(w)==1 and w[1]==0)
1501  {
1502    N=0;
1503    lstrings[1]=p;
1504  }
1505  else
1506  {
1507    string s1=p[1..w[1]-1];
1508    lstrings[1]=s1;
1509    int j;
1510    for(j=1;j<N;j++)
1511    {
1512      string s2=p[w[j]..w[j+1]-1];
1513      lstrings[j+1]=s2;
1514      kill s2;
1515    }
1516    string s3=p[w[N]..size(p)];
1517    lstrings[N+1]=s3;
1518  }
1519  list cutstrings;
1520  int k;
1521  list Id;
1522  for(k=1;k<=N+1;k++)
1523  {
1524    cutstrings[k]=cutoffrel(lstrings[k]);
1525    Id[k]=translatenew(cutstrings[k]);
1526  }
1527  return(Id);
1528
1529
1530}
1531/////////////////////////////////////////////////
1532static proc translatenew(string word)
1533{
1534  int n=size(word);
1535  string subword=word[1..n];
1536  string strpoly="poly f=";
1537  list linterim;
1538  int i;
1539  for(i=1;i<=n;i++)
1540  {
1541    if(i<n and subword[i]==" " and subword[i+1]!="+" and subword[i+1]!="-" and subword[i+1]!=" " and subword[i-1]!="+" and subword[i-1]!="-" and subword[i-1]!=" " and i>1)
1542    {
1543      linterim[i]="*";
1544    }
1545    else
1546    {
1547      linterim[i]=word[i];
1548    }
1549    strpoly=strpoly+print(linterim[i],"%s");
1550  }
1551  strpoly=strpoly+";";
1552  execute(strpoly);
1553  return(f);
1554}
1555//////////////////////////////////////////////////
1556static proc rightorder(intvec v)
1557////////////orders the entries of an intvec from small to bigger
1558{
1559  list ldown=intveclist(v);
1560  list lup;
1561  intvec v1;
1562  int counter;
1563  int min;
1564  int i;
1565  for(i=1;i<=size(v);i++)
1566  {
1567    min=Min(listintvec(ldown));
1568    lup[i]=min;
1569    counter=listfind(ldown,min);
1570    ldown=delete(ldown,counter);
1571  }
1572  intvec result=listintvec(lup);
1573  return(result);
1574}
1575/////////////////////////////////////////////////
1576static proc listfind(list l, int n)
1577//////gives the position of n in l, 0 if not found
1578{
1579  int i;
1580  intvec counter;
1581  int j=1;
1582  for(i=1;i<=size(l);i++)
1583  {
1584    if(n==l[i])
1585    {
1586      counter[j]=i;
1587      j++;
1588    }
1589  }
1590  int result=Min(counter);
1591  return(result);
1592}
1593//////////////////////////////////////////////////
1594static proc cutoffrel(string str)
1595/////////cut off the relations "/=,<= etc." from output-string
1596{
1597  list rels="<=",">=","<",">","/=","=";  //these are all of qepcad's relations
1598  int i;
1599  list l;
1600  for(i=1;i<=size(rels);i++)
1601  {
1602    l[i]=find(str,rels[i]);
1603  }
1604  intvec v=listintvec(l);
1605  v=addintvec(v,v);
1606  int position=Min(v);
1607  string result;
1608  if(position==0)
1609  {
1610    result=str;
1611  }
1612  else
1613  {
1614    result=str[1..position-1];
1615  }
1616  return(result);
1617}
1618//////////////////////////////////////////////////
1619static proc addintvec(intvec v1, intvec v2)
1620///////concatenates two intvecs and deletes occurring zeroentries, output intvec
1621{
1622  list lresult;
1623  int i;
1624  list l1;
1625  list l2;
1626  for(i=1;i<=size(v1);i++)
1627  {
1628    l1[i]=v1[i];
1629  }
1630  kill i;
1631  int k;
1632  for(k=1;k<=size(v2);k++)
1633  {
1634    l2[k]=v2[k];
1635  }
1636  lresult=l1+l2;
1637  intvec result;
1638  int j;
1639  int counter=1;
1640  for(j=1;j<=size(lresult);j++)
1641  {
1642    if(lresult[j]!=0)
1643    {
1644      result[counter]=lresult[j];
1645      counter++;
1646    }
1647  }
1648  return(result);
1649
1650}
1651/////////////////////////////////////////////////
1652static proc intveclist(intvec v)
1653//////returns the intvec as list
1654{
1655  list l;
1656  int i;
1657  for(i=size(v);i>=1;i--)
1658  {
1659    l[i]=v[i];
1660  }
1661  return(l);
1662}
1663//////////////////////////////////////////////////
1664static proc listintvec(list l)
1665//////////returns the list as intvec: only integer-entries allowed
1666{
1667  intvec v;
1668  int i;
1669  for(i=size(l);i>=1;i--)
1670  {
1671    v[i]=l[i];
1672  }
1673  return(v);
1674}
1675//////////////////////////////////////////////////
1676static proc TestAndDelete(string str, string booleansign)
1677{
1678  int decide=find(str,booleansign);
1679  intvec v;
1680  v[1]=decide;
1681  while(decide!=0 and decide<size(str))//if booleansign ist not contained in str
1682  {
1683    int n=size(v);
1684    decide=find(str,booleansign,decide+1);
1685    if(decide!=0)
1686    {
1687      v[n+1]=decide;
1688    }
1689    kill n;
1690  }
1691  if(size(v)==1 and v[1]==0)/////i.e. booleansign NOT in str
1692  {
1693    list result=str,v;
1694    return(result);
1695  }
1696  else
1697  {
1698    list l;
1699    string p;
1700    int i;
1701    int j;
1702    for(i=1;i<=size(str);i++)///copy the string str into l
1703    {
1704      l[i]=str[i];
1705    }
1706    kill i;
1707    for(j=1;j<=size(v);j++)///replace booleansign by empty char
1708    {
1709      int k;
1710      for(k=0;k<=size(booleansign)-1;k++)
1711      {
1712        l[v[j]+k]=" ";
1713      }
1714      kill k;
1715    }
1716    int s;
1717    for(s=1;s<=size(l);s++)///copy back
1718    {
1719      p=p+string(l[s]);
1720    }
1721    kill s;
1722    kill l;
1723    list result=p,v;
1724    return(result);
1725  }
1726}
1727//////////////////////////////////////////////////
1728static proc nchoice(int n1,int n2)
1729{
1730  int N2=maximal(n1,n2);
1731  int N1=minimal(n1,n2);
1732  if(N1==0)
1733  {
1734    return(N2);
1735  }
1736  else
1737  {
1738    return(N1);
1739  }
1740}
Note: See TracBrowser for help on using the repository browser.