source: git/Singular/LIB/tst.lib @ 4c20ee

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