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