source: git/Singular/LIB/tst.lib @ 341696

spielwiese
Last change on this file since 341696 was 341696, checked in by Hans Schönemann <hannes@…>, 14 years ago
Adding Id property to all files git-svn-id: file:///usr/local/Singular/svn/trunk@12231 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 24.9 KB
Line 
1// $Id$
2//(obachman, last modified 6/30/98)
3/////////////////////////////////////////////////////////////////////////////
4
5version="$Id$";
6category="Utilities";
7info="
8LIBRARY:  tst.lib      Procedures for running automatic tst Tests
9
10PROCEDURES:
11 tst_system(s)          returns string which is stdout of system(\"sh\", s)
12 tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout),
13                                   prepending prefix \"// tst_ignore:\"
14 tst_init()             writes some identification data to GetTstStatusFile()
15 tst_status([any])      writes status info to GetTstStatusFile()
16 tst_InitTimer()        initialize tst-Timer
17 tst_StopTimer()        stop Tst-Timer
18 tst_GetTimer           get value of Tst-Timer
19 tst_ReportTimer        report value of Tst-Timer
20 tst_groebnerTest(ideal i)
21                        tests groebner command
22 tst_stdEqual(ideal i1, ideal i2)
23                        test whether two std's are \"equal\"
24
25 tst_test_res(ideal i)  test different res commands for homog ideal i
26";
27
28/////////////////////////////////////////////////////////////////////////////
29proc tst_system(string s, list #)
30"USAGE:    tst_system(s); s string
31RETURN:   string which is stdout and stderr of system(\"sh\", s)
32EXAMPLE:  example tst_system; shows examples"
33{
34  string tmpfile = "/tmp/tst_" + string(system("pid"));
35  int errno;
36
37  s = s + " 1>" + tmpfile + " 2>&1";
38  errno = system("sh", s);
39  s = read(tmpfile);
40  errno = system("sh", "rm -f " + tmpfile);
41  if (size(#) > 0 && size(s) > 1)
42  {
43    s = s[1, size(s) -1];
44  }
45  return (s);
46}
47example
48{
49  "EXAMPLE"; echo = 2;
50  string s = tst_system("echo This is an example of tst_system");
51  "The following is what the system call wrote to stdout: " + s;
52}
53
54proc tst_ignore(list #)
55"USAGE:    tst_ignore(any,[keyword], [link])
56            any     -- valid argument to string()
57            keyword -- an arbitrary string
58            link    -- a link which can be written to
59RETURN:   none; writes string(any) to link (or stdout, if no link given),
60          prepending prefix \"// tst_ignore:\", or
61                            \"// tst_ignore:keyword hostname:\",
62                            if keyword was given.
63          Should be used in tst files to output system dependent data
64          (like date, pathnames).
65EXAMPLE:  example tst_ignore; shows examples
66"
67{
68  if (! defined(tst_no_status))
69  {
70    string s;
71    string keyword = "";
72    link outlink = "";
73
74    // Check # of args
75    if (size(#) < 1 || size(#) > 3)
76    {
77      "Error tst_ignore: Wrong number of arguments";
78      "Usage: tst_ignore (any,[keyword], [link]);";
79      return();
80    }
81
82    // Get Args
83    s = string(#[1]);
84    if (size(#) == 3)
85    {
86      keyword = #[2];
87      outlink = #[3];
88    }
89    if (size(#) == 2)
90    {
91      if (typeof(#[2]) == "string")
92      {
93        keyword = #[2];
94      }
95      else
96      {
97        outlink = #[2];
98      }
99    }
100
101    // check args
102    if (typeof(keyword) != "string")
103    {
104      "Error tst_ignore: Keyword must be a string";
105      "Usage: tst_ignore (any,[keyword], [link]);";
106      return();
107    }
108
109    if (status(outlink, "open", "no"))
110    {
111      open(outlink);
112    }
113
114    if (status(outlink, "write", "not ready"))
115    {
116      "Error tst_ignore: Cannot write to link";
117      outlink;
118      "Usage: tst_ignore (any,[keyword], [link]);";
119      return();
120    }
121
122    // ready -- do the actual work
123    if (keyword != "")
124    {
125      write(outlink,"// tst_ignore:" + keyword + " :: " + tst_system("hostname", 1) + ":" + s);
126    }
127    else
128    {
129      write(outlink, "// tst_ignore: " + s);
130    }
131  }
132}
133example
134{
135  "EXAMPLE";
136  "System independent data can safely be output in tst files;";
137  "However, system dependent data like dates, or pathnames, should be output";
138  "using the command tst_ignore(...), like";
139  echo = 2;
140  tst_ignore(tst_system("date"));
141  int t1 = timer;
142  tst_ignore(t1, "time");
143  tst_ignore(memory(1), "memory");
144}
145
146static proc Get_tst_timer()
147{
148  if (! defined (tst_timer))
149  {
150    string tst_timer = "// tst_ignore:0";
151    export tst_timer;
152    return (0);
153  }
154  else
155  {
156    execute("int tst_int_timer = " + tst_timer[15,size(tst_timer)] + ";");
157    return (tst_int_timer);
158  }
159}
160
161static proc Set_tst_timer (int this_time)
162{
163  tst_timer = tst_timer[1,14] + string(this_time);
164}
165
166static proc GetTstStatusFile()
167{
168  if (!defined(tst_status_file))
169  {
170    return ("tst_status.out");
171  }
172  else
173  {
174    return (tst_status_file);
175  }
176}
177
178static proc tst_status_out (def prefix, def what, list #)
179{
180  string outstring;
181
182  outstring = string(prefix) + " >> " + string(what);
183  if (size(#) > 0)
184  {
185    outstring = outstring + " :: " +
186      tst_system("hostname", 1) + ":" + string(#[1]);
187  }
188  write(":a " + GetTstStatusFile(), outstring);
189}
190
191proc tst_status (list #)
192"USAGE:   tst_status([prefix [, start_up]])
193           prefix -- string
194           start_up -- int
195RETURN:   none
196PURPOSE: writes to tst-output the current memory usage and used CPU time.
197         If no integer argument is given, the elapsed CPU time since
198         the last call to tst_status() is reported.
199         If an integer argument is given, the elapsed CPU time since the
200         start-up of @sc{Singular} is reported.
201         If prefix is given, output reported start with prefix.
202NOTE:     Should be used regularly within tst files to enable automatic
203          tracking of memory and time performance.
204EXAMPLE: example tst_status; shows example
205SEE ALSO: tst_init
206"
207{
208  int start_up;
209
210  if (size(#) > 0)
211  {
212    if (typeof(#[1]) == "string")
213    {
214      string prefix = #[1];
215      if (size(#) > 1)
216      {
217        start_up = 1;
218      }
219    }
220    else
221    {
222      start_up = 1;
223    }
224  }
225  if (! defined(tst_no_status))
226  {
227    if (! defined(tst_status_counter))
228    {
229      int tst_status_counter = 1;
230      export tst_status_counter;
231    }
232    else
233    {
234      tst_status_counter++;
235    }
236
237    if (!defined(prefix))
238    {
239      def prefix = tst_status_counter;
240    }
241    tst_status_out(prefix, "tst_memory_0", memory(0));
242    tst_status_out(prefix, "tst_memory_1", memory(1));
243    tst_status_out(prefix, "tst_memory_2", memory(2));
244    if (start_up > 0)
245    {
246      tst_status_out(prefix, "tst_timer_1", timer);
247    }
248    else
249    {
250      tst_status_out(prefix, "tst_timer", timer - Get_tst_timer());
251      Set_tst_timer(timer);
252    }
253  }
254}
255example
256{
257  "EXAMPLE";  echo = 2;
258  tst_status();
259  ring r;
260  poly p = (x+y+z)^40;
261  tst_status();
262  tst_status(1);
263}
264
265
266proc tst_init(list #)
267"USAGE:   tst_init([file])
268            file -- string
269RETURN:  none
270PURPOSE: initializes further calls to tst routines:
271         If no arguments are given, and if tst_status_file is not defined,
272         then tst-output is written to stdout, else tst-output is written
273         to file.
274EXAMPLE: example tst_init; shows example
275"
276{
277  if (! defined(tst_no_status))
278  {
279    string outfile = "";
280
281    if (size(#) > 0)
282    {
283      if (typeof(#[1]) == string)
284      {
285        outfile  = #[1];
286      }
287    }
288    if (!defined(tst_status_file))
289    {
290      string tst_status_file = outfile;
291      export tst_status_file;
292    }
293    if (GetTstStatusFile() != "")
294    {
295      write(":w " + GetTstStatusFile(), "Status Output of " + GetTstStatusFile());
296    }
297    tst_status_out("init", "USER    :" + system("getenv", "USER"));
298    tst_status_out("init", "HOSTNAME:" + tst_system("hostname", 1));
299    tst_status_out("init", "uname -a:" + tst_system("uname -a", 1));
300    tst_status_out("init", "date    :" + tst_system("date", 1));
301    tst_status_out("init", "version :" + string(system("version")));
302    tst_status_out("init", "ticks   :" + string(system("--ticks-per-sec")));
303    "init >> " + GetTstStatusFile();
304  }
305}
306example
307{
308  "EXAMPLE";  echo = 2;
309  tst_init();
310}
311
312proc tst_InitTimer(list #)
313"USAGE: tst_InitTime([ticks_per_second])
314          ticks_per_second -- int
315RETURN: none
316PURPOSE: initializes tst timer for subsequent calls to tst_StopTimer or
317         tst_ReportTimer.
318         If the ticks_per_second argument is given, then the timer resolution
319         is set to this value. Otherwise, the default timer resolution is used.
320SEE ALSO: tst_StopTimer, tst_GetTimer, tst_ReportTimer
321"
322{
323  if (!defined(tst_Timer))
324  {
325    int tst_Timer;
326    export tst_Timer;
327  }
328  if (size(#) > 0)
329  {
330    if (typeof(#[1]) == "int")
331    {
332      if (#[1] > 0)
333      {
334        system("--ticks-per-sec", #[1]);
335      }
336      else
337      {
338        ERROR("need integer argument > 0");
339      }
340    }
341    else
342    {
343      ERROR("need integer argument");
344    }
345  }
346  tst_Timer = timer;
347}
348
349proc tst_StopTimer()
350"USAGE: tst_StopTimer()
351RETURN: int, timer ticks of elapsed CPU time since last call to tst_InitTimer
352PUPOSE: stops the timer initialized by previous call to tst_InitTimer
353SEE ALSO: tst_InitTimer, tst_GetTimer, tst_ReportTimer
354"
355{
356  tst_Timer = timer - tst_Timer;
357  return (tst_Timer);
358}
359
360proc tst_GetTimer()
361"USAGE: tst_GetTimer()
362RETURN: int, timer ticks of elapsed CPU time since last call to tst_Init
363NOTE:  does NOT stop the time initialized by previous call to tst_InitTimer
364SEE ALSO: tst_InitTimer, tst_GetTimer, tst_ReportTimer
365"
366{
367  int tt = timer - tst_Timer;
368  return (tt);
369}
370
371proc tst_ReportTimer(list #)
372"USAGE: tst_ReportTimer([prefix])
373RETURN: none
374PUPOSE: stops the timer initialized by previous call to tst_InitTimer;
375        reports time to tst-output;
376        if prefix is given, timer output is prefixed by it.
377SEE ALSO: tst_InitTimer, tst_GetTimer, tst_StopTimer, tst_OutTimer, tst_init
378"
379{
380  tst_Timer = timer - tst_Timer;
381  tst_OutTimer(tst_Timer, #);
382}
383
384proc tst_OutTimer(int tt, list #)
385"USAGE: tst_OutTimer(ticks [, prefix])
386RETURN: none
387PURPOSE: reports value of tt to tst-output;
388         if prefix is given, timer output is prefixed by it.
389SEE ALSO: tst_InitTimer, tst_GetTimer, tst_StopTimer, tst_ReportTimer, tst_init
390"
391{
392  string prefix = "OutTimer";
393
394  if (size(#) > 0)
395  {
396    prefix = string(#[1]);
397  }
398  tst_status_out(prefix, "tst-Timer", tt);
399}
400
401///////////////////////////////////////////////////////////////////////
402
403proc tst_groebnerTest(ideal i, list #)
404"USAGE: tst_groebnerTesti,[v]) : ideal i, [int v]
405RETURN: 1, if groebner command produced \"equal\" std as std command
406        0, otherwise
407        Two std's are \"equal\" here, if their redSB's are element-wise equal,
408        and if they reduce each other to zero, and if their leading ideals
409        are equal
410        On success, times of std - groebner is written with tst_ignore, and
411        times are added to global variables tst_std_time and
412        tst_groebner_time. If v given, and <= 0, short ideal
413        characteristic is printed, if v > 0, ideals are printed.
414        On failure, Error message and ideals are printed.
415EXAMPLE: example tst_groebner; shows an example
416"
417{
418  int st = timer;
419  ideal si = std(i);
420  st = timer - st;
421
422  int gt = timer;
423  ideal gi = groebner(i);
424  gt = timer - gt;
425
426  if (tst_stdEqual(si, gi))
427  {
428    tst_ignore(string(st) + " - " + string(gt) + " == " + string(st - gt));
429    if (! defined(tst_groebner_time))
430    {
431      int tst_groebner_time;
432      int tst_std_time;
433      export tst_groebner_time, tst_std_time;
434    }
435    tst_std_time = tst_std_time + st;
436    tst_groebner_time = tst_groebner_time + gt;
437    if (size(#))
438    {
439      if (typeof(#[1] == "int"))
440      {
441        if (#[1] <= 0)
442        {
443          idPrintShort(si, "si");
444          idPrintShort(gi, "gi");
445        }
446        else
447        {
448          si;
449          gi;
450        }
451      }
452    }
453    return (1);
454  }
455  return (0);
456}
457example
458{
459  "EXAMPLE: "; echo = 2;
460  ring r = 0, (a,b,c,d), lp;
461  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
462  tst_groebnerTest(i);
463  tst_groebnerTest(i, 0);
464  tst_groebnerTest(i, 1);
465}
466
467
468//
469// A routine which test for equality of "std-bases"
470//
471proc tst_stdEqual(ideal i1, ideal i2)
472"USAGE: tst_stdEqual(i1, i2)  ideal i1, i2
473RETURN 1, if i1 \"equald\" i2 as a std bases
474       0, otherwise
475       Two std's are \"equal\" here, if their redSB's are element-wise equal,
476       and if they reduce each other to zero, and if their leading ideals
477       are equal
478       On failure, error message is printed.
479EXAMPLE: example tst_stdEqual; shows an example
480"
481{
482  int i;
483  int back;
484  intvec opts = option(get);
485  option(redSB);
486
487  ideal ri1 = simplify(interred(i1), 1);
488  ideal ri2 = simplify(interred(i2), 1);
489
490  option(set, opts);
491
492  if (size(ri1) != size(ri2))
493  {
494    "Error in tst_stdEqual: Reduced sizes differ";
495    size(ri1);
496    size(ri2);
497    return(0);
498  }
499
500  for (i=1; i<=size(ri1); i++)
501  {
502    if (ri1[i] != ri2[i])
503    {
504      "Error in tst_stdEqual: " + string(i) + " th polynomials differ";
505      ri1[i];
506      ri2[i];
507      return(0);
508    }
509  }
510
511  // reduced SB are now equal
512  if (size(reduce(i1, i2, 1)) == 0)
513  {
514    if (size(reduce(i2, i1, 1)) == 0)
515    {
516      poly p1, p2;
517
518      ideal si1 = simplify(i1, 7);
519      ideal si2 = simplify(i2, 7);
520
521      if (size(si1) == size(si2))
522      {
523        for (i=1; i<=size(si1); i++)
524        {
525          p1 = p1 + lead(si1[i]);
526          p2 = p2 + lead(si2[i]);
527        }
528        if (p1 != p2)
529        {
530          "Error in tst_stdEqual: Lead monoms differ:";
531          p1;
532          p2;
533          return(0);
534        }
535      }
536      else
537      {
538        "Error in tst_stdEqual: size differs:";
539        size(si1);
540        size(si2);
541        return(0);
542      }
543    }
544    else
545    {
546      "Error in tst_stdEqual: reduce(i2, i1) != 0";
547      return(0);
548    }
549  }
550  else
551  {
552    back = 1; "Error in tst_stdEqual: reduce(i1, i2) != 0";
553    return(0);
554  }
555
556  return (1);
557}
558example
559{
560  "EXAMPLE: "; echo = 2;
561  ring r = 0, (a,b,c,d), lp;
562  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
563  tst_stdEqual(groebner(i), std(i));
564  tst_stdEqual(std(i), i);
565}
566
567static proc idPrintShort(ideal id, string name)
568{
569  "Summary of " + name + " (leading monoms and size of polys):";
570  int i;
571  for (i = 1; i<=size(id); i++)
572  {
573    "[" + string(i) + "]: #" + string(size(id[i])) + ":" + string(lead(id[i]));
574  }
575}
576
577
578proc tst_test_res(ideal i, list #)
579
580"USAGE:    tst_test_res(ideal i, only_lres_and_hres)
581RETURN:    1, if ok; 0 on error
582PURPOSE:   Tests sres, lres, hres, mres with betti commands and conversions
583           If optinal third argument is given, test only lres and hres
584EXAMPLE:  example tst_test_res shows an example"
585{
586  int ret = 1;
587
588  if (! homog(i))
589  {
590    ERROR("ERROR: input ideal needs to be homogenous ");
591  }
592
593  if (size(#) == 0)
594  {
595    resolution rs = sres(std(i), 0);
596    resolution rm = mres(i,0);
597  }
598
599  resolution rh = hres(i,0);
600  resolution rl = lres(i, 0);
601
602  if (size(#) == 0)
603  {
604    intmat is = betti(rs);
605    intmat im = betti(rm);
606  }
607
608  intmat ih = betti(rh);
609  intmat il = betti(rl);
610
611  if (size(ih) != size(il)){"ERROR: size(ih) != size(il)";return(0);}
612  if (size(#) == 0)
613  {
614    if (size(ih) != size(is)){"ERROR: size(ih) != size(is)";return(0);}
615    if (size(ih) != size(im)){"ERROR: size(ih) != size(im)";return(0);}
616  }
617
618  if (ih != il){"ERROR: ih != il";return(0);}
619  if (size(#) == 0)
620  {
621    if (ih != is){"ERROR: ih != is";return(0);}
622    if (ih != im){"ERROR: ih != im";return(0);}
623  }
624
625  if (size(#) == 0)
626  {
627    list ls = list(rs);
628    list lm = list(rm);
629  }
630  list lh = list(rh);
631  list ll = list(rl);
632
633  if (size(#) == 0)
634  {
635    intmat is_1 = betti(ls);
636    intmat im_1 = betti(lm);
637  }
638  intmat ih_1 = betti(lh);
639  intmat il_1 = betti(ll);
640
641  if (size(ih_1) != size(il_1)){"ERROR: size(ih_1) != size(il_1)";return(0);}
642  if (size(#) == 0)
643  {
644    if (size(ih_1) != size(is_1)){"ERROR: size(ih_1) != size(is_1)";return(0);}
645    if (size(ih_1) != size(im_1)){"ERROR: size(ih_1) != size(im_1)";return(0);}
646  }
647
648  if (ih_1 != il_1){"ERROR: ih_1 != il_1";return(0);}
649  if (size(#) == 0)
650  {
651    if (ih_1 != is_1){"ERROR: ih_1 != is_1";return(0);}
652    if (ih_1 != im_1){"ERROR: ih_1 != im_1";return(0);}
653  }
654
655
656  if (size(ih) != size(ih_1)) {"ERROR: size(ih) != size(ih_1)";return(0);}
657  if (ih != ih_1) {"ERROR: ih != ih_1";return(0);}
658
659  return (ret);
660}
661example
662{
663  "EXAMPLE: "; echo = 2;
664  ring an=0,(w,x,y,z),(dp,C);
665  ideal i=
666    1w2xy+1w2xz+1w2yz+1wxyz+1x2yz+1xy2z+1xyz2,
667    1w4x+1w4z+1w3yz+1w2xyz+1wx2yz+1x2y2z+1xy2z2,
668    1w6+1w5z+1w4xz+1w3xyz+1w2xy2z+1wx2y2z+1x2y2z2;
669  tst_test_res(i);
670  kill an;
671}
672
673/////////////////////////////////////////////////////////////////////////////
674proc tst_rgen_init_weights(int n)
675{
676  intvec v = 1..n;
677  return (v);
678}
679
680proc tst_rgen_init_matrix(int n)
681{
682  intmat m[n][n];
683  int i;
684  // let us emulate lp
685  for (i=1; i<= n; i++)
686  {
687    m[i,i] = 1;
688  }
689  return (m);
690}
691
692proc tst_rgen_generate_block(int n_vars, string simple_ordering, int extra_weights)
693{
694  string order = simple_ordering;
695  if (extra_weights > n_vars)
696  {
697    extra_weights = n_vars;
698  }
699
700  if ((simple_ordering[1] == "W") || (simple_ordering[1] == "w"))
701  {
702    order = order + "(" + string(tst_rgen_init_weights(n_vars)) + ")";
703  }
704  else
705  {
706    if (simple_ordering[1] == "M")
707    {
708      order = order + "(" + string(tst_rgen_init_matrix(n_vars)) + ")";
709    }
710    else
711    {
712      order = order + "(" + string(n_vars) + ")";
713    }
714  }
715  if (extra_weights >= 1)
716  {
717    order = "a(" + string(tst_rgen_init_weights(extra_weights)) + ")," + order;
718  }
719  return (order);
720}
721
722proc tst_rgen_generate_blocks(int n_vars, list simple_orderings, intvec extra_weights)
723{
724  int i;
725  int j;
726  list blocks;
727
728  for (i=1; i<=size(simple_orderings); i++)
729  {
730    for (j=1; j<=size(extra_weights); j++)
731    {
732      blocks = blocks + list(tst_rgen_generate_block(n_vars, simple_orderings[i], extra_weights[j]));
733    }
734  }
735  return (blocks);
736}
737
738proc tst_rgen_generate_product_orderings(int n_vars, list simple_orderings, intvec extra_weights, intvec products)
739{
740  list p_orderings;
741  int i;
742  int nn_vars, j, k,l;
743  list nb_orderings;
744  string n_ordering;
745
746  for (i=1;i<=size(products);i++)
747  {
748    if (products[i] > 1 && products[i] <= n_vars)
749    {
750      nn_vars = n_vars / products[i];
751      nb_orderings = tst_rgen_generate_blocks(nn_vars, simple_orderings, extra_weights);
752      for (j=1; j<=size(nb_orderings); j++)
753      {
754        n_ordering = nb_orderings[j];
755        for (k=2; k<=products[i]; k++)
756        {
757          l = (j + k - 1) %  size(nb_orderings);
758          if (l == 0)
759          {
760            l = size(nb_orderings);
761          }
762          n_ordering = n_ordering + "," + nb_orderings[l];
763        }
764        if (products[i]*nn_vars < n_vars)
765        {
766          n_ordering = n_ordering + ", lp";
767        }
768        p_orderings = p_orderings + list(n_ordering);
769      }
770    }
771    else
772    {
773      if (products[i] == 1)
774      {
775        p_orderings = p_orderings + tst_rgen_generate_blocks(n_vars, simple_orderings, extra_weights);
776      }
777    }
778  }
779  if (size(p_orderings) < 1)
780  {
781    p_orderings = tst_rgen_generate_blocks(n_vars, simple_orderings, extra_weights);
782  }
783  return (p_orderings);
784}
785
786
787proc tst_rgen_init()
788{
789  if (! defined(tst_rgen_charstrs))
790  {
791    list tst_rgen_charstrs;
792    export(tst_rgen_charstrs);
793    tst_rgen_charstrs = list("32003", "0");
794  }
795  if (! defined(tst_rgen_nvars))
796  {
797    intvec tst_rgen_nvars;
798    export(tst_rgen_nvars);
799    tst_rgen_nvars = 1..10;
800  }
801  if (! defined(tst_rgen_simple_orderings))
802  {
803    list tst_rgen_simple_orderings;
804    export(tst_rgen_simple_orderings);
805    tst_rgen_simple_orderings = list("lp", "dp", "Dp", "ls", "ds", "Ds", "wp","Wp","ws","Ws","M");
806  }
807  if (! defined(tst_rgen_comp_orderings))
808  {
809    list tst_rgen_comp_orderings;
810    exportto(Top,tst_rgen_comp_orderings);
811    tst_rgen_comp_orderings = list("", "C", "c", "CC", "cc");
812  }
813  if (! defined(tst_rgen_products))
814  {
815    intvec tst_rgen_products;
816    export(tst_rgen_products);
817    tst_rgen_products = 1..3;
818  }
819  if (! defined(tst_rgen_extra_weights))
820  {
821    intvec tst_rgen_extra_weights;
822    export(tst_rgen_extra_weights);
823    tst_rgen_extra_weights = 0..2;
824  }
825
826  if (! defined(tst_rgen_exp_bounds))
827  {
828    list tst_rgen_exp_bounds;
829    export(tst_rgen_exp_bounds);
830  }
831
832  if (! defined(tst_rgen_char_index))
833  {
834    int tst_rgen_char_index, tst_rgen_var_index, tst_rgen_comp_index, tst_rgen_ordering_index, tst_rgen_exp_bounds_index;
835    list tst_rgen_orderings;
836    exportto(Top, tst_rgen_char_index);
837    exportto(Top, tst_rgen_var_index);
838    exportto(Top, tst_rgen_comp_index);
839    exportto(Top, tst_rgen_ordering_index);
840    exportto(Top, tst_rgen_orderings);
841    exportto(Top, tst_rgen_exp_bounds_index);
842  }
843  tst_rgen_char_index = 1;
844  tst_rgen_var_index = 1;
845  tst_rgen_comp_index = 1;
846  tst_rgen_ordering_index = 0;
847  tst_rgen_exp_bounds_index = 1;
848  tst_rgen_orderings = tst_rgen_generate_product_orderings(tst_rgen_nvars[1], tst_rgen_simple_orderings, tst_rgen_extra_weights, tst_rgen_products);
849}
850
851proc tst_next_ring()
852{
853  tst_rgen_ordering_index++;
854  if (tst_rgen_ordering_index > size(tst_rgen_orderings))
855  {
856    tst_rgen_comp_index++;
857    if (tst_rgen_comp_index > size(tst_rgen_comp_orderings))
858    {
859      tst_rgen_exp_bounds_index++;
860      if (tst_rgen_exp_bounds_index > size(tst_rgen_exp_bounds))
861      {
862        tst_rgen_var_index++;
863        if (tst_rgen_var_index > size(tst_rgen_nvars))
864        {
865          tst_rgen_char_index++;
866          if (tst_rgen_char_index > size(tst_rgen_charstrs))
867          {
868            return ("");
869          }
870          tst_rgen_var_index = 1;
871        }
872        tst_rgen_exp_bounds_index = 1;
873      }
874      tst_rgen_comp_index = 1;
875      tst_rgen_orderings =  tst_rgen_generate_product_orderings(tst_rgen_nvars[tst_rgen_var_index], tst_rgen_simple_orderings, tst_rgen_extra_weights, tst_rgen_products);
876    }
877    tst_rgen_ordering_index = 1;
878  }
879
880  if (tst_rgen_nvars[tst_rgen_var_index] <= 26)
881  {
882    string rs = "(" + tst_rgen_charstrs[tst_rgen_char_index] + "),(" + A_Z("a", tst_rgen_nvars[tst_rgen_var_index]) + "),(";
883  }
884  else
885  {
886    string rs = "(" + tst_rgen_charstrs[tst_rgen_char_index] + "),(x(1.." + string(tst_rgen_nvars[tst_rgen_var_index]) + ")),(";
887  }
888
889  if (tst_rgen_comp_orderings[tst_rgen_comp_index] == "CC")
890  {
891    rs = rs + "C," + tst_rgen_orderings[tst_rgen_ordering_index];
892  }
893  else
894  {
895    if (tst_rgen_comp_orderings[tst_rgen_comp_index] == "cc")
896    {
897      rs = rs + "c," + tst_rgen_orderings[tst_rgen_ordering_index];
898    }
899    else
900    {
901      if (tst_rgen_comp_orderings[tst_rgen_comp_index] == "C")
902      {
903        rs = rs + tst_rgen_orderings[tst_rgen_ordering_index] + ", C";
904      }
905      else
906      {
907        if (tst_rgen_comp_orderings[tst_rgen_comp_index] == "c")
908        {
909          rs = rs + tst_rgen_orderings[tst_rgen_ordering_index] + ",c";
910        }
911        else
912        {
913          rs = rs + tst_rgen_orderings[tst_rgen_ordering_index];
914        }
915      }
916    }
917  }
918  if (size(tst_rgen_exp_bounds) > 0)
919  {
920    if (! defined(tst_rgen_Lring))
921    {
922      string tst_rgen_Lring;
923      exportto(Top,tst_rgen_Lring);
924    }
925    tst_rgen_Lring = rs + ",L(" + string(tst_rgen_exp_bounds[tst_rgen_exp_bounds_index]) + "))";
926    if (system("version") >= 1309)
927    {
928      rs = tst_rgen_Lring;
929    }
930    else
931    {
932      rs = rs + ")";
933    }
934  }
935  else
936  {
937    rs = rs + ")";
938  }
939
940  return (rs);
941}
942
943
944proc tst_FullIdeal()
945{
946  ideal id, mid;
947  int n_vars = nvars(basering);
948  int i,j;
949  for (i=1; i<=n_vars; i++)
950  {
951    mid = maxideal(i);
952    id[i] = mid[1];
953    for (j=2;j<=size(mid); j++)
954    {
955      id[i] = id[i] + mid[j];
956    }
957  }
958  return (id);
959}
960
961proc tst_cyclic(int n)
962{
963  int i, j, k, l;
964  ideal id;
965
966  poly p, q;
967  for (i=1; i<n; i++)
968  {
969    p = 0;
970    k = 1;
971    for (j=1; j<=n; j++)
972    {
973      q = var(j);
974      k = j + 1;
975        if (k > n)
976        {
977          k=1;
978        }
979      for (l=2; l <= i; l++)
980      {
981        q = q*var(k);
982        k++;
983        if (k > n)
984        {
985          k=1;
986        }
987      }
988      p = p + q;
989    }
990    id[i] = p;
991  }
992
993  p = var(1);
994  for (i=2;i<=n;i++)
995  {
996    p = p*var(i);
997  }
998  id[n] = p -1;
999  return (id);
1000}
1001
1002proc tst_hom_cyclic(int n)
1003{
1004  ideal i = tst_cyclic(n);
1005  i[n] = i[n] + 1 + var(n+1)^n;
1006  return (i);
1007}
1008
1009proc tst_TestMult(ideal id, int how_often, int Module)
1010{
1011  int i, j, l, is, s;
1012  module m;
1013  def ret;
1014  poly p;
1015  if (Module > 0)
1016  {
1017    for (i=1; i<= size(id); i++)
1018    {
1019      m[i] = id[i] + gen(2)*id[i];
1020    }
1021    ret = m;
1022  }
1023  else
1024  {
1025    ret = id;
1026  }
1027  l = 0;
1028  for (i=1; i<= how_often; i++)
1029  {
1030    l++;
1031    if (l > size(id))
1032    {
1033      l = 1;
1034    }
1035    for (j=1;j<=size(id);j++)
1036    {
1037      ret[j] = ret[j]*id[l];
1038    }
1039  }
1040  for (i=1; i<=size(ret); i++)
1041  {
1042    is = size(ret[i]);
1043    s = s + is;
1044    string(i) + " : " + string(is) + " : " + string(lead(ret[i]));
1045  }
1046  "s : " + string(s);
1047}
1048
1049proc tst_TestAdd(ideal id, int how_often, int Module)
1050{
1051  int i, j, k, l;
1052  module m;
1053  ideal idl = 1, maxideal(1);
1054
1055  if (Module > 0)
1056  {
1057    for (i=1; i<= size(id); i++)
1058    {
1059      m[i] = id[i] + gen(2)*id[i];
1060    }
1061  }
1062  def r,p;
1063  if (Module > 0)
1064  {
1065    r = m;
1066  }
1067  else
1068  {
1069    r = id;
1070  }
1071  l = 0;
1072  for (j=1; j<= how_often; j++)
1073  {
1074    l++;
1075    if (l > size(idl))
1076    {
1077      l = 1;
1078    }
1079    for (k=1; k<=size(r); k++)
1080    {
1081      p = idl[l]*r[k];
1082      for (i=1; i<=k;i++)
1083      {
1084        p = p + r[i];
1085      }
1086      r[k] = p;
1087    }
1088  }
1089  int is, s;
1090  for (i=1; i<=size(r); i++)
1091  {
1092    is = size(r[i]);
1093    s = s + is;
1094    string(i) + " : " + string(is) + " : " + string(lead(r[i]));
1095  }
1096  "s : " + string(s);
1097}
1098
1099proc tst_PrintStats(def id)
1100{
1101  int i, is, s;
1102
1103  for (i=1; i<=size(id); i++)
1104  {
1105    is = size(id[i]);
1106    s = s + is;
1107    string(i) + " : " + string(is) + " : " + string(lead(id[i]));
1108  }
1109  "s : " + string(s);
1110}
1111
Note: See TracBrowser for help on using the repository browser.