Annotation of OpenXM/src/kan96xx/Kan/dr.sm1, Revision 1.12
1.12 ! takayama 1: % $OpenXM: OpenXM/src/kan96xx/Kan/dr.sm1,v 1.11 2003/05/15 00:42:07 takayama Exp $
1.1 maekawa 2: %% dr.sm1 (Define Ring) 1994/9/25, 26
3: %% This file is error clean.
4:
5: @@@.quiet { }
1.5 takayama 6: { (macro package : dr.sm1, 9/26,1995 --- Version 12/10, 2000. ) message } ifelse
1.1 maekawa 7:
8: /ctrlC-hook {
9: %%% define your own routing in case of error.
10: } def
11: [(ctrlC-hook)
12: [(When ctrl-C is pressed, this function is executed.)
13: (User can define one's own ctrlC-hook function.)
14: ]] putUsages
15:
16: %% n evenQ bool
17: /evenQ {
18: /arg1 set
19: arg1 2 idiv 2 mul arg1 sub 0 eq
20: { true }
21: { false } ifelse
22: } def
23:
24: %% (x,y,z) polynomial_ring [x-list, d-list , paramList]
25: /ring_of_polynomials {
26: /arg1 set
27: [/vars /n /i /xList /dList /param] pushVariables
28: %dup print (-----) message
29: [
30: (mmLarger) (matrix) switch_function
31: (mpMult) (poly) switch_function
32: (red@) (module1) switch_function
33: (groebner) (standard) switch_function
34: (isSameComponent) (x) switch_function
35:
36: [arg1 to_records pop] /vars set
37: vars length evenQ
38: { }
39: { vars [(PAD)] join /vars set }
40: ifelse
41: vars length 2 idiv /n set
42: [ << n 1 sub >> -1 0
43: { /i set
44: vars i get
45: } for
46: ] /xList set
47: [ << n 1 sub >> -1 0
48: { /i set
49: vars << i n add >> get
50: } for
51: ] /dList set
52:
53: [(H)] xList join [@@@.esymbol] join /xList set
54: [(h)] dList join [@@@.Esymbol] join /dList set
55: [0 %% dummy characteristic
56: << xList length >> << xList length >> << xList length >>
57: << xList length >>
58: << xList length 1 sub >> << xList length >> << xList length >>
59: << xList length >>
60: ] /param set
61:
62: [xList dList param] /arg1 set
63: ] pop
64: popVariables
65: arg1
66: } def
67:
68: %% (x,y,z) polynomial_ring [x-list, d-list , paramList]
69: %% with no graduation and homogenization variables.
70: /ring_of_polynomials2 {
71: /arg1 set
72: [/vars /n /i /xList /dList /param] pushVariables
73: %dup print (-----) message
74: [
75: (mmLarger) (matrix) switch_function
76: (mpMult) (poly) switch_function
77: (red@) (module1) switch_function
78: (groebner) (standard) switch_function
79: (isSameComponent) (x) switch_function
80:
81: [arg1 to_records pop] /vars set
82: vars length evenQ
83: { }
84: { vars [(PAD)] join /vars set }
85: ifelse
86: vars length 2 idiv /n set
87: [ << n 1 sub >> -1 0
88: { /i set
89: vars i get
90: } for
91: ] /xList set
92: [ << n 1 sub >> -1 0
93: { /i set
94: vars << i n add >> get
95: } for
96: ] /dList set
97:
98: [0 %% dummy characteristic
99: << xList length >> << xList length >> << xList length >>
100: << xList length >>
101: << xList length >> << xList length >> << xList length >>
102: << xList length >>
103: ] /param set
104:
105: [xList dList param] /arg1 set
106: ] pop
107: popVariables
108: arg1
109: } def
110:
111: %% (x,y,z) polynomial_ring [x-list, d-list , paramList]
112: %% with no homogenization variables.
113: /ring_of_polynomials3 {
114: /arg1 set
115: [/vars /n /i /xList /dList /param] pushVariables
116: %dup print (-----) message
117: [
118: (mmLarger) (matrix) switch_function
119: (mpMult) (poly) switch_function
120: (red@) (module1) switch_function
121: (groebner) (standard) switch_function
122: (isSameComponent) (x) switch_function
123:
124: [arg1 to_records pop] /vars set
125: vars length evenQ
126: { }
127: { vars [(PAD)] join /vars set }
128: ifelse
129: vars length 2 idiv /n set
130: [ << n 1 sub >> -1 0
131: { /i set
132: vars i get
133: } for
134: ] /xList set
135: xList [@@@.esymbol] join /xList set
136: [ << n 1 sub >> -1 0
137: { /i set
138: vars << i n add >> get
139: } for
140: ] /dList set
141: dList [@@@.Esymbol] join /dList set
142:
143: [0 %% dummy characteristic
144: << xList length >> << xList length >> << xList length >>
145: << xList length >>
146: << xList length >> << xList length >> << xList length >>
147: << xList length >>
148: ] /param set
149:
150: [xList dList param] /arg1 set
151: ] pop
152: popVariables
153: arg1
154: } def
155:
156: /ring_of_differential_operators {
157: /arg1 set
158: [/vars /n /i /xList /dList /param] pushVariables
159: [
160: (mmLarger) (matrix) switch_function
161: (mpMult) (diff) switch_function
162: (red@) (module1) switch_function
163: (groebner) (standard) switch_function
164: (isSameComponent) (x) switch_function
165:
166: [arg1 to_records pop] /vars set %[x y z]
167: vars reverse /xList set %[z y x]
168: vars {@@@.Dsymbol 2 1 roll 2 cat_n} map
169: reverse /dList set %[Dz Dy Dx]
170: [(H)] xList join [@@@.esymbol] join /xList set
171: [(h)] dList join [@@@.Esymbol] join /dList set
172: [0 1 1 1 << xList length >>
173: 1 1 1 << xList length 1 sub >> ] /param set
174: [ xList dList param ] /arg1 set
175: ] pop
176: popVariables
177: arg1
178: } def
179:
180: /ring_of_differential_operators3 {
181: %% with no homogenization variables.
182: /arg1 set
183: [/vars /n /i /xList /dList /param] pushVariables
184: [
185: (mmLarger) (matrix) switch_function
186: (mpMult) (diff) switch_function
187: (red@) (module1) switch_function
188: (groebner) (standard) switch_function
189: (isSameComponent) (x) switch_function
190:
191: [arg1 to_records pop] /vars set %[x y z]
192: vars reverse /xList set %[z y x]
193: vars {@@@.Dsymbol 2 1 roll 2 cat_n} map
194: reverse /dList set %[Dz Dy Dx]
195: xList [@@@.esymbol] join /xList set
196: dList [@@@.Esymbol] join /dList set
197: [0 0 0 0 << xList length >>
198: 0 0 0 << xList length 1 sub >> ] /param set
199: [ xList dList param ] /arg1 set
200: ] pop
201: popVariables
202: arg1
203: } def
204:
205: /ring_of_q_difference_operators {
206: /arg1 set
207: [/vars /n /i /xList /dList /param] pushVariables
208: [
209: (mmLarger) (matrix) switch_function
210: (mpMult) (diff) switch_function
211: (red@) (module1) switch_function
212: (groebner) (standard) switch_function
213: (isSameComponent) (x) switch_function
214:
215: [arg1 to_records pop] /vars set %[x y z]
216: vars reverse /xList set %[z y x]
217: vars {@@@.Qsymbol 2 1 roll 2 cat_n} map
218: reverse /dList set %[Dz Dy Dx]
219: [(q)] xList join [@@@.esymbol] join /xList set
220: [(h)] dList join [@@@.Esymbol] join /dList set
221: [0 1 << xList length >> << xList length >> << xList length >>
222: 1 << xList length 1 sub >> << xList length >> << xList length >> ]
223: /param set
224: [ xList dList param ] /arg1 set
225: ] pop
226: popVariables
227: arg1
228: } def
229:
230: /ring_of_q_difference_operators3 {
231: %% with no homogenization and q variables.
232: /arg1 set
233: [/vars /n /i /xList /dList /param] pushVariables
234: [
235: (mmLarger) (matrix) switch_function
236: (mpMult) (diff) switch_function
237: (red@) (module1) switch_function
238: (groebner) (standard) switch_function
239: (isSameComponent) (x) switch_function
240:
241: [arg1 to_records pop] /vars set %[x y z]
242: vars reverse /xList set %[z y x]
243: vars {@@@.Qsymbol 2 1 roll 2 cat_n} map
244: reverse /dList set %[Dz Dy Dx]
245: xList [@@@.esymbol] join /xList set
246: dList [@@@.Esymbol] join /dList set
247: [0 0 << xList length >> << xList length >> << xList length >>
248: 0 << xList length 1 sub >> << xList length >> << xList length >> ]
249: /param set
250: [ xList dList param ] /arg1 set
251: ] pop
252: popVariables
253: arg1
254: } def
255:
256: /ring_of_difference_operators {
257: /arg1 set
258: [/vars /n /i /xList /dList /param] pushVariables
259: [
1.8 takayama 260: (This is an obsolete macro. Use ring_of_differential_difference_operators)
261: error
1.1 maekawa 262: (mmLarger) (matrix) switch_function
263: (mpMult) (difference) switch_function
264: (red@) (module1) switch_function
265: (groebner) (standard) switch_function
266: (isSameComponent) (x) switch_function
267:
268: [arg1 to_records pop] /vars set %[x y z]
269: vars reverse /xList set %[z y x]
270: vars {@@@.diffEsymbol 2 1 roll 2 cat_n} map
271: reverse /dList set %[Dz Dy Dx]
272: [(H)] xList join [@@@.esymbol] join /xList set
273: [(h)] dList join [@@@.Esymbol] join /dList set
274: [0 1 1 << xList length >> << xList length >>
275: 1 1 << xList length 1 sub >> << xList length >> ] /param set
276: [ xList dList param ] /arg1 set
277: ] pop
278: popVariables
279: arg1
280: } def
281:
282:
1.8 takayama 283: /ring_of_differential_difference_operators {
284: /arg1 set
285: [/vars /n /i /xList /dList /param /dvar /evar /vars2 ] pushVariables
286: [
287: /vars arg1 def
288: vars tag 6 eq not {
289: ( List is expected as the argument for ring_of_differential_difference_operators ) error
290: } { } ifelse
291: vars 0 get /dvar set
292: vars 1 get /evar set
293: (mmLarger) (matrix) switch_function
294: (mpMult) (difference) switch_function
295: (red@) (module1) switch_function
296: (groebner) (standard) switch_function
297: (isSameComponent) (x) switch_function
298:
299: [dvar to_records pop] /vars set %[x y z]
300: vars reverse /xList set %[z y x]
301:
302: [evar to_records pop] /vars2 set %[s1 s2]
303:
304: vars2 reverse {@@@.Esymbol 2 1 roll 2 cat_n} map
305: xList
306: join /xList set %[Es2 Es1 z y x]
307:
308: vars2 reverse
309: vars {@@@.Dsymbol 2 1 roll 2 cat_n} map
310: reverse join /dList set %[s2 s1 Dz Dy Dx]
311: [(H)] xList join [@@@.esymbol] join /xList set
312: [(h)] dList join [@@@.Esymbol] join /dList set
313: [0 1 1 << vars2 length 1 add >> << xList length >>
314: 1 1 << vars2 length 1 add >> << xList length 1 sub >> ] /param set
315: [ xList dList param ] /arg1 set
316: ] pop
317: popVariables
318: arg1
319: } def
1.1 maekawa 320:
321: /reverse {
322: /arg1 set
323: arg1 length 1 lt
324: { [ ] }
325: {
326: [
327: << arg1 length 1 sub >> -1 0
328: {
329: arg1 2 1 roll get
330: } for
331: ]
332: } ifelse
333: } def
334:
335: /memberQ {
336: %% a set0 memberQ bool
337: /arg2 set /arg1 set
338: [/a /set0 /flag /i ] pushVariables
339: [
340: /a arg1 def /set0 arg2 def
341: /flag 0 def
342: 0 1 << set0 length 1 sub >>
343: {
344: /i set
345: << set0 i get >> a eq
346: {
347: /flag 1 def
348: }
349: { }
350: ifelse
351: } for
352: ] pop
353: /arg1 flag def
354: popVariables
355: arg1
356: } def
357:
358: /transpose {
359: /arg1 set
360: [/mat /m /n /ans /i /j] pushVariables
361: [
362: /mat arg1 def
363: /m mat length def
364: mat 0 get isArray
365: { }
366: { (transpose: Argument must be an array of arrays.) error }
367: ifelse
368: /n mat 0 get length def
369: /ans [ 1 1 n { pop [ 1 1 m { pop 0 } for ]} for ] def
370: 0 1 << m 1 sub >> {
371: /i set
372: 0 1 << n 1 sub >> {
373: /j set
374: ans [ j i ] << mat i get j get >> put
375: } for
376: } for
377: /arg1 ans def
378: ] pop
379: popVariables
380: arg1
381: } def
382:
383:
384: /getPerm {
385: %% old new getPerm perm
386: /arg2 set /arg1 set
387: [/old /new /i /j /p] pushVariables
388: [
389: /old arg1 def
390: /new arg2 def
391: [
392: /p old length def
393: 0 1 << p 1 sub >>
394: {
395: /i set
396: 0 1 << p 1 sub >>
397: {
398: /j set
399: old i get
400: new j get
401: eq
402: { j }
403: { } ifelse
404: } for
405: } for
406: ] /arg1 set
407: ] pop
408: popVariables
409: arg1
410: } def
411:
412: /permuteOrderMatrix {
413: %% order perm puermuteOrderMatrix newOrder
414: /arg2 set /arg1 set
415: [/order /perm /newOrder /k ] pushVariables
416: [
417: /order arg1 def
418: /perm arg2 def
419: order transpose /order set
420: order 1 copy /newOrder set pop
421:
422: 0 1 << perm length 1 sub >>
423: {
424: /k set
425: newOrder << perm k get >> << order k get >> put
426: } for
427: newOrder transpose /newOrder set
428: ] pop
429: /arg1 newOrder def
430: popVariables
431: arg1
432: } def
433:
434:
435:
436: /complement {
437: %% set0 universe complement compl
438: /arg2 set /arg1 set
439: [/set0 /universe /compl /i] pushVariables
440: /set0 arg1 def /universe arg2 def
441: [
442: 0 1 << universe length 1 sub >>
443: {
444: /i set
445: << universe i get >> set0 memberQ
446: { }
447: { universe i get }
448: ifelse
449: } for
450: ] /arg1 set
451: popVariables
452: arg1
453: } def
454:
455:
456: %%% from order.sm1
457:
458: %% size i evec [0 0 ... 0 1 0 ... 0]
459: /evec {
460: /arg2 set /arg1 set
461: [/size /iii] pushVariables
462: /size arg1 def /iii arg2 def
463: [
464: 0 1 << size 1 sub >>
465: {
466: iii eq
467: { 1 }
468: { 0 }
469: ifelse
470: } for
471: ] /arg1 set
472: popVariables
473: arg1
474: } def
475:
476: %% size i evec_neg [0 0 ... 0 -1 0 ... 0]
477: /evec_neg {
478: /arg2 set /arg1 set
479: [/size /iii] pushVariables
480: /size arg1 def /iii arg2 def
481: [
482: 0 1 << size 1 sub >>
483: {
484: iii eq
485: { -1 }
486: { 0 }
487: ifelse
488: } for
489: ] /arg1 set
490: popVariables
491: arg1
492: } def
493:
494:
495: %% size i j e_ij << matrix e(i,j) >>
496: /e_ij {
497: /arg3 set /arg2 set /arg1 set
498: [/size /k /i /j] pushVariables
499: [
500: /size arg1 def /i arg2 def /j arg3 def
501: [ 0 1 << size 1 sub >>
502: {
503: /k set
504: k i eq
505: { size j evec }
506: {
507: k j eq
508: { size i evec }
509: { size k evec }
510: ifelse
511: } ifelse
512: } for
513: ] /arg1 set
514: ] pop
515: popVariables
516: arg1
517: } def
518:
519:
520: %% size i j d_ij << matrix E_{ij} >>
521: /d_ij {
522: /arg3 set /arg2 set /arg1 set
523: [/size /k /i /j] pushVariables
524: [
525: /size arg1 def /i arg2 def /j arg3 def
526: [ 0 1 << size 1 sub >>
527: {
528: /k set
529: k i eq
530: { size j evec }
531: {
532: [ 0 1 << size 1 sub >> { pop 0} for ]
533: } ifelse
534: } for
535: ] /arg1 set
536: ] pop
537: popVariables
538: arg1
539: } def
540:
541: %% size matid << id matrix >>
542: /matid {
543: /arg1 set
544: [/size /k ] pushVariables
545: [
546: /size arg1 def
547: [ 0 1 << size 1 sub >>
548: {
549: /k set
550: size k evec
551: } for
552: ] /arg1 set
553: ] pop
554: popVariables
555: arg1
556: } def
557:
558:
559: %% m1 m2 oplus
560: /oplus {
561: /arg2 set /arg1 set
562: [/m1 /m2 /n /m /k ] pushVariables
563: [
564: /m1 arg1 def /m2 arg2 def
565: m1 length /n set
566: m2 length /m set
567: [
568: 0 1 << n m add 1 sub >>
569: {
570: /k set
571: k n lt
572: {
573: << m1 k get >> << m -1 evec >> join
574: }
575: {
576: << n -1 evec >> << m2 << k n sub >> get >> join
577: } ifelse
578: } for
579: ] /arg1 set
580: ] pop
581: popVariables
582: arg1
583: } def
584:
585: %%%%%%%%%%%%%%%%%%%%%%%
586:
587: /eliminationOrderTemplate { %% esize >= 1
588: %% if esize == 0, it returns reverse lexicographic order.
589: %% m esize eliminationOrderTemplate mat
590: /arg2 set /arg1 set
591: [/m /esize /m1 /m2 /k ] pushVariables
592: [
593: /m arg1 def /esize arg2 def
594: /m1 m esize sub 1 sub def
595: /m2 esize 1 sub def
596: [esize 0 gt
597: {
598: [1 1 esize
599: { pop 1 } for
600: esize 1 << m 1 sub >>
601: { pop 0 } for
602: ] %% 1st vector
603: }
604: { } ifelse
605:
606: m esize gt
607: {
608: [1 1 esize
609: { pop 0 } for
610: esize 1 << m 1 sub >>
611: { pop 1 } for
612: ] %% 2nd vector
613: }
614: { } ifelse
615:
616: m1 0 gt
617: {
618: m 1 sub -1 << m m1 sub >>
619: {
620: /k set
621: m k evec_neg
622: } for
623: }
624: { } ifelse
625:
626: m2 0 gt
627: {
628: << esize 1 sub >> -1 1
629: {
630: /k set
631: m k evec_neg
632: } for
633: }
634: { } ifelse
635:
636: ] /arg1 set
637: ] pop
638: popVariables
639: arg1
640: } def
641:
642: /elimination_order {
643: %% [x-list d-list params] (x,y,z) elimination_order
644: %% vars evars
645: %% [x-list d-list params order]
646: /arg2 set /arg1 set
647: [/vars /evars /univ /order /perm /univ0 /compl] pushVariables
648: /vars arg1 def /evars [arg2 to_records pop] def
649: [
650: /univ vars 0 get reverse
651: vars 1 get reverse join
652: def
653:
654: << univ length 2 sub >>
655: << evars length >>
656: eliminationOrderTemplate /order set
657:
658: [[1]] order oplus [[1]] oplus /order set
659:
660: /univ0 [univ reverse aload pop pop] reverse def %% [e,x,y,h] --> [x,y,h]
661:
662: /compl
663: [univ 0 get] evars join evars univ0 complement join
664: def
665: compl univ
666: getPerm /perm set
667: %%perm :: univ :: compl ::
668:
669: order perm permuteOrderMatrix /order set
670:
671:
672: vars [order] join /arg1 set
673: ] pop
674: popVariables
675: arg1
676: } def
677:
678: /elimination_order2 {
679: %% [x-list d-list params] (x,y,z) elimination_order
680: %% vars evars
681: %% [x-list d-list params order]
682: %% with no graduation and homogenization variables.
683: /arg2 set /arg1 set
684: [/vars /evars /univ /order /perm /compl] pushVariables
685: /vars arg1 def /evars [arg2 to_records pop] def
686: [
687: /univ vars 0 get reverse
688: vars 1 get reverse join
689: def
690:
691: << univ length >>
692: << evars length >>
693: eliminationOrderTemplate /order set
694: /compl
695: evars << evars univ complement >> join
696: def
697: compl univ
698: getPerm /perm set
699: %%perm :: univ :: compl ::
700:
701: order perm permuteOrderMatrix /order set
702:
703: vars [order] join /arg1 set
704: ] pop
705: popVariables
706: arg1
707: } def
708:
709:
710: /elimination_order3 {
711: %% [x-list d-list params] (x,y,z) elimination_order
712: %% vars evars
713: %% [x-list d-list params order]
714: /arg2 set /arg1 set
715: [/vars /evars /univ /order /perm /univ0 /compl] pushVariables
716: /vars arg1 def /evars [arg2 to_records pop] def
717: [
718: /univ vars 0 get reverse
719: vars 1 get reverse join
720: def
721:
722: << univ length 1 sub >>
723: << evars length >>
724: eliminationOrderTemplate /order set
725:
726: [[1]] order oplus /order set
727:
728: /univ0 [univ reverse aload pop pop] reverse def %% [e,x,y] --> [x,y]
729:
730: /compl
731: [univ 0 get] evars join evars univ0 complement join
732: def
733: compl univ
734: getPerm /perm set
735: %%perm :: univ :: compl ::
736:
737: order perm permuteOrderMatrix /order set
738:
739: vars [order] join /arg1 set
740: ] pop
741: popVariables
742: arg1
743: } def
744:
745:
746: /define_ring {
747: %[ (x,y,z) ring_of_polynominals
748: % (x,y) elimination_order
749: % 17
750: %] define_ring
751: % or
752: %[ (x,y,z) ring_of_polynominals
753: % (x,y) elimination_order
754: % 17
755: % [(keyword) value (keyword) value ...]
756: %] define_ring
757: /arg1 set
758: [/rp /param /foo] pushVariables
759: [/rp arg1 def
760:
761: rp 0 get length 3 eq {
762: rp 0 [rp 0 get 0 get rp 0 get 1 get rp 0 get 2 get ]
763: ( ) elimination_order put
764: } { } ifelse
765:
766: [
767: rp 0 get 0 get %% x-list
768: rp 0 get 1 get %% d-list
769: rp 0 get 2 get /param set
770: param 0 << rp 1 get >> put %% << rp 1 get >> is 17 in the example.
771: param %% parameters.
772: rp 0 get 3 get %% order matrix.
773: rp length 2 eq
774: { [ ] } %% null optional argument.
775: { rp 2 get }
776: ifelse
777: ] /foo set
778: foo aload pop set_up_ring@
779: ] pop
780: popVariables
781: [(CurrentRingp)] system_variable
782: } def
783:
784:
785: [(define_qring)
786: [( [varlist ring_of_q_difference_operators order characteristic] define_qring)
787: ( Pointer to the ring. )
788: (Example: [$x,y$ ring_of_q_difference_operators $Qx,Qy$ elimination_order)
789: ( 0] define_qring )
790: (cf. define_ring, set_up_ring@ <coefficient ring>, ring_def, << ,, >>)
791: ]
792: ] putUsages
793: /define_qring {
794: %[ (x,y,z) ring_of_q_difference_operators
795: % (Qx,Qy) elimination_order
796: % 17
797: %] define_qring
798: /arg1 set
799: [/rp /param /foo /cring /ppp] pushVariables
800: [/rp arg1 def
801: /ppp rp 1 get def
802: %% define coefficient ring.
803: [(q) @@@.esymbol] [(h) @@@.Esymbol]
804: [ppp 2 2 2 2 1 2 2 2]
805: [[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]
806: [(mpMult) (poly)] set_up_ring@
807: /cring [(CurrentRingp)] system_variable def
808:
809: rp 0 get length 3 eq {
810: rp 0 [rp 0 get 0 get rp 0 get 1 get rp 0 get 2 get ]
811: ( ) elimination_order put
812: } { } ifelse
813:
814: [
815: rp 0 get 0 get %% x-list
816: rp 0 get 1 get %% d-list
817: rp 0 get 2 get /param set
818: param 0 << rp 1 get >> put %% << rp 1 get >> is 17 in the example.
819: param %% parameters.
820: rp 0 get 3 get %% order matrix.
821: rp length 2 eq
822: { [(mpMult) (diff) (coefficient ring) cring] } %% optional argument.
823: { [(mpMult) (diff) (coefficient ring) cring] rp 2 get join }
824: ifelse
825: ] /foo set
826: foo aload pop set_up_ring@
827: ] pop
828: popVariables
829: [(CurrentRingp)] system_variable
830: } def
831:
832: [(ring_def)
833: [(ring ring_def)
834: (Set the current ring to the <<ring>>)
835: (Example: [(x,y) ring_of_polynomials [[(x) 1]] weight_vector 0 ] define_ring)
836: ( /R set)
837: ( R ring_def)
838: (In order to get the ring object R to which a given polynomial f belongs,)
839: (one may use the command )
840: ( f (ring) data_conversion /R set)
841: (cf. define_ring, define_qring, system_variable, poly (ring) data_conversion)
842: (cf. << ,, >>)
843: ]
844: ] putUsages
845:
846: /ring_def {
847: /arg1 set
848: [(CurrentRingp) arg1] system_variable
849: } def
850:
851:
852:
853: /lexicographicOrderTemplate {
854: % size lexicographicOrderTemplate matrix
855: /arg1 set
856: [/k /size] pushVariables
857: [
858: /size arg1 def
859: [ 0 1 << size 1 sub >>
860: {
861: /k set
862: size k evec
863: } for
864: ] /arg1 set
865: ] pop
866: popVariables
867: arg1
868: } def
869:
870: /lexicographic_order {
871: %% [x-list d-list params] (x,y,z) lexicograhic_order
872: %% vars evars
873: %% [x-list d-list params order]
874: /arg2 set /arg1 set
875: [/vars /evars /univ /order /perm /univ0 /compl] pushVariables
876: /vars arg1 def /evars [arg2 to_records pop] def
877: [
878: /univ vars 0 get reverse
879: vars 1 get reverse join
880: def
881:
882: << univ length 2 sub >>
883: lexicographicOrderTemplate /order set
884:
885: [[1]] order oplus [[1]] oplus /order set
886:
887: /univ0 [univ reverse aload pop pop] reverse def %% [e,x,y,h] --> [x,y,h]
888:
889: /compl
890: [univ 0 get] evars join evars univ0 complement join
891: def
892: compl univ
893: getPerm /perm set
894: %%perm :: univ :: compl ::
895:
896: order perm permuteOrderMatrix /order set
897:
898: vars [order] join /arg1 set
899: ] pop
900: popVariables
901: arg1
902: } def
903:
904: /lexicographic_order2 {
905: %% [x-list d-list params] (x,y,z) lexicograhic_order
906: %% vars evars
907: %% [x-list d-list params order]
908: %% with no graduation and homogenization variables
909: /arg2 set /arg1 set
910: [/vars /evars /univ /order /perm /compl] pushVariables
911: /vars arg1 def /evars [arg2 to_records pop] def
912: [
913: /univ vars 0 get reverse
914: vars 1 get reverse join
915: def
916:
917: << univ length >>
918: lexicographicOrderTemplate /order set
919:
920: /compl
921: evars << evars univ complement >> join
922: def
923: compl univ
924: getPerm /perm set
925:
926: order perm permuteOrderMatrix /order set
927:
928: vars [order] join /arg1 set
929: ] pop
930: popVariables
931: arg1
932: } def
933:
934: /lexicographic_order3 {
935: %% [x-list d-list params] (x,y,z) lexicograhic_order
936: %% vars evars
937: %% [x-list d-list params order]
938: %% with no homogenization variable.
939: /arg2 set /arg1 set
940: [/vars /evars /univ /order /perm /univ0 /compl] pushVariables
941: /vars arg1 def /evars [arg2 to_records pop] def
942: [
943: /univ vars 0 get reverse
944: vars 1 get reverse join
945: def
946:
947: << univ length 1 sub >>
948: lexicographicOrderTemplate /order set
949:
950: [[1]] order oplus /order set
951:
952: /univ0 [univ reverse aload pop pop] reverse def %% [e,x,y] --> [x,y]
953:
954: /compl
955: [univ 0 get] evars join evars univ0 complement join
956: def
957: compl univ
958: getPerm /perm set
959: %%perm :: univ :: compl ::
960:
961: order perm permuteOrderMatrix /order set
962:
963: vars [order] join /arg1 set
964: ] pop
965: popVariables
966: arg1
967: } def
968:
969: %%%%%% add_rings %%%%%%%%%%%%%% 10/5
970:
971: /graded_reverse_lexicographic_order {
972: ( ) elimination_order
973: } def
974:
975:
976: /getX {
977: %% param [1|2|3|4] getX [var-lists] ; 1->c,2->l,3->m,4->n
978: /arg2 set /arg1 set
979: [/k /param /func /low /top] pushVariables
980: [
981: /param arg1 def /func arg2 def
982: func 1 eq
983: {
984: /low 0 def
985: }
986: {
987: /low << param 2 get >> << func 1 sub >> get def
988: } ifelse
989: /top << param 2 get >> << func 4 add >> get 1 sub def
990: [
991: low 1 top
992: {
993: /k set
994: param 0 get k get
995: } for
996: ] /arg1 set
997: ] pop
998: popVariables
999: arg1
1000: } def
1001:
1002: /getD {
1003: %% param [1|2|3|4] getD [var-lists] ; 1->c,2->l,3->m,4->n
1004: /arg2 set /arg1 set
1005: [/k /param /func /low /top] pushVariables
1006: [
1007: /param arg1 def /func arg2 def
1008: func 1 eq
1009: {
1010: /low 0 def
1011: }
1012: {
1013: /low << param 2 get >> << func 1 sub >> get def
1014: } ifelse
1015: /top << param 2 get >> << func 4 add >> get 1 sub def
1016: [
1017: low 1 top
1018: {
1019: /k set
1020: param 1 get k get
1021: } for
1022: ] /arg1 set
1023: ] pop
1024: popVariables
1025: arg1
1026: } def
1027:
1028: /getXV {
1029: %% param [1|2|3|4] getXV [var-lists] ; 1->c,2->l,3->m,4->n
1030: /arg2 set /arg1 set
1031: [/k /param /func /low /top] pushVariables
1032: [
1033: /param arg1 def /func arg2 def
1034: /low << param 2 get >> << func 4 add >> get def
1035: /top << param 2 get >> func get 1 sub def
1036: [
1037: low 1 top
1038: {
1039: /k set
1040: param 0 get k get
1041: } for
1042: ] /arg1 set
1043: ] pop
1044: popVariables
1045: arg1
1046: } def
1047:
1048: /getDV {
1049: %% param [1|2|3|4] getDV [var-lists] ; 1->c,2->l,3->m,4->n
1050: /arg2 set /arg1 set
1051: [/k /param /func /low /top] pushVariables
1052: [
1053: /param arg1 def /func arg2 def
1054: /low << param 2 get >> << func 4 add >> get def
1055: /top << param 2 get >> func get 1 sub def
1056: [
1057: low 1 top
1058: {
1059: /k set
1060: param 1 get k get
1061: } for
1062: ] /arg1 set
1063: ] pop
1064: popVariables
1065: arg1
1066: } def
1067:
1068: /reNaming {
1069: %% It also changes oldx2 and oldd2, which are globals.
1070: /arg1 set
1071: [/i /j /new /count /ostr /k] pushVariables
1072: [
1073: /new arg1 def
1074: /count 0 def
1075: 0 1 << new length 1 sub >> {
1076: /i set
1077: << i 1 add >> 1 << new length 1 sub >> {
1078: /j set
1079: << new i get >> << new j get >> eq
1080: {
1081: new j get /ostr set
1082: (The two rings have the same name :) messagen
1083: new i get messagen (.) message
1084: (The name ) messagen
1085: new i get messagen ( is changed into ) messagen
1086: new j << new i get << 48 count add $string$ data_conversion >>
1087: 2 cat_n >> put
1088: new j get messagen (.) message
1089: /oldx2 ostr << new j get >> reNaming2
1090: /oldd2 ostr << new j get >> reNaming2
1091: /count count 1 add def
1092: }
1093: { }
1094: ifelse
1095: } for
1096: } for
1097: /arg1 new def
1098: ] pop
1099: popVariables
1100: arg1
1101: } def
1102:
1103: /reNaming2 {
1104: %% array oldString newString reNaming2
1105: %% /aa (x) (y) reNaming2
1106: /arg3 set /arg2 set /arg1 set
1107: [/array /oldString /newString /k] pushVariables
1108: [
1109: /array arg1 def /oldString arg2 def /newString arg3 def
1110: 0 1 << array load length 1 sub >>
1111: {
1112: /k set
1113: << array load k get >> oldString eq
1114: {
1115: array load k newString put
1116: }
1117: { } ifelse
1118: } for
1119: ] pop
1120: popVariables
1121: } def
1122:
1123: /add_rings {
1124: /arg2 set /arg1 set
1125: [/param1 /param2
1126: /newx /newd /newv
1127: /k /const /od1 /od2 /od
1128: /oldx2 /oldd2 % these will be changed in reNaming.
1129: /oldv
1130: ] pushVariables
1131: [
1132: /param1 arg1 def /param2 arg2 def
1133: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1134: /newx
1135: [ ]
1136: param2 1 getX join param1 1 getX join
1137: param2 1 getXV join param1 1 getXV join
1138:
1139: param2 2 getX join param1 2 getX join
1140: param2 2 getXV join param1 2 getXV join
1141:
1142: param2 3 getX join param1 3 getX join
1143: param2 3 getXV join param1 3 getXV join
1144:
1145: param2 4 getX join param1 4 getX join
1146: param2 4 getXV join param1 4 getXV join
1147: def
1148: /newd
1149: [ ]
1150: param2 1 getD join param1 1 getD join
1151: param2 1 getDV join param1 1 getDV join
1152:
1153: param2 2 getD join param1 2 getD join
1154: param2 2 getDV join param1 2 getDV join
1155:
1156: param2 3 getD join param1 3 getD join
1157: param2 3 getDV join param1 3 getDV join
1158:
1159: param2 4 getD join param1 4 getD join
1160: param2 4 getDV join param1 4 getDV join
1161: def
1162:
1163: /newv newx newd join def
1164: /oldx2 param2 0 get def /oldd2 param2 1 get def
1165: /oldx2 oldx2 {1 copy 2 1 roll pop} map def
1166: /oldd2 oldd2 {1 copy 2 1 roll pop} map def
1167: /newv newv reNaming def
1168:
1169: /newx [
1170: 0 1 << newv length 2 idiv 1 sub >>
1171: {
1172: /k set
1173: newv k get
1174: } for
1175: ] def
1176: /newd [
1177: 0 1 << newv length 2 idiv 1 sub >>
1178: {
1179: /k set
1180: newv << newv length 2 idiv k add >> get
1181: } for
1182: ] def
1183: /const [
1184: << param1 2 get 0 get >>
1185: << param1 2 get 1 get param2 2 get 1 get add >>
1186: << param1 2 get 2 get param2 2 get 2 get add >>
1187: << param1 2 get 3 get param2 2 get 3 get add >>
1188: << param1 2 get 4 get param2 2 get 4 get add >>
1189: << param1 2 get 5 get param2 2 get 5 get add >>
1190: << param1 2 get 6 get param2 2 get 6 get add >>
1191: << param1 2 get 7 get param2 2 get 7 get add >>
1192: << param1 2 get 8 get param2 2 get 8 get add >>
1193: ] def
1194:
1195: /od1 param1 3 get def /od2 param2 3 get def
1196: od1 od2 oplus /od set
1197:
1198: %%oldx2 :: oldd2 ::
1199: << param1 0 get reverse >> << param1 1 get reverse >> join
1200: << oldx2 reverse >> << oldd2 reverse >> join
1201: join /oldv set
1202:
1203:
1204: od << oldv << newx reverse newd reverse join >> getPerm >>
1205: permuteOrderMatrix /od set
1206:
1207: /arg1 [newx newd const od] def
1208: ] pop
1209: popVariables
1210: arg1
1211: } def
1212:
1213:
1214: %%%% end of add_rings
1215:
1216:
1217:
1218: [(swap01) [
1219: $[ .... ] swap01 [....]$
1220: $Examples: [(x,y) ring_of_polynomials (x) elmination_order 0] swap01 $
1221: $ define_ring$
1222: ]] putUsages
1223: %
1224: /swap01 {
1225: /arg1 set
1226: [/rg /ch ] pushVariables
1227: [
1228: arg1 0 get /rg set % ring
1229: arg1 1 get /ch set % characteristics
1230: [rg 0 get , rg 1 get , rg 2 get ,
1231: << rg 3 get length >> 0 1 e_ij << rg 3 get >> mul ] /rg set
1232: /arg1 [ rg ch ] def
1233: ] pop
1234: popVariables
1235: arg1
1236: } def
1237:
1238: [(swap0k) [
1239: $[ .... ] k swap0k [....]$
1240: $Examples: [(x,y) ring_of_polynomials (x) elmination_order 0] 1 swap0k $
1241: $ define_ring$
1242: $swap01 == 1 swap0k$
1243: ]] putUsages
1244: %
1245: /swap0k {
1246: /arg2 set
1247: /arg1 set
1248: [/rg /ch /kk] pushVariables
1249: [
1250: arg2 /kk set
1251: arg1 0 get /rg set % ring
1252: arg1 1 get /ch set % characteristics
1253: [rg 0 get , rg 1 get , rg 2 get ,
1254: << rg 3 get length >> 0 kk e_ij << rg 3 get >> mul ] /rg set
1255: /arg1 [ rg ch ] def
1256: ] pop
1257: popVariables
1258: arg1
1259: } def
1260:
1261: %%%%%%%%%%%%% weight vector
1262: [(position)
1263: [(set element position number)
1264: (Example: [(cat) (dog) (hot chocolate)] (cat) position ===> 0.)
1265: ]
1266: ] putUsages
1267: /position {
1268: /arg2 set /arg1 set
1269: [/univ /elem /num /flag] pushVariables
1270: [
1271: /univ arg1 def
1272: /elem arg2 def
1273: /num -1 def /flag -1 def
1274: 0 1 << univ length 1 sub >>
1275: {
1276: /num set
1277: univ num get elem eq
1278: { /flag 0 def exit }
1279: { }
1280: ifelse
1281: } for
1282: flag -1 eq
1283: {/num -1 def}
1284: { }
1285: ifelse
1286: ] pop
1287: /arg1 num def
1288: popVariables
1289: arg1
1290: } def
1291:
1292:
1293: [(evecw)
1294: [(size position weight evecw [0 0 ... 0 weight 0 ... 0] )
1295: (Example: 3 0 113 evecw ===> [113 0 0])
1296: ]
1297: ] putUsages
1298: /evecw {
1299: /arg3 set /arg2 set /arg1 set
1300: [/size /iii /www] pushVariables
1301: /size arg1 def /iii arg2 def /www arg3 def
1302: [
1303: 0 1 << size 1 sub >>
1304: {
1305: iii eq
1306: { www }
1307: { 0 }
1308: ifelse
1309: } for
1310: ] /arg1 set
1311: popVariables
1312: arg1
1313: } def
1314:
1315: [(weight_vector)
1316: [ ([x-list d-list params] [[(name) weight ...] [...] ...] weight_vector)
1317: ([x-list d-list params order])
1318: (Example:)
1319: ( [(x,y,z) ring_of_polynomials [[(x) 100 (y) 10]] weight_vector 0] )
1320: ( define_ring )
1321: ]
1322: ] putUsages
1323: /weight_vector {
1324: /arg2 set /arg1 set
1325: [/vars /univ /w-vectors /www /k /order1 /order2] pushVariables
1326: /vars arg1 def /w-vectors arg2 def
1327: [
1328: /univ vars 0 get reverse
1329: vars 1 get reverse join
1330: def
1331: [
1332: 0 1 << w-vectors length 1 sub >>
1333: {
1334: /k set
1335: univ w-vectors k get w_to_vec
1336: } for
1337: ] /order1 set
1338: %% order1 ::
1339:
1340: vars ( ) elimination_order 3 get /order2 set
1341: vars [ << order1 order2 join >> ] join /arg1 set
1342: ] pop
1343: popVariables
1344: arg1
1345: } def
1346:
1347: %% [@@@.esymbol (x) (y) (h)] [(x) 100 (y) 10] w_to_vec [0 100 10 0]
1348: %% univ www
1349: /w_to_vec {
1350: /arg2 set /arg1 set
1351: [/univ /www /k /vname /vweight /ans] pushVariables
1352: /univ arg1 def /www arg2 def
1353: [
1354: /ans << univ length >> -1 0 evecw def
1355: 0 2 << www length 2 sub >>
1356: {
1357: %% ans ::
1358: /k set
1359: www k get /vname set
1360: www << k 1 add >> get /vweight set
1361: << univ length >>
1362: << univ vname position >>
1363: vweight evecw
1364: ans add /ans set
1365: } for
1366: /arg1 ans def
1367: ] pop
1368: popVariables
1369: arg1
1370: } def
1371:
1372: %%%%%%%%%% end of weight_vector macro
1373:
1374: %%%%%%%% eliminatev macro
1375: [(eliminatev)
1376: [([g1 g2 g3 ...gm] [list of variables] eliminatev [r1 ... rp])
1377: (Example: [(x y z - 1). (z-1). (y-1).] [(x) (y)] eliminatev [ z-1 ])
1378: ]
1379: ] putUsages
1380: /eliminatev {
1381: /arg2 set /arg1 set
1382: [/gb /var /vars /ans /k] pushVariables
1383: [
1384: /gb arg1 def
1385: /vars arg2 def
1386: /ans gb def
1387: 0 1 << vars length 1 sub >> {
1388: /k set
1389: ans << vars k get >> eliminatev.tmp
1390: /ans set
1391: } for
1392: /arg1 ans def
1393: ] pop
1394: popVariables
1395: arg1
1396: } def
1397: /eliminatev.tmp {
1398: /arg2 set /arg1 set
1399: [/gb /degs /ans /n /var /ff /rr /gg] pushVariables
1400: [
1401: /gb arg1 def
1402: /var arg2 def
1403: /degs gb {
1404: /gg set
1405: gg (0). eq
1406: { 0 }
1407: { gg (ring) data_conversion /rr set
1408: gg << var rr ,, >> degree
1409: } ifelse
1410: } map def
1411: %%degs message
1412: /ans [
1413: 0 1 << gb length 1 sub >> {
1414: /n set
1415: << degs n get >> 0 eq
1416: { gb n get /ff set
1417: ff (0). eq
1418: { }
1419: { ff } ifelse
1420: }
1421: { } ifelse
1422: } for
1423: ] def
1424: /arg1 ans def
1425: ] pop
1426: popVariables
1427: arg1
1428: } def
1429:
1430: /eliminatev.tmp.org {
1431: /arg2 set /arg1 set
1432: [/gb /degs /ans /n /var /ff] pushVariables
1433: [
1434: /gb arg1 def
1435: /var arg2 def
1436: /degs gb {var . degree} map def
1437: /ans [
1438: 0 1 << gb length 1 sub >> {
1439: /n set
1440: << degs n get >> 0 eq
1441: { gb n get /ff set
1442: ff (0). eq
1443: { }
1444: { ff } ifelse
1445: }
1446: { } ifelse
1447: } for
1448: ] def
1449: /arg1 ans def
1450: ] pop
1451: popVariables
1452: arg1
1453: } def
1454: %%% end of eliminatev macro
1455:
1456: %%% macro for output
1457:
1458: [(isInteger)
1459: [(obj isInteger bool) ]
1460: ] putUsages
1461: /isInteger {
1462: (type?) data_conversion << 0 (type?) data_conversion >> eq
1463: } def
1464:
1465: [(isArray)
1466: [(obj isArray bool) ]
1467: ] putUsages
1468: /isArray {
1469: (type?) data_conversion << [ ] (type?) data_conversion >> eq
1470: } def
1471:
1472: [(isPolynomial)
1473: [(obj isPolynomial bool) ]
1474: ] putUsages
1475: /isPolynomial {
1476: (type?) data_conversion
1477: << [(x) (var) 0] system_variable . (type?) data_conversion >> eq
1478: } def
1479:
1480: [(isString)
1481: [(obj isString bool) ]
1482: ] putUsages
1483: /isString {
1484: (type?) data_conversion
1485: << (Hi) (type?) data_conversion >> eq
1486: } def
1487:
1488: [(isClass)
1489: [(obj isClass bool) ]
1490: ] putUsages
1491: /isClass {
1492: (type?) data_conversion ClassP eq
1493: } def
1494:
1495: [(isUniversalNumber)
1496: [(obj isUniversalNumber bool) ]
1497: ] putUsages
1498: /isUniversalNumber {
1499: (type?) data_conversion UniversalNumberP eq
1500: } def
1501:
1502: [(isDouble)
1503: [(obj isDouble bool) ]
1504: ] putUsages
1505: /isDouble {
1506: (type?) data_conversion DoubleP eq
1507: } def
1508:
1509: [(isRational)
1510: [(obj isRational bool) ]
1511: ] putUsages
1512: /isRational {
1513: (type?) data_conversion RationalFunctionP eq
1.7 takayama 1514: } def
1515:
1516: [(isRing)
1517: [(obj isRing bool) ]
1518: ] putUsages
1519: /isRing {
1520: (type?) data_conversion RingP eq
1.1 maekawa 1521: } def
1522:
1523: /toString.tmp {
1524: /arg1 set
1525: [/obj /fname] pushVariables
1526: /obj arg1 def
1527: [
1528: obj isArray
1529: {
1530: obj {toString.tmp} map
1531: }
1532: { } ifelse
1533: obj isInteger
1534: {
1535: obj (dollar) data_conversion %% not string. It returns the ascii code.
1536: }
1537: { } ifelse
1538: obj isPolynomial
1539: {
1540: obj (string) data_conversion
1541: }
1542: { } ifelse
1543: obj isString
1544: { obj }
1545: { } ifelse
1546: obj isUniversalNumber
1547: { obj (string) data_conversion } { } ifelse
1548: obj isDouble
1549: { obj (string) data_conversion } { } ifelse
1550: obj isRational
1551: { obj (string) data_conversion } { } ifelse
1552: obj tag 0 eq
1553: { (null) } { } ifelse
1554:
1555: %%% New code that uses a file.
1556: obj tag 2 eq obj tag 13 eq or obj tag 14 eq or obj tag 17 eq or
1557: { [(getUniqueFileName) (/tmp/sm1_toString)] extension /fname set
1558: [(outputObjectToFile) fname obj] extension pop
1559: fname pushfile
1560: [(/bin/rm -rf ) fname] cat system
1561: } { } ifelse
1562: ] /arg1 set
1563: popVariables
1564: arg1 aload pop
1565: } def
1566:
1567:
1568:
1569: %% [(xy) [(x+1) (2)]] toString.tmp2 ([ xy , [ x+1 , 2 ] ])
1570: /toString.tmp2 {
1571: /arg1 set
1572: [/obj /i /n /r] pushVariables
1573: [
1574: /obj arg1 def
1575: obj isArray
1576: {
1.2 takayama 1577: [(LeftBracket)] system_variable %%( [ )
1.1 maekawa 1578: obj {toString.tmp2} map /r set
1579: /n r length 1 sub def
1580: [0 1 n {
1581: /i set
1582: i n eq {
1583: r i get
1584: }
1585: { r i get ( , ) 2 cat_n }
1586: ifelse
1587: } for
1588: ] aload length cat_n
1.2 takayama 1589: [(RightBracket)] system_variable %%( ] )
1.1 maekawa 1590: 3 cat_n
1591: }
1592: {
1593: obj
1594: } ifelse
1595: ] /arg1 set
1596: popVariables
1597: arg1 aload pop
1598: } def
1599:
1600:
1601: [(toString)
1602: [(obj toString)
1603: (Convert obj to a string.)
1604: (Example: [ 1 (x+1). [ 2 (Hello)]] toString ==> $[ 1 , x+1 , [ 2 , Hello ] ]$)
1605: ]
1606: ] putUsages
1607: /toString {
1608: /arg1 set
1609: [/obj ] pushVariables
1610: [
1611: /obj arg1 def
1612: obj isString
1613: { obj }
1614: { obj toString.tmp toString.tmp2 }
1615: ifelse /arg1 set
1616: ] pop
1617: popVariables
1618: arg1
1619: } def
1620:
1621: [(output)
1622: [(obj output) (Output the object to the standard file sm1out.txt)]
1623: ] putUsages
1624: /output {
1625: /arg1 set
1626: [/obj /fd ] pushVariables
1627: [
1628: /obj arg1 def
1629: (sm1out.txt) (a) file /fd set
1630: (Writing to sm1out.txt ...) messagen
1631: [ fd << obj toString >> writestring ] pop
1632: [ fd << 10 (string) data_conversion >> writestring ] pop
1633: ( Done.) message
1634: fd closefile
1635: ] pop
1636: popVariables
1637: } def
1638: %%%% end of macro for output.
1639: [(tag)
1640: [(obj tag integer)
1641: (tag returns datatype.)
1642: (cf. data_conversion)
1643: (Example: 2 tag IntegerP eq ---> 1)
1644: ]
1645: ] putUsages
1646: /etag {(type??) data_conversion} def
1647: [(etag)
1648: [(obj etag integer)
1649: (etag returns extended object tag. cf. kclass.c)
1650: ]
1651: ] putUsages
1652: /tag {(type?) data_conversion} def
1653: %% datatype constants
1654: /IntegerP 1 (type?) data_conversion def
1655: /LiteralP /arg1 (type?) data_conversion def %Sstring
1656: /StringP (?) (type?) data_conversion def %Sdollar
1657: /ExecutableArrayP { 1 } (type?) data_conversion def
1658: /ArrayP [ 0 ] (type?) data_conversion def
1659: /PolyP (1). (type?) data_conversion def
1660: /FileP 13 def
1661: /RingP 14 def
1662: /UniversalNumberP 15 def
1663: /RationalFunctionP 16 def
1664: /ClassP 17 def
1665: /DoubleP 18 def
1666: /@.datatypeConstant.usage [
1667: (IntegerP, LiteralP, StringP, ExecutableArrayP, ArrayP, PolyP, FileP, RingP,)
1668: (UniversalNumberP, RationalFunctionP, ClassP, DoubleP)
1669: ( return data type identifiers.)
1670: (Example: 7 tag IntegerP eq ---> 1)
1671: ] def
1672: [(IntegerP) @.datatypeConstant.usage ] putUsages
1673: [(LiteralP) @.datatypeConstant.usage ] putUsages
1674: [(StringP) @.datatypeConstant.usage ] putUsages
1675: [(ExecutableArrayP) @.datatypeConstant.usage ] putUsages
1676: [(ArrayP) @.datatypeConstant.usage ] putUsages
1677: [(PolyP) @.datatypeConstant.usage ] putUsages
1678: [(RingP) @.datatypeConstant.usage ] putUsages
1679: [(UniversalNumberP) @.datatypeConstant.usage ] putUsages
1680: [(RationalFunctionP) @.datatypeConstant.usage ] putUsages
1681: [(ClassP) @.datatypeConstant.usage ] putUsages
1682: [(DoubleP) @.datatypeConstant.usage ] putUsages
1683:
1684: [(,,)
1685: [( string ring ,, polynomial)
1686: (Parse the <<string>> as an element in the <<ring>> and returns)
1687: (the polynomial.)
1688: (cf. define_ring, define_qring, ring_def)
1689: (Example: [(x,y) ring_of_polynomials [[(x) 1]] weight_vector 7]define_ring)
1690: ( /myring set)
1691: ( ((x+y)^4) myring ,, /f set)
1692: ]] putUsages
1693:
1694: /,, {
1695: /arg2 set /arg1 set
1696: [/rrr] pushVariables
1697: [ arg1 tag StringP eq
1698: arg2 tag RingP eq and
1699: { [(CurrentRingp)] system_variable /rrr set
1700: [(CurrentRingp) arg2] system_variable
1701: /arg1 arg1 expand def
1702: [(CurrentRingp) rrr] system_variable
1703: }
1704: {(Argument Error for ,, ) error }
1705: ifelse
1706: ] pop
1707: popVariables
1708: arg1
1709: } def
1710:
1711: [(..)
1712: [( string .. universalNumber)
1713: (Parse the << string >> as a universalNumber.)
1714: (Example: (123431232123123).. /n set)
1715: ]] putUsages
1716: /.. { (universalNumber) data_conversion } def
1717:
1718: [(dc)
1719: [(Abbreviation of data_conversion.)
1720: ]] putUsages
1721: /dc { data_conversion } def
1722:
1723:
1724: %%% start of shell sort macro.
1725: [(and) [(obj1 obj2 and bool)]] putUsages
1726: /and { add 1 copy 2 eq {pop 1} {pop 0} ifelse } def
1727:
1728: [(or) [(obj1 obj2 or bool)]] putUsages
1729: /or { add 1 copy 2 eq {pop 1} { } ifelse} def
1730:
1731: [(ge) [(obj1 obj2 ge bool) (greater than or equal)]] putUsages
1732: %% 2 copy is equivalent to dup 3 -1 roll dup 4 -2 roll 3 -1 roll 2 -1 roll
1733: /ge { dup 3 -1 roll dup 4 -2 roll 3 -1 roll 2 -1 roll
1734: eq {pop pop 1}
1735: { gt {1}
1736: {0}
1737: ifelse}
1738: ifelse} def
1739:
1740: [(le) [(obj1 obj2 le bool) (less than or equal)]] putUsages
1741: /le { dup 3 -1 roll dup 4 -2 roll 3 -1 roll 2 -1 roll
1742: eq {pop pop 1}
1743: { lt {1}
1744: {0}
1745: ifelse}
1746: ifelse} def
1747:
1748: [(break)
1749: [(bool break)]
1750: ] putUsages
1751: /break { {exit} { } ifelse } def
1752:
1753: /not { 0 eq {1} {0} ifelse} def
1754: /append { /arg2 set [arg2] join } def
1755:
1756: [(power)
1757: [(obj1 obj2 power obj3)
1758: $obj3 is (obj1)^(obj2). cf. npower$
1759: $Example: (2). 8 power :: ===> 256 $
1760: ]
1761: ] putUsages
1762: %% From SSWork/yacc/incmac.sm1
1763: %% f k power f^k
1764: /power {
1765: /arg2 set
1766: /arg1 set
1767: [/f /k /i /ans] pushVariables
1768: [
1769: /ans (1).. def
1770: /f arg1 def /k arg2 ..int def
1771: k 0 lt {
1772: 1 1 << 0 k sub >> {
1773: /ans f ans {mul} sendmsg2 def
1774: } for
1775: /ans (1).. ans {div} sendmsg2 def
1776: }
1777: {
1778: 1 1 k {
1779: /ans f ans {mul} sendmsg2 def
1780: } for
1781: } ifelse
1782: /arg1 ans def
1783: ] pop
1784: popVariables
1785: arg1
1786: } def
1787: [(..int)
1788: [ (universalNumber ..int int)]] putUsages
1789: /..int { %% universal number to int
1790: (integer) data_conversion
1791: } def
1792: [(SmallRing) [(SmallRing is the ring of polynomials Q[t,x,T,h].)]] putUsages
1793: /SmallRing [(CurrentRingp)] system_variable def
1794:
1795: %%% From SSWork/yacc/lib/printSVector.modified.sm1
1796: %%% supporting code for printSVector.
1797: /greaterThanOrEqual {
1798: /arg2 set /arg1 set
1799: arg1 arg2 gt { 1 }
1800: { arg1 arg2 eq {1} {0} ifelse} ifelse
1801: } def
1802:
1803: /lengthUniv {
1804: length (universalNumber) dc
1805: } def
1806:
1807: /getUniv {
1808: (integer) dc get
1809: } def %% Do not forget to thow away /.
1810:
1811: %%[(@@@.printSVector)
1812: %% [( vector @@@.printSVector outputs the <<vector>> in a pretty way.)
1813: %% ( The elements of the vector must be strings.)
1814: %% ]
1815: %%] putUsages
1816:
1817: %%% compiled code by d0, 1996, 8/17.
1818: /@@@.printSVector {
1819: /arg1 set
1820: [ %%start of local variables
1821: /keys /i /j /n /max /width /m /k /kk /tmp0 ] pushVariables [ %%local variables
1822: /keys arg1 def
1823: /n
1824: keys lengthUniv
1825: def
1826: /max (0).. def
1827: /i (0).. def
1828: %%for init.
1829: %%for
1830: { i n lt
1831: { } {exit} ifelse
1832: [ {%%increment
1833: /i i (1).. add def
1834: } %%end of increment{A}
1835: {%%start of B part{B}
1836: keys i getUniv lengthUniv
1837: max gt
1838: %% if-condition
1839: { %%ifbody
1840: /max
1841: keys i getUniv lengthUniv
1842: def
1843: }%%end if if body
1844: { %%if- else part
1845: } ifelse
1846: } %% end of B part. {B}
1847: 2 1 roll] {exec} map
1848: } loop %%end of for
1849: /max max (3).. add
1850: def
1851: /width (80).. def
1852: /m (0).. def
1853:
1854: %%while
1855: { m max mul
1856: (80).. lt
1857: { } {exit} ifelse
1858: /m m (1).. add
1859: def
1860: } loop
1861: /k (0).. def
1862: /kk (0).. def
1863: /i (0).. def
1864: %%for init.
1865: %%for
1866: { i n lt
1867: { } {exit} ifelse
1868: [ {%%increment
1869: /i i (1).. add def
1870: } %%end of increment{A}
1871: {%%start of B part{B}
1872: keys i getUniv messagen
1873: /kk kk (1).. add
1874: def
1875: /k k
1876: keys i getUniv lengthUniv
1877: add
1878: def
1879: /tmp0 max
1880: keys i getUniv lengthUniv
1881: sub
1882: def
1883: /j (0).. def
1884: %%for init.
1885: %%for
1886: { j tmp0 lt
1887: { } {exit} ifelse
1888: [ {%%increment
1889: /j j (1).. add def
1890: } %%end of increment{A}
1891: {%%start of B part{B}
1892: /k k (1).. add
1893: def
1894: kk m lt
1895: %% if-condition
1896: { %%ifbody
1897: ( ) messagen
1898: }%%end if if body
1899: { %%if- else part
1900: } ifelse
1901: } %% end of B part. {B}
1902: 2 1 roll] {exec} map
1903: } loop %%end of for
1904: kk m greaterThanOrEqual
1905: %% if-condition
1906: { %%ifbody
1907: /kk (0).. def
1908: /k (0).. def
1909: newline
1910: }%%end if if body
1911: { %%if- else part
1912: } ifelse
1913: } %% end of B part. {B}
1914: 2 1 roll] {exec} map
1915: } loop %%end of for
1916: newline
1917: /ExitPoint ]pop popVariables %%pop the local variables
1918: } def
1919: %%end of function
1920:
1921: /rest { % returns remainder of a given list
1922: [ 2 1 roll aload length -1 roll pop ]
1923: } def
1924: [(rest)
1925: [(array rest the-rest-of-the-array)
1926: (Ex. [1 2 [3 0]] rest ===> [2 [3 0]])
1927: ]
1928: ] putUsages
1929:
1930: %% from SSkan/develop/minbase.sm1
1931: /reducedBase {
1932: /arg1 set
1933: [/base /minbase /n /i /j /myring /zero /f] pushVariables
1934: [
1935: /base arg1 def
1936: base isArray { }
1937: { (The argument of reducedBase must be an array of polynomials)
1938: error
1939: } ifelse
1940: base 0 get isPolynomial { }
1941: { (The element of the argument of reducedBase must be polynomials)
1942: error
1943: } ifelse
1944: /myring base 0 get (ring) dc def
1945: /zero (0) myring ,, def
1946: base length 1 sub /n set
1947: /minbase [ 0 1 n { /i set base i get } for ] def
1948: 0 1 n {
1949: /i set
1950: minbase i get /f set
1951: f zero eq {
1952: }
1953: {
1954: 0 1 n {
1955: /j set
1956: << minbase j get zero eq >> << i j eq >> or {
1957: }
1958: {
1959: [(isReducible) << minbase j get >> f] gbext
1960: {
1961: minbase j zero put
1962: }
1963: { } ifelse
1964: } ifelse
1965: } for
1966: } ifelse
1967: } for
1968: minbase { minbase.iszero } map /arg1 set
1969: ] pop
1970: popVariables
1971: arg1
1972: } def
1973:
1974: [(reducedBase)
1975: [(base reducedBase reducedBase)
1976: (<<reducedBase>> prunes redundant elements in the Grobner basis <<base>> and)
1977: (returns <<reducedBase>>.)
1978: (Ex. [(x^2+1). (x+1). (x^3).] reducedBase ---> [(x+1).])
1979: ]
1980: ] putUsages
1981:
1982: %% package functions
1983: /minbase.iszero {
1984: dup (0). eq {
1985: pop
1986: }
1987: { } ifelse
1988: } def
1989:
1990: /== {
1991: message
1992: } def
1993: [(==)
1994: [(obj ==)
1995: (Print obj)
1996: ]
1997: ] putUsages
1998:
1999: /@@@.all_variables {
2000: [/n /i] pushVariables
2001: [
2002: /n [(N)] system_variable def
2003: [
2004: 0 1 n 1 sub {
2005: /i set
2006: [(x) (var) i] system_variable
2007: } for
2008: 0 1 n 1 sub {
2009: /i set
2010: [(D) (var) i] system_variable
2011: } for
2012: ] /arg1 set
2013: ] pop
2014: popVariables
2015: arg1
2016: } def
2017:
2018: /weightv {
2019: @@@.all_variables
2020: 2 1 roll w_to_vec
2021: } def
2022:
2023: [(weightv)
2024: [(array weightv weight_vector_for_init)
2025: (cf. init)
2026: (Example: /w [(x) 10 (h) 2] weightv def)
2027: ( ((x-h)^10). w init ::)
2028: ]
2029: ] putUsages
2030:
2031: /output_order {
2032: /arg1 set
2033: [/vars /vlist /perm /total /ans] pushVariables
2034: [
2035: /vlist arg1 def
2036: /vars @@@.all_variables def
2037: vlist { vars 2 1 roll position } map /perm set
2038: perm ==
2039: /total [ 0 1 [(N)] system_variable 2 mul 1 sub { } for ] def
2040: perm perm total complement join /ans set
2041: [(outputOrder) ans] system_variable
2042: ] pop
2043: popVariables
2044: } def
2045:
2046: [(output_order)
2047: [$ [(v1) (v2) ...] output_order $
2048: (Set the order of variables to print for the current ring.)
2049: (cf. system_variable)
2050: (Example: [(y) (x)] output_order)
2051: $ (x*y). :: ===> y*x $
2052: ]
2053: ] putUsages
2054:
2055: %% destraction. SSkan/Kan/debug/des.sm1, 1998, 2/27 , 3/1
2056: %% should be included in dr.sm1
2057:
2058: /factorial {
2059: /arg2 set
2060: /arg1 set
2061: [ /f /n ] pushVariables
2062: [
2063: /f arg1 def
2064: /n arg2 def
2065: /ans (1).. def
2066: n 0 lt { (f n factorial : n must be a non-negative integer)
2067: error } { } ifelse
2068: 0 1 n 1 sub {
2069: (universalNumber) dc /i set
2070: ans << f i sub >> mul /ans set
2071: } for
2072: /arg1 ans def
2073: ] pop
2074: popVariables
2075: arg1
2076: } def
2077:
2078: [(factorial)
2079: [(f n factorial g)
2080: $integer n, g is f (f-1) ... (f-n+1)$
2081: ]
2082: ] putUsages
2083:
2084:
2085: /destraction1 {
2086: /arg4 set
2087: /arg3 set
2088: /arg2 set
2089: /arg1 set
2090: [/ww /f /dx /ss /xx /coeff0 /expvec
2091: /coeffvec /expvec2 /ans /one] pushVariables
2092: [
2093: /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
2094: /one (1). def %%
2095: /ww [ xx toString -1 dx toString 1 ] weightv def
2096: f ww init f sub (0). eq { }
2097: { [(destraction1 : inhomogeneous with respect to )
2098: xx ( and ) dx ] cat error } ifelse
2099: f [[xx one]] replace dx coefficients /coeff0 set
2100: /expvec coeff0 0 get { (integer) dc } map def
2101: /coeffvec coeff0 1 get def
2102: expvec { ss 2 -1 roll factorial } map /expvec2 set
2103: expvec2 coeffvec mul /ans set
2104: /arg1 ans def
2105: ] pop
2106: popVariables
2107: arg1
2108: } def
2109:
2110:
2111: /distraction {
2112: /arg4 set
2113: /arg3 set
2114: /arg2 set
2115: /arg1 set
2116: [/f /dx /ss /xx /ans /n /i] pushVariables
2117: [(CurrentRingp)] pushEnv
2118: [
2119: /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
2120: f (0). eq { /dist1.L goto } { f (ring) dc ring_def } ifelse
2121: /n xx length def
2122: 0 1 n 1 sub {
2123: /i set
2124: /f f xx i get dx i get ss i get destraction1 /f set
2125: } for
2126: /dist1.L
2127: /arg1 f def
2128: ]pop
2129: popEnv
2130: popVariables
2131: arg1
2132: } def
2133: [(distraction)
2134: [(f [ list of x-variables ] [ list of D-variables ] [ list of s-variables ])
2135: ( distraction result )
2136: $Example: (x Dx Dy + Dy). [(x). (y).] [(Dx). (Dy).] [(x). (y).] distraction$
2137: ]
2138: ] putUsages
2139: /destraction { distraction } def
2140:
2141:
2142:
2143:
2144: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2145: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2146: %%%%%%%%%%%%%%%% sorting
2147: %/N 1000 def
2148: %/a.shell [N -1 0 { } for ] def
2149: %a.shell 0 -1000 put
2150: %% You need gate keeper.
2151: [(shell)
2152: [([gate-keeper f1 f2 ... fm] shell result)
2153: (Sort the list. Gate-keeper should be the smallest element)]
2154: ] putUsages
2155: /shell {
2156: /arg1 set
2157: [/N /a.shell /h /i /v /j] pushVariables
2158: [
2159: /a.shell arg1 def
2160: /N a.shell length 1 sub def
2161:
2162: /h 1 def
2163: {/h h 3 mul 1 add def
2164: << h N ge >> break
2165: } loop
2166: {
2167: /h << h 3 idiv >> def
2168: << h 1 add >> 1 N {
2169: /i set
2170: /v a.shell i get def
2171: /j i def
2172: {
2173: %% a.shell print newline
2174: << a.shell << j h sub >> get >> v le break
2175: a.shell j << a.shell << j h sub >> get >> put
2176: /j j h sub def
2177: j h le break
2178: } loop
2179: a.shell j v put
2180: } for
2181: h 1 lt break
2182: } loop
2183: /arg1 a.shell def
2184: ] pop
2185: popVariables
2186: arg1
2187: } def
2188: %%%% end of shell sort macro
2189:
2190: /variableNames {
2191: /arg1 set
2192: [/in-variableNames /rrr /nnn /i /cp] pushVariables
2193: [
2194: /rrr arg1 def
2195: [(CurrentRingp)] system_variable /cp set
2196: [(CurrentRingp) rrr] system_variable
2197: [(N)] system_variable /nnn set
2198: [ 0 1 nnn 1 sub {
2199: /i set [(x) (var) i] system_variable } for ]
2200: [ 0 1 nnn 1 sub {
2201: /i set [(D) (var) i] system_variable } for ]
2202: join /arg1 set
2203: [(CurrentRingp) cp] system_variable
2204: ] pop
2205: popVariables
2206: arg1
2207: } def
2208:
2209:
2210: /makeRingMap {
2211: /arg3 set /arg2 set /arg1 set
2212: [/in-makeRingMap /corres /M /N /corresM /corresN
2213: /vars /vars-org /i /p /ans /cp] pushVariables
2214: [
2215: /corres arg1 def /M arg2 def /N arg3 def
2216: /corresM corres 0 get def
2217: /corresN corres 1 get def
2218: [(CurrentRingp)] system_variable /cp set
2219: [(CurrentRingp) M] system_variable
2220: M variableNames /vars set vars 1 copy /vars-org set
2221: 0 1 corresM length 1 sub {
2222: /i set
2223: vars corresM i get position /p set
2224: p -1 gt {
2225: vars p $($ corresN i get $)$ 3 cat_n put
2226: } { } ifelse
2227: } for
2228: /arg1 [vars M N vars-org] def
2229: [(CurrentRingp) cp] system_variable
2230: ] pop
2231: popVariables
2232: arg1
2233: } def
2234:
2235:
2236:
2237: /ringmap {
2238: /arg2 set /arg1 set
2239: [/in-ringmap /f /M2N /cp /f2] pushVariables
2240: [
2241: /f arg1 def /M2N arg2 def
2242: [(CurrentRingp)] system_variable /cp set
2243: f (0). eq { /f2 f def }
2244: {
2245: %f (ring) dc M2N 1 get eq
2246: %{ }
2247: %{ (The argument polynomial does not belong to the domain ring.) message
2248: % error
2249: % } ifelse
2250: [(CurrentRingp) M2N 1 get] system_variable
2251: [(variableNames) M2N 0 get] system_variable
2252: f toString /f2 set
2253: [(variableNames) M2N 3 get] system_variable
2254: f2 M2N 2 get ,, /f2 set
2255: } ifelse
2256: [(CurrentRingp) cp] system_variable
2257: /arg1 f2 def
2258: ] pop
2259: popVariables
2260: arg1
2261: } def
2262:
2263: [(makeRingMap)
2264: [( rule ring1 ring2 makeRingMap maptable )
2265: (makeRingMap is an auxiliary function for the macro ringmap. See ringmap)
2266: ]
2267: ] putUsages
2268: [(ringmap)
2269: [(f mapTable ringmap r)
2270: (f is mapped to r where the map is defined by the mapTable, which is generated)
2271: (by makeRingMap as follows:)
2272: ( rule ring1 ring2 makeRingMap maptable )
2273: $Example:$
2274: $[(x,y) ring_of_differential_operators ( ) elimination_order 0] define_ring$
2275: $/R1 set$
2276: $[(t,y,z) ring_of_differential_operators ( ) elimination_order 0] define_ring$
2277: $/R2 set$
2278: $[[(x) (Dx)] [((t-1) Dt) (z)]] /r0 set$
2279: $r0 R1 R2 makeRingMap /maptable set$
2280: $(Dx-1) R1 ,, /ff set$
2281: $ ff maptable ringmap :: $
2282: ]
2283: ] putUsages
2284:
2285:
2286: /getVariableNames {
2287: [/in-getVariableNames /ans /i /n] pushVariables
2288: [
2289: /n [(N)] system_variable def
2290: [
2291: n 1 sub -1 0 {
2292: /i set
2293: [(x) (var) i] system_variable
2294: } for
2295: n 1 sub -1 0{
2296: /i set
2297: [(D) (var) i] system_variable
2298: } for
2299: ] /arg1 set
2300: ] pop
2301: popVariables
2302: arg1
2303: } def
2304: [(getVariableNames)
2305: [(getVariableNames list-of-variables)
2306: (Example: getVariableNames :: [e,x,y,E,H,Dx,Dy,h])
2307: ]
2308: ] putUsages
2309:
2310: /tolower {
2311: /arg1 set
2312: [/in-tolower /s /sl] pushVariables
2313: [
2314: /s arg1 def
2315: s (array) dc /s set
2316: s { tolower.aux (string) dc } map /sl set
2317: sl aload length cat_n /arg1 set
2318: ] pop
2319: popVariables
2320: arg1
2321: } def
2322:
2323: /tolower.aux {
2324: /arg1 set
1.9 takayama 2325: arg1 64 gt arg1 91 lt and
1.1 maekawa 2326: { arg1 32 add }
2327: { arg1 } ifelse
2328: } def
2329: [(tolower)
2330: [(string tolower string2)
2331: (Capital letters in string are converted to lower case letters.)
2332: $Example: (Hello World) tolower :: (hello world)$
2333: ]
2334: ] putUsages
2335:
2336: /hilbert {
2337: /arg2 set
2338: /arg1 set
2339: [/in-hilb /base /vlist /rrrorg /rrr /ff /strf] pushVariables
2340: [
2341: /base arg1 def
2342: /vlist arg2 def
2343: [(CurrentRingp)] system_variable /rrrorg set
2344: /strf 0 def
2345: vlist isString
2346: { /vlist [ vlist to_records pop ] def }
2347: { } ifelse
2348: base isArray { }
2349: { (hilb : the first argument must be an array of polynomials.)
2350: error
2351: } ifelse
2352: vlist isArray { }
2353: { (hilb : the second argument must be an array of polynomials.)
2354: error
2355: } ifelse
2356:
2357: vlist 0 get isString{ /strf 1 def } { } ifelse
2358: base 0 get isPolynomial {
2359: base 0 get (ring) dc /rrr set
2360: }
2361: {
2362: [ vlist { (,) } map aload length cat_n ring_of_polynomials 0 ] define_ring
2363: /rrr set
2364: base { . } map /base set
2365: } ifelse
2366: vlist { dup isPolynomial { } { rrr ,, } ifelse } map /vlist set
2367:
2368: [(hilbert) base vlist] extension /ff set
2369: [(CurrentRingp) rrrorg] system_variable
2370: /arg1 ff def
2371: ] pop
2372: popVariables
2373: arg1
2374: } def
2375:
2376: /hilbReduce {
2377: /arg2 set
2378: /arg1 set
2379: [/hhh /f /d /vv /ans] pushVariables
2380: [
2381: /hhh arg1 def %% hilbert function
2382: /vv arg2 def
2383: /f hhh 1 get def
2384: f (0). eq { /ans [0] def /hilbReduce.label goto } { } ifelse
2385: f vv << f (ring) dc >> ,, degree /vv set
2386: hhh 0 get /d set
2387: d d (integer) dc factorial /d set
2388: d << vv (universalNumber) dc vv factorial >> idiv /d set
2389: [(divByN) f d] gbext /ans set
2390: ans 1 get (0). eq
2391: { }
2392: { (hilbReduce : Invalid hilbert function ) error } ifelse
2393: /hilbReduce.label
2394: ans 0 get /arg1 set
2395: ] pop
2396: popVariables
2397: arg1
2398: } def
2399:
2400:
2401: [(hilbReduce)
2402: [([f,g] v hilbReduce p)
2403: (output of hilbert [f,g]; string v; poly p)
2404: (p is (g/(f!))*deg(g)!)
2405: $ [(x) (y^3)] (x,y,z) hilbert (h) hilbReduce $
2406: ]
2407: ] putUsages
2408: [(hilbert)
2409: [(base vlist hilbert [m f])
2410: (array of poly base; array of poly vlist; number m; poly f;)
2411: (array of string base; array of string vlist; number m; poly f;)
2412: (array of string base; string vlist; number m; poly f;)
2413: ([m f] represents the hilbert function (a_d x^d + ...)/m! where f=a_d x^d + ...)
2414: (The << base >> should be a reduced Grobner basis.)
2415: (Or, when the << base >> is an array of string,)
2416: (all entries should be monomials.)
2417: (Example: [(x^2) (x y )] (x,y) hilbert :: [2, 2 h + 4] )
2418: (Example: [(x^2) (y^2)] (x,y) hilbert (h) hilbReduce :: 4)
2419: (Example: [(x^2) (y^2) (x y)] [(x) (y)] hilbert (h) hilbReduce :: 3)
2420: (cf. hilb, hilbReduce)
2421: ]
2422: ] putUsages
2423:
2424: /hilb {
2425: hilbert (h) hilbReduce
2426: } def
2427: [(hilb)
2428: [(base vlist hilb f)
2429: (array of poly base; array of poly vlist; poly f;)
2430: (array of string base; array of string vlist; poly f;)
2431: (array of string base; string vlist; number m; poly f;)
2432: (f is the hilbert function (a_d x^d + ...)/m!)
2433: (The << base >> should be a reduced Grobner basis.)
2434: (Or, when the << base >> is an array of string,)
2435: (all entries should be monomials.)
2436: (Example: [(x^2) (x y )] (x,y) hilb :: h + 2 )
2437: (Example: [(x^2) (y^2)] (x,y) hilb 4)
2438: (Example: [(x^2) (y^2) (x y)] [(x) (y)] hilb :: 3)
2439: (cf. hilbert, hilbReduce)
2440: ]
2441: ] putUsages
2442:
2443: [(diff0)
2444: [ (f v n diff0 fn)
2445: (<poly> fn, v ; <integer> n ; <poly> fn)
2446: (fn = v^n f where v^n is the operator to take the n-th differential.)
2447: (We can use diff0 only in the ring of differential operators.)
2448: (Example: [(x) ring_of_differential_operators 0] define_ring )
2449: ( (x^10-x). (Dx). 1 diff0 ::)
2450: ]
2451: ] putUsages
2452: /diff0 {
2453: /arg3 set /arg2 set /arg1 set
2454: [/in-diff /f /v /n /fn /rrr] pushVariables
2455: [
2456: /f arg1 def /v arg2 def /n arg3 def
2457: f (0). eq
2458: { /fn (0). def }
2459: {
2460: f (ring) dc /rrr set
2461: v toString (^) n toString 3 cat_n rrr ,,
2462: f mul
2463: [[v (0).] [(h) rrr ,, (1) rrr ,,]] replace /fn set
2464: } ifelse
2465: fn /arg1 set
2466: ] pop
2467: popVariables
2468: arg1
2469: } def
2470:
2471: [(action)
2472: [( f g action p )
2473: (<poly> f,g,p)
2474: (Act f on g. The result is p. The homogenization variable h is put to 1.)
2475: (We can use diff0 only in the ring of differential operators.)
2476: (Example: [(x) ring_of_differential_operators 0] define_ring )
2477: ( (Dx^2). (x^2). action ::)
2478: ]
2479: ] putUsages
2480: /action {
2481: /arg2 set /arg1 set
2482: [/in-action /f /g /h /rr /rr.org /rule] pushVariables
2483: [
2484: /f arg1 def /g arg2 def
2485: /rr.org [(CurrentRingp)] system_variable def
2486: f (0). eq
2487: { /h (0). def }
2488: {
2489: f (ring) dc /rr set
2490: [(CurrentRingp) rr] system_variable
2491: f g mul /h set
2492: /rule getVariableNames def
2493: 0 1 rule length 2 idiv { rule rest /rule set } for
2494: rule { . [ 2 1 roll (0). ] } map /rule set
2495: rule << rule length 1 sub >> [(h). (1).] put
2496: %%ex. rule = [[(Dx1). (0).] [(Dx2). (0).] [(h). (1).]]
2497: /h h rule replace def
2498: } ifelse
2499: [(CurrentRingp) rr.org ] system_variable
2500: /arg1 h def
2501: ] pop
2502: popVariables
2503: arg1
2504: } def
2505:
2506: [(ord_w)
2507: [(ff [v1 w1 v2 w2 ... vm wm] ord_w d)
2508: (poly ff; string v1; integer w1; ...)
1.11 takayama 2509: (order of the initial of ff by the weight vector [w1 w2 ...])
1.1 maekawa 2510: (Example: [(x,y) ring_of_polynomials 0] define_ring )
2511: ( (x^2 y^3-x). [(x) 2 (y) 1] ord_w ::)
2512: ]
2513: ] putUsages
2514: /ord_w {
2515: /arg2 set /arg1 set
2516: [/ord_w-in /fff /www /rrr /iii /ddd] pushVariables
2517: [
2518: /fff arg1 def
2519: /www arg2 def
2520: fff (0). eq { /ddd -intInfinity def /ord_w.LLL goto} { } ifelse
2521: fff (ring) dc /rrr set
2522: fff init /fff set
2523: /ddd 0 def
2524: 0 2 www length 1 sub {
2525: /iii set
2526: fff << www iii get rrr ,, >> degree
2527: << www iii 1 add get >> mul
2528: ddd add /ddd set
2529: } for
1.12 ! takayama 2530: /ord_w.LLL
! 2531: /arg1 ddd def
! 2532: ] pop
! 2533: popVariables
! 2534: arg1
! 2535: } def
! 2536:
! 2537: [(ord_w_all)
! 2538: [(ff [v1 w1 v2 w2 ... vm wm] ord_w d)
! 2539: (poly ff; string v1; integer w1; ...)
! 2540: (order of ff by the weight vector [w1 w2 ...])
! 2541: (Example: [(x,y,t) ring_of_polynomials 0] define_ring )
! 2542: ( (x^2 y^3-x-t). [(t) 1 ] ord_w_all ::)
! 2543: ]
! 2544: ] putUsages
! 2545: /ord_w_all {
! 2546: /arg2 set /arg1 set
! 2547: [/ord_w-in /fff /fff-in /www /rrr /iii /ddd /zzz] pushVariables
! 2548: [
! 2549: /fff arg1 def
! 2550: /www arg2 def
! 2551: fff (0). eq { /ddd -intInfinity def /ord_w.LLL goto} { } ifelse
! 2552: fff (ring) dc /rrr set
! 2553: /zzz (0) rrr ,, def
! 2554: fff init /fff-in set
! 2555: fff fff-in sub /fff set
! 2556: /ddd 0 def
! 2557: {
! 2558: 0 2 www length 1 sub {
! 2559: /iii set
! 2560: fff-in << www iii get rrr ,, >> degree
! 2561: << www iii 1 add get >> mul
! 2562: ddd add /ddd set
! 2563: } for
! 2564: fff zzz eq { exit } { } ifelse
! 2565: fff init /fff-in set
! 2566: fff fff-in sub /fff set
! 2567: } loop
1.1 maekawa 2568: /ord_w.LLL
2569: /arg1 ddd def
2570: ] pop
2571: popVariables
2572: arg1
2573: } def
2574:
2575: [(laplace0)
2576: [
2577: (f [v1 ... vn] laplace0 g)
2578: (poly f ; string v1 ... vn ; poly g;)
2579: (array of poly f ; string v1 ... vn ; array of poly g;)
2580: ( g is the lapalce transform of f with respect to variables v1, ..., vn.)
2581: $Example: (x Dx + y Dy + z Dz). [(x) (y) (Dx) (Dy)] laplace0$
2582: $ x --> -Dx, Dx --> x, y --> -Dy, Dy --> y. $
2583: ]
2584: ] putUsages
2585: /laplace0 {
2586: /arg2 set /arg1 set
2587: [/in-laplace0 /ff /rule /vv /nn /ii /v0 /v1 /rr /ans1 /Dascii
2588: ] pushVariables
2589: [
2590: /ff arg1 def /vv arg2 def
2591: /Dascii @@@.Dsymbol (array) dc 0 get def %%D-clean
2592: /rule [ ] def
2593: ff isPolynomial {
2594: ff (0). eq { /ans1 (0). def }
2595: {
2596: ff (ring) dc /rr set
2597: /nn vv length def
2598: 0 1 nn 1 sub {
2599: /ii set
2600: vv ii get (type?) dc 1 eq
2601: { } % skip, may be weight [(x) 2 ] is OK.
2602: {
2603: /v0 vv ii get (string) dc def
2604: v0 (array) dc 0 get Dascii eq %% If the first character is D?
2605: { rule %% Dx-->x
2606: [v0 rr ,,
2607: v0 (array) dc rest { (string) dc} map aload length cat_n rr ,,]
2608: append /rule set
2609: }
2610: { rule %% x --> -Dx
2611: [v0 rr ,,
2612: (0).
2613: [Dascii] v0 (array) dc join { (string) dc } map aload length
2614: cat_n rr ,, sub
2615: ]
2616: append /rule set
2617: } ifelse
2618: } ifelse
2619: } for
2620: % rule message
2621: ff rule replace [[(h) rr ,, (1) rr ,,]] replace /ans1 set
2622: } ifelse
2623: }
2624: {
2625: ff isArray { /ans1 ff {vv laplace0 } map def }
2626: {
2627: (laplace0 : the first argument must be a polynomial.) error
2628: }ifelse
2629: } ifelse
2630: /arg1 ans1 def
2631: ] pop
2632: popVariables
2633: arg1
2634: } def
2635:
2636: [(ip1)
2637: [( [v1 ... vn] [w1 ... wn] m ip1 [f1 ... fs])
2638: (<poly> v1 ... vn ; <integer> w1 ... wn m)
2639: (<poly> f1 ... fs )
2640: (Example: [(x,y) ring_of_differential_operators 0] define_ring )
2641: ( [(Dx). (Dy).] [2 1] 3 ip1 :: [(2 Dx Dy). (Dy^3).])
2642: ( Returns Dx^p Dy^q such that 2 p + 1 q = 3.)
2643: ]
2644: ] putUsages
2645: /ip1 {
2646: /arg3 set /arg2 set /arg1 set
2647: [/in-ip1 /vv /ww /m /ans /k /tt /rr /rr.org /ff /tmp1] pushVariables
2648: [
2649: /vv arg1 def /ww arg2 def /m arg3 def
2650: vv 0 get (ring) dc /rr set
2651: /rr.org [(CurrentRingp)] system_variable def
2652: [(CurrentRingp) rr] system_variable
2653: [(x) (var) [(N)] system_variable 1 sub ] system_variable . /tt set
2654: /ans [ ] def
2655: m 0 lt
2656: { }
2657: {
2658: vv
2659: ww { tt 2 1 roll power } map mul /tmp1 set
2660: %% (tmp1 = ) messagen tmp1 message
2661: 0 1 m {
2662: /k set
2663: k 0 eq {
2664: /ff (1). def
2665: }
2666: { tmp1 k power /ff set } ifelse
2667: ff [[(h). (1).]] replace /ff set
2668: %% ff message
2669: {
2670: ff init tt degree m eq {
2671: /ans ans [ ff init [[tt (1).]] replace ] join def
2672: } { } ifelse
2673: ff ff init sub /ff set
2674: ff (0). eq { exit } { } ifelse
2675: } loop
2676: } for
2677: } ifelse
2678: [(CurrentRingp) rr.org] system_variable
2679: /arg1 ans def
2680: ] pop
2681: popVariables
2682: arg1
2683: } def
2684:
2685: [(findIntegralRoots)
2686: [( f findIntegralRoots vlist)
2687: (poly f; list of integers vlist;)
2688: (string f; list of integers vlist;)
2689: (f is a polynomials in one variable s. vlist the list of integral roots sorted.)
2690: (Example: (s^4-1) findIntegralRoots )
2691: ]
2692: ] putUsages
2693:
2694: /findIntegralRoots { findIntegralRoots.slow } def
2695:
2696: /findIntegralRoots.slow { %% by a stupid algorithm
2697: /arg1 set
2698: [/in-findIntegralRoots
2699: /ff /kk /roots /rrr /nn /k0 /d.find
2700: ] pushVariables
2701: [
2702: /ff arg1 def
2703: /roots [ ] def
2704: /rrr [(CurrentRingp)] system_variable def
2705: ff toString /ff set
2706: [(s) ring_of_polynomials ( ) elimination_order 0] define_ring
2707: ff . /ff set
2708:
2709: %%ff message %% Cancel the common numerical factor of the polynomial ff.
2710: ff (s). coeff 1 get { (universalNumber) dc } map ngcd /d.find set
2711: [(divByN) ff d.find] gbext 0 get /ff set
2712: %% d.find message
2713: %% ff message
2714:
2715: ff [[(s). (0).]] replace /k0 set
2716: k0 (universalNumber) dc /k0 set
2717: k0 (0).. eq { roots (0).. append /roots set } { } ifelse
2718:
2719: {
2720: ff [[(s). (0).]] replace /nn set
2721: nn (universalNumber) dc /nn set
2722: nn (0).. eq
2723: { (s^(-1)). ff mul /ff set }
2724: { exit }
2725: ifelse
2726: } loop
2727: ff [[(s). (0).]] replace /k0 set
2728: k0 (universalNumber) dc /k0 set
2729: k0 (-40000).. gt k0 (40000).. lt and not {
2730: [(Roots of b-function cannot be obtained by a stupid method.) nl
2731: (Use ox_asir for efficient factorizations, or restall and bfm manually.)
2732: nl
2733: (ox_asir server will be distributed from the asir ftp cite.) nl
2734: (See lib/ttt.tex for details.) nl
2735: ] cat
2736: error
2737: } { } ifelse
2738: nn (0).. lt { (0).. nn sub /nn set } { } ifelse
2739: /kk (0).. nn sub def
2740: /roots [ kk (1).. sub ] roots join def
2741: {
2742: kk nn gt { exit } { } ifelse
2743: ff [[(s). kk (poly) dc]] replace
2744: (0). eq
2745: { /roots roots kk append def }
2746: { } ifelse
2747: kk (1).. add /kk set
2748: } loop
2749: [(CurrentRingp) rrr] system_variable
2750: roots { (integer) dc } map /roots set %% ?? OK?
2751: roots shell rest /roots set
2752: /arg1 roots def
2753: ] pop
2754: popVariables
2755: arg1
2756: } def
2757:
2758: /ngcd {
2759: /arg1 set
2760: [/in-ngcd /nlist /g.ngcd /ans] pushVariables
2761: [
2762: /nlist arg1 def
2763: nlist length 2 lt
2764: { /ans nlist 0 get def /L.ngcd goto }
2765: {
2766: [(gcd) nlist 0 get nlist 1 get] mpzext /g.ngcd set
2767: g.ngcd (1).. eq { /ans (1).. def /L.ngcd goto } { } ifelse
2768: [g.ngcd] nlist rest rest join ngcd /ans set
2769: } ifelse
2770: /L.ngcd
2771: ans /arg1 set
2772: ] pop
2773: popVariables
2774: arg1
2775: } def
2776:
2777: [(ngcd)
2778: [(nlist ngcd d )
2779: (list of numbers nlist; number d;)
2780: (d is the gcd of the numbers in nlist.)
2781: (Example: [(12345).. (67890).. (98765)..] ngcd )
2782: ]] putUsages
2783:
2784: /dehomogenize {
2785: /arg1 set
2786: [/in-dehomogenize /f /rr /ans /cring] pushVariables
2787: [
2788: /f arg1 def
2789: f isPolynomial {
2790: f (0). eq
2791: { f /ans set }
2792: {
2793: f (ring) dc /rr set
2794: [(CurrentRingp)] system_variable /cring set
2795: [(CurrentRingp) rr] system_variable
2796: f [[[(D) (var) 0] system_variable . (1). ]] replace /ans set
2797: [(CurrentRingp) cring] system_variable
2798: } ifelse
2799: }
2800: {
2801: f isArray {
2802: f { dehomogenize } map /ans set
2803: }
2804: {(dehomogenize: argument should be a polynomial.) error }
2805: ifelse
2806: } ifelse
2807: /arg1 ans def
2808: ] pop
2809: popVariables
2810: arg1
2811: } def
2812:
2813: [(dehomogenize)
2814: [(obj dehomogenize obj2)
2815: (dehomogenize puts the homogenization variable to 1.)
2816: (Example: (x*h+h^2). dehomogenize :: x+1 )
2817: ]
2818: ] putUsages
2819:
2820:
2821: /from_records { { (,) } map aload length cat_n } def
2822: [(from_records)
2823: [ ([s1 s2 s3 ... sn] from_records (s1,s2,...,sn,))
2824: (Example : [(x) (y)] from_records :: (x,y,))
2825: (cf. to_records)
2826: ]
2827: ] putUsages
2828: /popEnv {
2829: { system_variable pop } map pop
2830: } def
2831:
2832: /pushEnv {
2833: %% opt=[(CurrentRingp) (NN)] ==> [[(CurrentRingp) val] [(NN) val]]
2834: { [ 2 1 roll dup [ 2 1 roll ] system_variable ] } map
2835: } def
2836: [(pushEnv)
2837: [(keylist pushEnv envlist)
2838: (array of string keylist, array of [string object] envlist;)
2839: (Values <<envlist>> of the global system variables specified )
2840: (by the <<keylist>> is push on the stack.)
2841: (keylist is an array of keywords for system_variable.)
2842: (cf. system_variable, popEnv)
2843: (Example: [(CurrentRingp) (KanGBmessage)] pushEnv)
2844: ]
2845: ] putUsages
2846: [(popEnv)
2847: [(envlist popEnv)
2848: (cf. pushEnv)
2849: ]
2850: ] putUsages
2851:
2852: /npower {
2853: /arg2 set
2854: /arg1 set
2855: [/f /k /i /ans] pushVariables
2856: [
2857: /f arg1 def /k arg2 ..int def
2858: f tag PolyP eq {
2859: /ans (1). def
2860: } {
2861: /ans (1).. def
2862: } ifelse
2863: k 0 lt {
2864: 1 1 << 0 k sub >> {
2865: /ans f ans {mul} sendmsg2 def
2866: } for
2867: /ans (1).. ans {div} sendmsg2 def
2868: }
2869: {
2870: 1 1 k {
2871: /ans f ans {mul} sendmsg2 def
2872: } for
2873: } ifelse
2874: /arg1 ans def
2875: ] pop
2876: popVariables
2877: arg1
2878: } def
2879: [(npower)
2880: [(obj1 obj2 npower obj3)
2881: (npower returns obj1^obj2 as obj3)
2882: (The difference between power and npower occurs when we compute f^0)
2883: (where f is a polynomial.)
2884: $power returns number(universalNumber) 1, but npower returns 1$
2885: (in the current ring.)
2886: ]
2887: ] putUsages
2888:
2889: /gensym {
2890: (dollar) dc 2 cat_n
2891: } def
2892: [(gensym)
2893: [(x i gensym xi)
2894: (string x; integer i; string xi)
2895: (It generate a string x indexed with the number i.)
2896: $Example: (Dx) 12 gensym (Dx12)$
2897: ]
2898: ] putUsages
2899:
2900: /cat {
2901: { toString } map aload length cat_n
2902: } def
2903: [(cat)
2904: [(a cat s)
2905: (array a ; string s;)
2906: (cat converts each entry of << a >> to a string and concatenates them.)
2907: (Example: [ (x) 1 2] cat ==> (x12))
2908: ]
2909: ] putUsages
2910:
2911:
2912: %%%%%%%%%%%%%%%%%%% pmat-level
2913: /pmat-level {
2914: /arg2 set
2915: /arg1 set
2916: [/n /i /m /lev /flag] pushVariables
2917: [
2918: /m arg1 def
2919: /lev arg2 def
2920: m isArray {
2921: /n m length def
2922: n 0 eq { /flag 0 def }
2923: { m 0 get isArray { /flag 1 def } { /flag 0 def} ifelse } ifelse
2924: } { /flag 0 def } ifelse
2925:
2926: flag {
2927: 0 1 lev {
2928: pop ( ) messagen
2929: } for
2930: ([ ) message
2931: 0 1 n 1 sub {
2932: /i set
2933: m i get lev 1 add pmat-level
2934: } for
2935: 0 1 lev {
2936: pop ( ) messagen
2937: } for
2938: (]) message
2939: }
2940: {
2941: 0 1 lev {
2942: pop ( ) messagen
2943: } for
2944: ( ) messagen
2945: m message
2946: } ifelse
2947: ] pop
2948: popVariables
2949: } def
2950:
2951: /pmat { 0 pmat-level } def
2952:
2953: [(pmat)
2954: [(f pmat)
2955: (array f;)
2956: (f is pretty printed.)
2957: ]
2958: ] putUsages
2959:
2960:
2961: /adjoint1 {
2962: /arg2 set
2963: /arg1 set
2964: [/in-adjoint1 /f /p /q /xx /dxx /ans /g /one] pushVariables
2965: [
2966: /f arg1 def
2967: /xx arg2 def
2968: f isPolynomial { }
2969: { (adjoint1: the first argument must be a polynomial.) message
2970: pop popVariables
2971: (adjoint1: the first argument must be a polynomial.) error
2972: } ifelse
2973: /ans (0). def
2974: f (0). eq { }
2975: {
2976: /xx xx (string) dc def
2977: /dxx [@@@.Dsymbol xx] cat def
2978: /xx xx f (ring) dc ,, def
2979: /dxx dxx f (ring) dc ,, def
2980: /one (1) f (ring) dc ,, def
2981:
2982: {
2983: /g f init def
2984: /f f g sub def
2985: /p g xx degree def
2986: /q g dxx degree def
2987: g [[xx one] [dxx one]] replace /g set
2988: g
2989: << (0). dxx sub q npower xx p npower mul >>
2990: mul
2991: ans add /ans set
2992: f (0). eq { exit } { } ifelse
2993: } loop
2994: ans dehomogenize /ans set
2995: } ifelse
2996: /arg1 ans def
2997: ] pop
2998: popVariables
2999: arg1
3000: } def
3001:
3002: /adjoint {
3003: /arg2 set
3004: /arg1 set
3005: [/in-adjoint /f /xx /xx0] pushVariables
3006: [
3007: /f arg1 def /xx arg2 def
3008: xx toString /xx set
3009: [xx to_records pop] /xx set
3010: xx { /xx0 set f xx0 adjoint1 /f set } map
3011: /arg1 f def
3012: ]pop
3013: popVariables
3014: arg1
3015: } def
3016:
3017: [(adjoint)
3018: [(f xlist adjoint g)
3019: (poly f; string xlist; poly g;)
3020: (g is the adjoint operator of f.)
3021: (The variables to take adjoint are specified by xlist.)
3022: (Example: [(x,y) ring_of_differential_operators 0] define_ring)
3023: ( (x^2 Dx - y x Dx Dy-2). (x,y) adjoint )
3024: $ ((-Dx) x^2 - (-Dx) (-Dy) x y -2). dehomogenize sub :: ==> 0$
3025: ]] putUsages
3026:
3027: %%%%% diagonal for tensor products
3028: %% 1998, 12/4 (Sat)
3029: %% s_i = x_i, t_i = x_i - y_i, Restrict to t_i = 0.
3030: %% x_i = x_i, y_i = s_i - t_i,
3031: %% Dx_i = Dt_i + Ds_i, Dy_i = -Dt_i.
3032: /diagonalx {
3033: /arg2 set
3034: /arg1 set
3035: [/in-diagonalx /f] pushVariables
3036: [
3037: (Not implemented yet.) message
3038: ] pop
3039: popVariables
3040: arg1
3041: } def
3042:
3043:
3044:
3045: %%%%%%%%%%% distraction2 for b-function
3046: /distraction2 {
3047: /arg4 set
3048: /arg3 set
3049: /arg2 set
3050: /arg1 set
3051: [/f /dx /ss /xx /ans /n /i /rr] pushVariables
3052: [
3053: /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
3054: f (0). eq { }
3055: {
3056: /rr f (ring) dc def
3057: xx {toString rr ,, } map /xx set
3058: dx {toString rr ,, } map /dx set
3059: ss {toString rr ,, } map /ss set
3060: /n xx length def
3061: 0 1 n 1 sub {
3062: /i set
3063: /f f xx i get dx i get ss i get destraction2.1 /f set
3064: } for
3065: } ifelse
3066: /arg1 f def
3067: ]pop
3068: popVariables
3069: arg1
3070: } def
3071: [(distraction2)
3072: [(f [ list of x-variables ] [ list of D-variables ] [ list of s-variables ])
3073: ( distraction2 result )
3074: $Example 1: [(x,y) ring_of_differential_operators 0] define_ring $
3075: $ (x^2 Dx Dy + x Dy). [(x). (y).] [(Dx). (Dy).] [(x). (y).] distraction2$
3076: $Example 2: (x^4 Dx^2 + x^2). [(x).] [(Dx). ] [(x).] distraction2$
3077: ]
3078: ] putUsages
3079: /destraction2.1 {
3080: /arg4 set
3081: /arg3 set
3082: /arg2 set
3083: /arg1 set
3084: [/ww /f /dx /ss /xx /coeff0 /expvec
3085: /coeffvec /expvec2 /ans /one /rr /dd] pushVariables
3086: [
3087: /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
3088: f (ring) dc /rr set
3089: /one (1) rr ,, def %%
3090: /ww [ xx toString -1 dx toString 1 ] weightv def
3091: f ww init f sub (0). eq { }
3092: { [(destraction2.1 : inhomogeneous with respect to )
3093: xx ( and ) dx nl
3094: (Your weight vector may not be generic.)
3095: ] cat error } ifelse
3096: /dd << f dx degree >> << f xx degree >> sub def
3097: f [[xx one]] replace dx coefficients /coeff0 set
3098: /expvec coeff0 0 get { (integer) dc } map def
3099: /coeffvec coeff0 1 get def
3100: expvec { ss 2 -1 roll factorial } map /expvec2 set
3101: expvec2 coeffvec mul /ans set
3102: %% x^p d^q, (p > q) case. x^2( x^2 Dx^2 + x Dx + 1)
3103: dd 0 lt {
3104: %% (ss+1) (ss+2) ... (ss+d)
3105: one 1 1 0 dd sub { (universalNumber) dc ss add mul} for
3106: ans mul /ans set
3107: }
3108: { } ifelse
3109: /arg1 ans def
3110: ] pop
3111: popVariables
3112: arg1
1.3 takayama 3113: } def
3114:
3115: /distraction2* {
3116: /arg1 set
3117: [/in-distraction2* /aa /f /vlist /xlist /dlist /slist ] pushVariables
3118: [(CurrentRingp)] pushEnv
3119: [
3120: /aa arg1 def
3121: /f aa 0 get def
3122: /vlist aa 1 get def
3123: /xlist aa 2 get def
3124: /dlist aa 3 get def
3125: /slist aa 4 get def
3126: vlist isArray
3127: {
3128: vlist { toString } map /vlist set
3129: }
3130: {
3131: vlist toString to_records /vlist set
3132: } ifelse
3133: xlist isArray
3134: {
3135: xlist { toString } map /xlist set
3136: }
3137: {
3138: xlist toString to_records /xlist set
3139: } ifelse
3140: slist isArray
3141: {
3142: slist { toString } map /slist set
3143: }
3144: {
3145: slist toString to_records /slist set
3146: } ifelse
3147: [vlist from_records ring_of_differential_operators 0] define_ring pop
3148: f toString .
3149: xlist { . } map
3150: dlist { toString . } map
3151: slist { toString . } map
3152: distraction2 /arg1 set
3153: ] pop
3154: popEnv
3155: popVariables
3156: arg1
1.1 maekawa 3157: } def
3158:
3159: /message-quiet {
3160: @@@.quiet { pop } { message } ifelse
3161: } def
3162: [(message-quiet)
3163: [(s message-quiet )
3164: (string s;)
3165: (It outputs the message s when @@@.quiet is not equal to 1.)
3166: (@@@.quiet is set to 1 when you start sm1 with the option -q.)
3167: ]] putUsages
3168: /messagen-quiet {
3169: @@@.quiet { pop } { messagen } ifelse
3170: } def
3171: [(messagen-quiet)
3172: [(s messagen-quiet )
3173: (string s;)
3174: (It outputs the message s without the newline when @@@.quiet is not equal to 1.)
3175: (@@@.quiet is set to 1 when you start sm1 with the option -q.)
3176: ]] putUsages
3177:
3178: /getvNames0 {
3179: /arg1 set
3180: [/in-getvNames0 /nlist /nn /i] pushVariables
3181: [
3182: /nlist arg1 def
3183: [(N)] system_variable /nn set
3184: nlist { /i set
3185: i nn lt {
3186: [(x) (var) i] system_variable
3187: } {
3188: [(D) (var) i nn sub] system_variable
3189: } ifelse
3190: } map
3191: /arg1 set
3192: ] pop
3193: popVariables
3194: arg1
3195: } def
3196:
3197: /getvNames {
3198: [/in-getvNames /nn] pushVariables
3199: [
3200: [(N)] system_variable /nn set
3201: [0 1 nn 2 mul 1 sub { } for] getvNames0 /arg1 set
3202: ] pop
3203: popVariables
3204: arg1
3205: } def
3206: [(getvNames)
3207: [(getvNames vlist)
3208: (list vlist)
3209: (It returns of the list of the variables in the order x0, x1, ..., D0, ...)
3210: (Use with [(variableNames) vlist] system_variable.)
3211: (cf. nlist getvNames0 vlist is used internally. cf. getvNamesC)
3212: ]] putUsages
3213:
3214: /getvNamesC {
3215: [/in-getvNamesC /nn /i] pushVariables
3216: [
3217: [(N)] system_variable /nn set
3218: [nn 1 sub -1 0 { } for nn 2 mul 1 sub -1 nn { } for ] getvNames0 /arg1 set
3219: ] pop
3220: popVariables
3221: arg1
3222: } def
3223: [(getvNamesC)
3224: [(getvNamesC vlist)
3225: (list vlist)
3226: $It returns of the list of the variables in the order 0, 1, 2, ... $
3227: $(cmo-order and output_order).$
3228: (cf. getvNames)
3229: ]] putUsages
3230:
3231: /getvNamesCR {
3232: /arg1 set
3233: [/in-getvNamesCR /rrr] pushVariables
3234: [(CurrentRingp)] pushEnv
3235: [
3236: /rrr arg1 def
3237: rrr isPolynomial {
3238: rrr (0). eq { (No name field for 0 polynomial.) error }
3239: { rrr (ring) dc /rrr set } ifelse
3240: } { } ifelse
3241: [(CurrentRingp) rrr] system_variable
3242: getvNamesC /arg1 set
3243: ] pop
3244: popEnv
3245: popVariables
3246: arg1
3247: } def
3248: [(getvNamesCR)
3249: [(obj getvNamesCR vlist)
3250: (obj ring | poly ; list vlist)
3251: $It returns of the list of the variables in the order 0, 1, 2, ... (cmo-order)$
3252: (for <<obj>>.)
3253: (Example: ( (x-2)^3 ). /ff set )
3254: ( [(x) ring_of_differential_operators 0] define_ring ff getvNamesCR ::)
3255: ]] putUsages
3256:
3257:
3258: /reduction-noH {
3259: /arg2 set
3260: /arg1 set
3261: [/in-reduction-noH /ff /gg] pushVariables
3262: [(Homogenize)] pushEnv
3263: [
3264: /ff arg1 def
3265: /gg arg2 def
3266: [(Homogenize) 0] system_variable
3267: ff gg reduction /arg1 set
3268: ] pop
3269: popEnv
3270: popVariables
3271: arg1
3272: } def
3273: [(reduction-noH)
3274: [(f g reduction-noH r)
3275: (poly f; array g; array r;)
3276: (Apply the normal form algorithm for f with the set g. All computations are)
3277: (done with the rule Dx x = x Dx +1, i.e., no homogenization, but other)
3278: (specifications are the same with reduction. cf. reduction)
3279: (g should be dehomogenized.)
3280: ]] putUsages
3281:
3282: /-intInfinity -999999999 def
3283: /intInfinity 999999999 def
3284: [(intInfinity)
3285: [(intInfinity = 999999999)]
3286: ] putUsages
3287: [(-intInfinity)
3288: [(-intInfinity = -999999999)]
3289: ] putUsages
3290:
3291:
3292: /maxInArray {
3293: /arg1 set
3294: [/in-maxInArray /v /ans /i /n] pushVariables
3295: [
3296: /v arg1 def
3297: /n v length def
3298: /maxInArray.pos 0 def
3299: n 0 eq {
3300: /ans null def
3301: } {
3302: /ans v 0 get def
3303: 1 1 n 1 sub {
3304: /i set
3305: v i get ans gt {
3306: /ans v i get def
3307: /maxInArray.pos i def
3308: } { } ifelse
3309: } for
3310: } ifelse
3311: /arg1 ans def
3312: ] pop
3313: popVariables
3314: arg1
3315: } def
3316: [(maxInArray)
3317: [( [v1 v2 ....] maxInArray m )
3318: (m is the maximum in [v1 v2 ...].)
3319: (The position of m is stored in the global variable maxInArray.pos.)
3320: ]] putUsages
3321:
3322: /cancelCoeff {
3323: /arg1 set
3324: [/in-cancelCoeff /ff /gg /dd /dd2] pushVariables
3325: [ /ff arg1 def
3326: ff (0). eq {
3327: /label.cancelCoeff2 goto
3328: } { } ifelse
3329: /gg ff def
3330: /dd [(lcoeff) ff init ] gbext (universalNumber) dc def
3331: {
3332: gg (0). eq { exit} { } ifelse
3333: [(lcoeff) gg init] gbext (universalNumber) dc /dd2 set
3334: [(gcd) dd dd2] mpzext /dd set
3335: dd (1).. eq {
3336: /label.cancelCoeff goto
3337: } { } ifelse
3338: /gg gg gg init sub def
3339: } loop
3340: [(divByN) ff dd] gbext 0 get /ff set
3341: /label.cancelCoeff
3342: [(lcoeff) ff init] gbext (universalNumber) dc (0).. lt
3343: { ff (-1).. mul /ff set } { } ifelse
3344: /label.cancelCoeff2
3345: /arg1 ff def
3346: ] pop
3347: popVariables
3348: arg1
3349: } def
3350: [(cancelCoeff)
3351: [(f cancelcoeff g)
3352: (poly f,g;)
3353: (Factor out the gcd of the coefficients.)
3354: (Example: (6 x^2 - 10 x). cancelCoeff)
3355: (See also gbext.)
3356: ]] putUsages
3357:
3358:
3359: /flatten {
3360: /arg1 set
3361: [/in-flatten /mylist] pushVariables
3362: [
3363: /mylist arg1 def
3364: mylist isArray {
3365: mylist { dup isArray { aload pop } { } ifelse } map /mylist set
3366: }{ } ifelse
3367: /arg1 mylist def
3368: ] pop
3369: popVariables
3370: arg1
3371: } def
3372: [(flatten)
3373: [(list flatten list2)
3374: (Flatten the list.)
3375: (Example 1: [ [1 2 3] 4 [2]] flatten ===> [1 2 3 4 2])
3376: ]] putUsages
3377:
3378: %% Take first N elements.
3379: /carN {
3380: /arg2 set
3381: /arg1 set
3382: [/in-res-getN /pp /nn /ans] pushVariables
3383: [
3384: /nn arg2 def
3385: /pp arg1 def
3386: pp isArray {
3387: pp length nn lt {
3388: /ans pp def
3389: } {
3390: [pp aload length nn sub /nn set 1 1 nn { pop pop } for ] /ans set
3391: } ifelse
3392: } {
3393: /ans pp def
3394: } ifelse
3395: /arg1 ans def
3396: ] pop
3397: popVariables
3398: arg1
3399: } def
3400: [(carN)
3401: [([f1 ... fm] n carN [f1 ... fn])
3402: (carN extracts the first n elements from the list.)
3403: ]] putUsages
3404:
3405: /getRing {
3406: /arg1 set
3407: [/in-getRing /aa /n /i /ans] pushVariables
3408: [
3409: /aa arg1 def
3410: /ans null def
3411: aa isPolynomial {
3412: aa (0). eq {
3413: } {
3414: /ans aa (ring) dc def
3415: } ifelse
3416: } {
3417: aa isArray {
3418: /n aa length 1 sub def
3419: 0 1 n { /i set aa i get getRing /ans set
3420: ans tag 0 eq { } { /getRing.LLL goto } ifelse
3421: } for
3422: }{ } ifelse
3423: } ifelse
3424: /getRing.LLL
3425: /arg1 ans def
3426: ] pop
3427: popVariables
3428: arg1
3429: } def
3430: [(getRing)
3431: [(obj getRing rr)
3432: (ring rr;)
3433: (getRing obtains the ring structure from obj.)
3434: (If obj is a polynomial, it returns the ring structure associated to)
3435: (the polynomial.)
3436: (If obj is an array, it recursively looks for the ring structure.)
3437: ]] putUsages
3438: /toVectors {
3439: /arg1 set
3440: [/in-toVectors /gg /n /ans] pushVariables
3441: [
3442: /gg arg1 def
3443: gg isArray {
3444: gg length 0 eq {
3445: /ans [ ] def
3446: /toVectors.LLL goto
3447: } {
3448: gg 0 get isInteger {
3449: gg @@@.toVectors2 /ans set
3450: } {
3451: gg @@@.toVectors /ans set
3452: } ifelse
3453: /toVectors.LLL goto
3454: } ifelse
3455: } {
3456: %% It is not array.
3457: gg (array) dc /ans set
3458: } ifelse
3459: /toVectors.LLL
3460: /arg1 ans def
3461: ] pop
3462: popVariables
3463: arg1
3464: } def
3465: /@@@.toVectors2 {
3466: /arg1 set
3467: [/in-@@@.toVectors2 /gg /ans /n /tmp /notarray] pushVariables
3468: [
3469: /gg arg1 def
3470: /ans gg 1 get @@@.toVectors def
3471: /n gg 0 get def
3472: gg 1 get isArray not {
3473: /ans [ans] def
3474: /notarray 1 def
3475: }{ /notarray 0 def} ifelse
3476: ans {
3477: /tmp set
3478: tmp length n lt {
3479: tmp
3480: [1 1 n tmp length sub { pop (0). } for ]
3481: join /tmp set
3482: } { } ifelse
3483: tmp
3484: } map
3485: /ans set
3486: notarray { ans 0 get /ans set } { } ifelse
3487: /arg1 ans def
3488: ] pop
3489: popVariables
3490: arg1
3491: } def
3492:
3493: /@@@.toVectors {
3494: /arg1 set
3495: [/in-@@@.toVectors /gg ] pushVariables
3496: [
3497: /gg arg1 def
3498: gg isArray {
3499: gg { $array$ data_conversion } map
3500: } {
3501: gg (array) data_conversion
3502: }ifelse
3503: /arg1 set
3504: ] pop
3505: popVariables
3506: arg1
3507: } def
3508:
3509: /toVectors2 { toVectors } def
3510:
3511: /fromVectors { { fromVectors.aux } map } def
3512: /fromVectors.aux {
3513: /arg1 set
3514: [/in-fromVector.aux /vv /mm /ans /i /ee] pushVariables
3515: [(CurrentRingp)] pushEnv
3516: [
3517: /vv arg1 def
3518: /mm vv length def
3519: /ans (0). def
3520: /ee (0). def
3521: 0 1 mm 1 sub {
3522: /i set
3523: vv i get (0). eq {
3524: } {
3525: [(CurrentRingp) vv i get (ring) dc] system_variable
3526: [(x) (var) [(N)] system_variable 1 sub] system_variable . /ee set
3527: /fromVector.LLL goto
3528: } ifelse
3529: } for
3530: /fromVector.LLL
3531: %% vv message
3532: 0 1 mm 1 sub {
3533: /i set
3534: vv i get (0). eq {
3535: } {
3536: /ans ans
3537: << vv i get >> << ee i npower >> mul
3538: add def
3539: } ifelse
3540: %% [i ans] message
3541: } for
3542: /arg1 ans def
3543: ] pop
3544: popEnv
3545: popVariables
3546: arg1
3547: } def
3548: [(fromVectors)
3549: [
3550: ([v1 v2 ...] fromVectors [s1 s2 ...])
3551: (array of poly : v1, v2, ... ; poly : s1, s2 ....)
3552: (cf. toVectors. <<e_>> varaible is assumed to be the last )
3553: ( variable in x. @@@.esymbol)
3554: $Example: [(x,y) ring_of_differential_operators 0] define_ring$
3555: $ [(x). (y).] /ff set $
3556: $ [ff ff] fromVectors :: $
3557: ]] putUsages
3558:
3559: /getOrderMatrix {
3560: /arg1 set
3561: [/in-getOrderMatrix /obj /rr /ans /ans2 /i] pushVariables
3562: [(CurrentRingp)] pushEnv
3563: [
3564: /obj arg1 def
3565: obj isArray {
3566: obj { getOrderMatrix } map /ans set
3567: ans length 0 {
3568: /ans null def
3569: } {
3570: /ans2 null def
3571: 0 1 ans length 1 sub {
3572: /i set
3573: ans i get tag 0 eq
3574: { }
3575: { /ans2 ans i get def } ifelse
3576: } for
3577: /ans ans2 def
3578: } ifelse
3579: /getOrderMatrix.LLL goto
3580: } { } ifelse
3581: obj tag 14 eq {
3582: [(CurrentRingp) obj] system_variable
3583: [(orderMatrix)] system_variable /ans set
3584: /getOrderMatrix.LLL goto
3585: } { } ifelse
3586: obj isPolynomial {
3587: obj (0). eq
3588: { /ans null def
3589: } { obj getRing /rr set
3590: [(CurrentRingp) rr] system_variable
3591: [(orderMatrix)] system_variable /ans set
3592: } ifelse
3593: /getOrderMatrix.LLL goto
3594: } { (getOrderMatrix: wrong argument.) error } ifelse
3595: /getOrderMatrix.LLL
3596: /arg1 ans def
3597: ] pop
3598: popEnv
3599: popVariables
3600: arg1
3601: } def
3602:
3603:
3604: [(getOrderMatrix)
3605: [(obj getOrderMatrix m)
3606: (array m)
3607: (getOrderMatrix obtains the order matrix from obj.)
3608: (If obj is a polynomial, it returns the order matrix associated to)
3609: (the polynomial.)
3610: (If obj is an array, it returns an order matrix of an element.)
3611: ]] putUsages
3612:
3613: /nl {
3614: 10 $string$ data_conversion
3615: } def
3616: [(nl)
3617: [(nl is the newline character.)
3618: $Example: [(You can break line) nl (here.)] cat message$
1.4 takayama 3619: ]] putUsages
3620:
3621: /to_int {
3622: /arg1 set
3623: [/to-int /ob /ans] pushVariables
3624: [
3625: /ob arg1 def
3626: /ans ob def
3627: ob isArray {
3628: ob {to_int} map /ans set
3629: /LLL.to_int goto
3630: } { } ifelse
3631: ob isInteger {
3632: ob (universalNumber) dc /ans set
3633: /LLL.to_int goto
3634: } { } ifelse
3635: /LLL.to_int
3636: /arg1 ans def
3637: ] pop
3638: popVariables
3639: arg1
3640: } def
3641: [(to_int)
3642: [(obj to_int obj2)
3643: (All integers in obj are changed to universalNumber.)
3644: (Example: /ff [1 2 [(hello) (0).]] def ff { tag } map ::)
3645: ( ff to_int { tag } map :: )
1.5 takayama 3646: ]] putUsages
3647:
3648: /define_ring_variables {
1.6 takayama 3649: [/in-define_ring_variables /drv._v /drv._p /drv._v0] pushVariables
3650: %% You cannot use these names for names for polynomials.
1.5 takayama 3651: [
1.6 takayama 3652: /drv._v getVariableNames def
3653: /drv._v0 drv._v def
3654: drv._v { dup /drv._p set (/) 2 1 roll ( $) drv._p ($. def ) } map cat
3655: /drv._v set
3656: % drv._v message
3657: [(parse) drv._v] extension
1.5 takayama 3658: ] pop
3659: popVariables
3660: } def
3661: [(define_ring_variables)
3662: [(It binds a variable <<a>> in the current ring to the sm1 variable <<a>>.)
3663: (For example, if x is a variable in the current ring, it defines the sm1)
3664: (variable x by /x (x) def)
3665: ]] putUsages
3666:
3667: /boundp {
3668: /arg1 set
3669: [/a /ans] pushVariables
3670: [
3671: /a arg1 def
3672: [(parse) [(/) a ( load tag 0 eq { /ans 0 def } )
3673: ( { /ans 1 def } ifelse )] cat ] extension
3674: /arg1 ans def
3675: ] pop
3676: popVariables
3677: arg1
3678: } def
3679: [(boundp)
3680: [( a boundp b)
3681: (string a, b is 0 or 1.)
3682: (If the variable named << a >> is bounded to a value,)
3683: (it returns 1 else it returns 0.)
3684: $Example: (hoge) boundp ::$
1.1 maekawa 3685: ]] putUsages
1.10 takayama 3686: [(isSubstr)
3687: [
3688: (s1 s2 isSubstr pos)
3689: (If s1 is a substring of s2, isSubstr returns the position in s2 from which)
3690: (s1 is contained in s2.)
3691: (If s1 is not a substring of s2, then isSubstr returns -1.)
3692: ]
3693: ] putUsages
3694: /isSubstr {
3695: /arg2 set /arg1 set
3696: [/in-isSubstr /s1 /s2 /i1 /i2 /n1 /n2
3697: /ans /flg
3698: ] pushVariables
3699: [
3700: /s1 arg1 def
3701: /s2 arg2 def
3702: s1 (array) dc /s1 set
3703: s2 (array) dc /s2 set
3704: /n1 s1 length def
3705: /n2 s2 length def
3706: /ans -1 def
3707: 0 1 n2 n1 sub {
3708: /i2 set
3709: /flg 1 def
3710: 0 1 n1 1 sub {
3711: /i1 set
3712: s1 i1 get s2 i2 i1 add get eq {
3713: } {
3714: /flg 0 def exit
3715: } ifelse
3716: } for
3717: flg {
3718: /ans i2 def
3719: /isSubstr.L2 goto
3720: } { /ans -1 def } ifelse
3721: } for
3722: /isSubstr.L2
3723: /arg1 ans def
3724: ] pop
3725: popVariables
3726: arg1
3727: } def
1.1 maekawa 3728:
3729: ;
3730:
3731:
3732:
3733:
3734:
3735:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>