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

spielwiese
Last change on this file since 341696 was 341696, checked in by Hans Schönemann <hannes@…>, 15 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
RevLine 
[341696]1// $Id$
[cb13f0]2//(obachman, last modified 6/30/98)
[9ebfb1b]3/////////////////////////////////////////////////////////////////////////////
[a31a46]4
[341696]5version="$Id$";
[fd3fb7]6category="Utilities";
[5480da]7info="
[a23294]8LIBRARY:  tst.lib      Procedures for running automatic tst Tests
[a31a46]9
[f34c37c]10PROCEDURES:
[5480da]11 tst_system(s)          returns string which is stdout of system(\"sh\", s)
[82716e]12 tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout),
[6b8aae5]13                                   prepending prefix \"// tst_ignore:\"
[620c25]14 tst_init()             writes some identification data to GetTstStatusFile()
[7d56875]15 tst_status([any])      writes status info to GetTstStatusFile()
[2f436b]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
[917fb5]20 tst_groebnerTest(ideal i)
21                        tests groebner command
22 tst_stdEqual(ideal i1, ideal i2)
[9ebfb1b]23                        test whether two std's are \"equal\"
[c93354]24
[b9b906]25 tst_test_res(ideal i)  test different res commands for homog ideal i
[5480da]26";
27
[9ebfb1b]28/////////////////////////////////////////////////////////////////////////////
[620c25]29proc tst_system(string s, list #)
[d2b2a7]30"USAGE:    tst_system(s); s string
[ac6554]31RETURN:   string which is stdout and stderr of system(\"sh\", s)
32EXAMPLE:  example tst_system; shows examples"
[a31a46]33{
34  string tmpfile = "/tmp/tst_" + string(system("pid"));
35  int errno;
[82716e]36
[a31a46]37  s = s + " 1>" + tmpfile + " 2>&1";
38  errno = system("sh", s);
39  s = read(tmpfile);
[cb13f0]40  errno = system("sh", "rm -f " + tmpfile);
[6b32990]41  if (size(#) > 0 && size(s) > 1)
[620c25]42  {
[6b32990]43    s = s[1, size(s) -1];
[620c25]44  }
[a31a46]45  return (s);
46}
47example
48{
49  "EXAMPLE"; echo = 2;
[7d56875]50  string s = tst_system("echo This is an example of tst_system");
[a31a46]51  "The following is what the system call wrote to stdout: " + s;
52}
53
[620c25]54proc tst_ignore(list #)
[82716e]55"USAGE:    tst_ignore(any,[keyword], [link])
[a31a46]56            any     -- valid argument to string()
[917fb5]57            keyword -- an arbitrary string
[82716e]58            link    -- a link which can be written to
59RETURN:   none; writes string(any) to link (or stdout, if no link given),
[917fb5]60          prepending prefix \"// tst_ignore:\", or
[6b8aae5]61                            \"// tst_ignore:keyword hostname:\",
[cb13f0]62                            if keyword was given.
63          Should be used in tst files to output system dependent data
64          (like date, pathnames).
[a31a46]65EXAMPLE:  example tst_ignore; shows examples
[d2b2a7]66"
[a31a46]67{
[7baf8c]68  if (! defined(tst_no_status))
[a31a46]69  {
[7baf8c]70    string s;
71    string keyword = "";
72    link outlink = "";
[82716e]73
[7baf8c]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)
[a31a46]85    {
86      keyword = #[2];
[7baf8c]87      outlink = #[3];
[a31a46]88    }
[7baf8c]89    if (size(#) == 2)
[a31a46]90    {
[7baf8c]91      if (typeof(#[2]) == "string")
92      {
93        keyword = #[2];
94      }
95      else
96      {
97        outlink = #[2];
98      }
[a31a46]99    }
[82716e]100
[7baf8c]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    }
[82716e]108
[7baf8c]109    if (status(outlink, "open", "no"))
110    {
111      open(outlink);
112    }
[cb13f0]113
[7baf8c]114    if (status(outlink, "write", "not ready"))
115    {
[3754ca]116      "Error tst_ignore: Cannot write to link";
[7baf8c]117      outlink;
118      "Usage: tst_ignore (any,[keyword], [link]);";
119      return();
120    }
[82716e]121
[7baf8c]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    }
[cb13f0]131  }
[a31a46]132}
133example
134{
[82716e]135  "EXAMPLE";
[a31a46]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
[620c25]146static proc Get_tst_timer()
[6b8aae5]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  {
[38c165]156    execute("int tst_int_timer = " + tst_timer[15,size(tst_timer)] + ";");
[6b8aae5]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
[620c25]166static proc GetTstStatusFile()
167{
168  if (!defined(tst_status_file))
169  {
170    return ("tst_status.out");
171  }
[917fb5]172  else
[620c25]173  {
174    return (tst_status_file);
175  }
176}
[917fb5]177
[620c25]178static proc tst_status_out (def prefix, def what, list #)
179{
180  string outstring;
[917fb5]181
[620c25]182  outstring = string(prefix) + " >> " + string(what);
183  if (size(#) > 0)
184  {
[917fb5]185    outstring = outstring + " :: " +
[620c25]186      tst_system("hostname", 1) + ":" + string(#[1]);
187  }
188  write(":a " + GetTstStatusFile(), outstring);
189}
[917fb5]190
[cb13f0]191proc tst_status (list #)
[2f436b]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.
[b9b906]197         If no integer argument is given, the elapsed CPU time since
[2f436b]198         the last call to tst_status() is reported.
199         If an integer argument is given, the elapsed CPU time since the
[3754ca]200         start-up of @sc{Singular} is reported.
[2f436b]201         If prefix is given, output reported start with prefix.
[917fb5]202NOTE:     Should be used regularly within tst files to enable automatic
[cb13f0]203          tracking of memory and time performance.
204EXAMPLE: example tst_status; shows example
[2f436b]205SEE ALSO: tst_init
[cb13f0]206"
207{
[2f436b]208  int start_up;
[b9b906]209
[2f436b]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  }
[7baf8c]225  if (! defined(tst_no_status))
[620c25]226  {
[7baf8c]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    }
[917fb5]236
[2f436b]237    if (!defined(prefix))
[7baf8c]238    {
[2f436b]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);
[7baf8c]247    }
248    else
249    {
[2f436b]250      tst_status_out(prefix, "tst_timer", timer - Get_tst_timer());
[7baf8c]251      Set_tst_timer(timer);
252    }
[cb13f0]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
[917fb5]265
[2f436b]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.
[a31a46]274EXAMPLE: example tst_init; shows example
[d2b2a7]275"
[a31a46]276{
[7baf8c]277  if (! defined(tst_no_status))
278  {
[2f436b]279    string outfile = "";
[b9b906]280
[2f436b]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    }
[7baf8c]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")));
[447527]302    tst_status_out("init", "ticks   :" + string(system("--ticks-per-sec")));
[7baf8c]303    "init >> " + GetTstStatusFile();
304  }
[a31a46]305}
306example
307{
308  "EXAMPLE";  echo = 2;
309  tst_init();
310}
311
[2f436b]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";
[b9b906]393
[2f436b]394  if (size(#) > 0)
395  {
396    prefix = string(#[1]);
397  }
398  tst_status_out(prefix, "tst-Timer", tt);
399}
400
[9ebfb1b]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,
[917fb5]408        and if they reduce each other to zero, and if their leading ideals
[9ebfb1b]409        are equal
410        On success, times of std - groebner is written with tst_ignore, and
[917fb5]411        times are added to global variables tst_std_time and
412        tst_groebner_time. If v given, and <= 0, short ideal
[7a5e7c]413        characteristic is printed, if v > 0, ideals are printed.
[9ebfb1b]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;
[917fb5]421
[9ebfb1b]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
[917fb5]467
[9ebfb1b]468//
469// A routine which test for equality of "std-bases"
[917fb5]470//
[9ebfb1b]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,
[917fb5]476       and if they reduce each other to zero, and if their leading ideals
[9ebfb1b]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);
[917fb5]486
[9ebfb1b]487  ideal ri1 = simplify(interred(i1), 1);
488  ideal ri2 = simplify(interred(i2), 1);
[917fb5]489
[9ebfb1b]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    {
[3754ca]504      "Error in tst_stdEqual: " + string(i) + " th polynomials differ";
[9ebfb1b]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;
[917fb5]517
[9ebfb1b]518      ideal si1 = simplify(i1, 7);
519      ideal si2 = simplify(i2, 7);
[917fb5]520
[9ebfb1b]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
[917fb5]577
[f932563]578proc tst_test_res(ideal i, list #)
[a31a46]579
[f932563]580"USAGE:    tst_test_res(ideal i, only_lres_and_hres)
[c93354]581RETURN:    1, if ok; 0 on error
582PURPOSE:   Tests sres, lres, hres, mres with betti commands and conversions
[f932563]583           If optinal third argument is given, test only lres and hres
[c93354]584EXAMPLE:  example tst_test_res shows an example"
585{
586  int ret = 1;
[b9b906]587
[c93354]588  if (! homog(i))
589  {
590    ERROR("ERROR: input ideal needs to be homogenous ");
591  }
[b9b906]592
[f932563]593  if (size(#) == 0)
594  {
[908c36]595    resolution rs = sres(std(i), 0);
596    resolution rm = mres(i,0);
[f932563]597  }
[b9b906]598
[908c36]599  resolution rh = hres(i,0);
600  resolution rl = lres(i, 0);
[b9b906]601
[f932563]602  if (size(#) == 0)
603  {
[908c36]604    intmat is = betti(rs);
605    intmat im = betti(rm);
[f932563]606  }
[b9b906]607
[908c36]608  intmat ih = betti(rh);
609  intmat il = betti(rl);
[c93354]610
[c54075]611  if (size(ih) != size(il)){"ERROR: size(ih) != size(il)";return(0);}
[f932563]612  if (size(#) == 0)
613  {
[c54075]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);}
[f932563]616  }
[b9b906]617
[c54075]618  if (ih != il){"ERROR: ih != il";return(0);}
[f932563]619  if (size(#) == 0)
620  {
[c54075]621    if (ih != is){"ERROR: ih != is";return(0);}
622    if (ih != im){"ERROR: ih != im";return(0);}
[f932563]623  }
[c93354]624
[f932563]625  if (size(#) == 0)
626  {
[908c36]627    list ls = list(rs);
628    list lm = list(rm);
[f932563]629  }
[908c36]630  list lh = list(rh);
631  list ll = list(rl);
[c93354]632
[f932563]633  if (size(#) == 0)
634  {
[908c36]635    intmat is_1 = betti(ls);
636    intmat im_1 = betti(lm);
[f932563]637  }
[908c36]638  intmat ih_1 = betti(lh);
639  intmat il_1 = betti(ll);
[c93354]640
[c54075]641  if (size(ih_1) != size(il_1)){"ERROR: size(ih_1) != size(il_1)";return(0);}
[f932563]642  if (size(#) == 0)
643  {
[c54075]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);}
[f932563]646  }
[b9b906]647
[c54075]648  if (ih_1 != il_1){"ERROR: ih_1 != il_1";return(0);}
[f932563]649  if (size(#) == 0)
650  {
[c54075]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);}
[f932563]653  }
[c93354]654
[b9b906]655
[c54075]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);}
[c93354]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}
[82716e]672
[55b8ae]673/////////////////////////////////////////////////////////////////////////////
674proc tst_rgen_init_weights(int n)
675{
676  intvec v = 1..n;
677  return (v);
678}
679
[ec7aac]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);
[b9b906]690}
691
[55b8ae]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  }
[b9b906]699
[55b8ae]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  {
[b9b906]706    if (simple_ordering[1] == "M")
[55b8ae]707    {
[ec7aac]708      order = order + "(" + string(tst_rgen_init_matrix(n_vars)) + ")";
[55b8ae]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;
[b9b906]727
[55b8ae]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;
[b9b906]745
[55b8ae]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    }
[b9b906]771    else
[55b8ae]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;
[1fc5ce]810    exportto(Top,tst_rgen_comp_orderings);
[55b8ae]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
[ec7aac]826  if (! defined(tst_rgen_exp_bounds))
827  {
828    list tst_rgen_exp_bounds;
829    export(tst_rgen_exp_bounds);
830  }
[b9b906]831
[55b8ae]832  if (! defined(tst_rgen_char_index))
833  {
[ec7aac]834    int tst_rgen_char_index, tst_rgen_var_index, tst_rgen_comp_index, tst_rgen_ordering_index, tst_rgen_exp_bounds_index;
[55b8ae]835    list tst_rgen_orderings;
[1fc5ce]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);
[55b8ae]842  }
843  tst_rgen_char_index = 1;
844  tst_rgen_var_index = 1;
845  tst_rgen_comp_index = 1;
[ec7aac]846  tst_rgen_ordering_index = 0;
847  tst_rgen_exp_bounds_index = 1;
[55b8ae]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    {
[ec7aac]859      tst_rgen_exp_bounds_index++;
860      if (tst_rgen_exp_bounds_index > size(tst_rgen_exp_bounds))
[55b8ae]861      {
[ec7aac]862        tst_rgen_var_index++;
863        if (tst_rgen_var_index > size(tst_rgen_nvars))
[55b8ae]864        {
[ec7aac]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;
[55b8ae]871        }
[ec7aac]872        tst_rgen_exp_bounds_index = 1;
[55b8ae]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  }
[b9b906]879
[ec7aac]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  }
[55b8ae]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    }
[b9b906]899    else
[55b8ae]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      }
[b9b906]905      else
[55b8ae]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  }
[b9b906]918  if (size(tst_rgen_exp_bounds) > 0)
[ec7aac]919  {
920    if (! defined(tst_rgen_Lring))
921    {
922      string tst_rgen_Lring;
[1fc5ce]923      exportto(Top,tst_rgen_Lring);
[ec7aac]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  }
[b9b906]939
[55b8ae]940  return (rs);
941}
942
943
[ec7aac]944proc tst_FullIdeal()
[55b8ae]945{
[ec7aac]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    }
[55b8ae]957  }
[ec7aac]958  return (id);
[55b8ae]959}
960
[ec7aac]961proc tst_cyclic(int n)
[55b8ae]962{
963  int i, j, k, l;
[ec7aac]964  ideal id;
[b9b906]965
[ec7aac]966  poly p, q;
967  for (i=1; i<n; i++)
[55b8ae]968  {
[ec7aac]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;
[55b8ae]991  }
[b9b906]992
[ec7aac]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
[5de8c8]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
[ec7aac]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)
[55b8ae]1016  {
[ec7aac]1017    for (i=1; i<= size(id); i++)
[55b8ae]1018    {
[ec7aac]1019      m[i] = id[i] + gen(2)*id[i];
[55b8ae]1020    }
[ec7aac]1021    ret = m;
1022  }
1023  else
1024  {
1025    ret = id;
[55b8ae]1026  }
1027  l = 0;
[ec7aac]1028  for (i=1; i<= how_often; i++)
[55b8ae]1029  {
1030    l++;
1031    if (l > size(id))
1032    {
[ec7aac]1033      l = 1;
[55b8ae]1034    }
[ec7aac]1035    for (j=1;j<=size(id);j++)
[55b8ae]1036    {
[ec7aac]1037      ret[j] = ret[j]*id[l];
[55b8ae]1038    }
1039  }
[ec7aac]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);
[55b8ae]1047}
1048
[ec7aac]1049proc tst_TestAdd(ideal id, int how_often, int Module)
[55b8ae]1050{
1051  int i, j, k, l;
[ec7aac]1052  module m;
1053  ideal idl = 1, maxideal(1);
[b9b906]1054
[ec7aac]1055  if (Module > 0)
[55b8ae]1056  {
[ec7aac]1057    for (i=1; i<= size(id); i++)
[55b8ae]1058    {
[ec7aac]1059      m[i] = id[i] + gen(2)*id[i];
[55b8ae]1060    }
1061  }
[ec7aac]1062  def r,p;
1063  if (Module > 0)
1064  {
1065    r = m;
1066  }
1067  else
1068  {
1069    r = id;
1070  }
[55b8ae]1071  l = 0;
1072  for (j=1; j<= how_often; j++)
1073  {
1074    l++;
[ec7aac]1075    if (l > size(idl))
[55b8ae]1076    {
[ec7aac]1077      l = 1;
[55b8ae]1078    }
[ec7aac]1079    for (k=1; k<=size(r); k++)
[55b8ae]1080    {
[ec7aac]1081      p = idl[l]*r[k];
1082      for (i=1; i<=k;i++)
[55b8ae]1083      {
[ec7aac]1084        p = p + r[i];
[55b8ae]1085      }
[ec7aac]1086      r[k] = p;
[55b8ae]1087    }
1088  }
[ec7aac]1089  int is, s;
1090  for (i=1; i<=size(r); i++)
[55b8ae]1091  {
[ec7aac]1092    is = size(r[i]);
1093    s = s + is;
1094    string(i) + " : " + string(is) + " : " + string(lead(r[i]));
[55b8ae]1095  }
[ec7aac]1096  "s : " + string(s);
[55b8ae]1097}
1098
1099proc tst_PrintStats(def id)
1100{
1101  int i, is, s;
[b9b906]1102
[55b8ae]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}
[b9b906]1111
Note: See TracBrowser for help on using the repository browser.