[BACK]Return to dr.sm1 CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Annotation of OpenXM/src/kan96xx/Kan/dr.sm1, Revision 1.30

1.30    ! takayama    1: % $OpenXM: OpenXM/src/kan96xx/Kan/dr.sm1,v 1.29 2004/08/22 12:52:34 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:
1.28      takayama   53:      [@@@.Hsymbol] xList join [@@@.esymbol] join /xList set
1.1       maekawa    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]
1.28      takayama  170:      [@@@.Hsymbol] xList join [@@@.esymbol] join /xList set
1.1       maekawa   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]
1.28      takayama  272:      [@@@.Hsymbol] xList join [@@@.esymbol] join /xList set
1.1       maekawa   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]
1.28      takayama  311:      [@@@.Hsymbol] xList join [@@@.esymbol] join /xList set
1.8       takayama  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:   [
1.26      takayama 1769:    /ans (1).. def
                   1770:    [(QuoteMode)] system_variable {
                   1771:      /f arg1 def   /k arg2 def
                   1772:      [(ooPower) f k] extension /ans set
                   1773:    } {
1.1       maekawa  1774:      /f arg1 def   /k arg2 ..int def
                   1775:      k 0 lt {
                   1776:        1 1 << 0 k sub >> {
                   1777:          /ans f ans {mul} sendmsg2 def
                   1778:        } for
                   1779:        /ans (1).. ans {div} sendmsg2 def
                   1780:      }
                   1781:      {
                   1782:        1 1 k {
                   1783:          /ans f ans {mul} sendmsg2 def
                   1784:        } for
                   1785:      } ifelse
1.26      takayama 1786:    } ifelse
                   1787:    /arg1 ans def
1.1       maekawa  1788:   ] pop
                   1789:   popVariables
                   1790:   arg1
                   1791: } def
                   1792: [(..int)
                   1793:  [ (universalNumber ..int int)]] putUsages
                   1794: /..int { %% universal number to int
                   1795:   (integer) data_conversion
                   1796: } def
                   1797: [(SmallRing) [(SmallRing is the ring of polynomials Q[t,x,T,h].)]] putUsages
                   1798: /SmallRing  [(CurrentRingp)] system_variable  def
                   1799:
                   1800: %%% From SSWork/yacc/lib/printSVector.modified.sm1
                   1801: %%% supporting code for printSVector.
                   1802: /greaterThanOrEqual {
                   1803:   /arg2 set /arg1 set
                   1804:   arg1 arg2 gt { 1 }
                   1805:   { arg1 arg2 eq {1} {0} ifelse} ifelse
                   1806: } def
                   1807:
                   1808: /lengthUniv {
                   1809:  length (universalNumber) dc
                   1810: } def
                   1811:
                   1812: /getUniv {
                   1813:  (integer) dc get
                   1814: } def  %% Do not forget to thow away /.
                   1815:
                   1816: %%[(@@@.printSVector)
                   1817: %% [( vector @@@.printSVector   outputs the <<vector>> in a pretty way.)
                   1818: %%  ( The elements of the vector must be strings.)
                   1819: %% ]
                   1820: %%] putUsages
                   1821:
                   1822: %%% compiled code by d0, 1996, 8/17.
                   1823: /@@@.printSVector {
                   1824:  /arg1 set
                   1825: [ %%start of local variables
                   1826: /keys /i /j /n /max /width /m /k /kk /tmp0 ] pushVariables [ %%local variables
                   1827: /keys arg1 def
                   1828: /n
                   1829: keys lengthUniv
                   1830:  def
                   1831: /max (0)..  def
                   1832: /i (0)..  def
                   1833: %%for init.
                   1834: %%for
                   1835: { i n  lt
                   1836:  {  } {exit} ifelse
                   1837: [ {%%increment
                   1838: /i  i (1).. add def
                   1839: } %%end of increment{A}
                   1840: {%%start of B part{B}
                   1841: keys i  getUniv lengthUniv
                   1842: max  gt
                   1843:  %% if-condition
                   1844:   { %%ifbody
                   1845: /max
                   1846: keys i   getUniv lengthUniv
                   1847:  def
                   1848:   }%%end if if body
                   1849:   { %%if- else part
                   1850:   } ifelse
                   1851: } %% end of B part. {B}
                   1852:  2 1 roll] {exec} map
                   1853: } loop %%end of for
                   1854: /max max (3)..  add
                   1855:  def
                   1856: /width (80)..  def
                   1857: /m (0)..  def
                   1858:
                   1859: %%while
                   1860: { m max  mul
                   1861: (80)..  lt
                   1862:  { } {exit} ifelse
                   1863:  /m m (1)..  add
                   1864:  def
                   1865: } loop
                   1866: /k (0)..  def
                   1867: /kk (0)..  def
                   1868: /i (0)..  def
                   1869: %%for init.
                   1870: %%for
                   1871: { i n  lt
                   1872:  {  } {exit} ifelse
                   1873: [ {%%increment
                   1874: /i  i (1).. add def
                   1875: } %%end of increment{A}
                   1876: {%%start of B part{B}
                   1877: keys i getUniv messagen
                   1878: /kk kk (1)..  add
                   1879:  def
                   1880: /k k
                   1881: keys i getUniv lengthUniv
                   1882:  add
                   1883:  def
                   1884: /tmp0 max
                   1885: keys i  getUniv lengthUniv
                   1886:  sub
                   1887:  def
                   1888: /j (0)..  def
                   1889: %%for init.
                   1890: %%for
                   1891: { j tmp0  lt
                   1892:  {  } {exit} ifelse
                   1893: [ {%%increment
                   1894: /j  j (1).. add def
                   1895: } %%end of increment{A}
                   1896: {%%start of B part{B}
                   1897: /k k (1)..  add
                   1898:  def
                   1899: kk m  lt
                   1900:  %% if-condition
                   1901:   { %%ifbody
                   1902: ( ) messagen
                   1903:   }%%end if if body
                   1904:   { %%if- else part
                   1905:   } ifelse
                   1906: } %% end of B part. {B}
                   1907:  2 1 roll] {exec} map
                   1908: } loop %%end of for
                   1909: kk m  greaterThanOrEqual
                   1910:  %% if-condition
                   1911:   { %%ifbody
                   1912: /kk (0)..  def
                   1913: /k (0)..  def
                   1914: newline
                   1915:   }%%end if if body
                   1916:   { %%if- else part
                   1917:   } ifelse
                   1918: } %% end of B part. {B}
                   1919:  2 1 roll] {exec} map
                   1920: } loop %%end of for
                   1921: newline
                   1922: /ExitPoint ]pop popVariables %%pop the local variables
                   1923: } def
                   1924: %%end of function
                   1925:
                   1926: /rest { % returns remainder of a given list
                   1927:   [ 2 1 roll  aload length -1 roll pop ]
                   1928: } def
                   1929: [(rest)
                   1930:  [(array rest the-rest-of-the-array)
                   1931:   (Ex. [1 2 [3 0]] rest ===> [2 [3 0]])
                   1932:  ]
                   1933: ] putUsages
                   1934:
                   1935: %% from SSkan/develop/minbase.sm1
                   1936: /reducedBase {
                   1937:   /arg1 set
                   1938:   [/base /minbase /n /i /j /myring /zero /f] pushVariables
                   1939:   [
                   1940:      /base arg1 def
                   1941:      base isArray { }
                   1942:      { (The argument of reducedBase must be an array of polynomials)
                   1943:         error
                   1944:      } ifelse
                   1945:      base 0 get isPolynomial { }
                   1946:      { (The element of the argument of reducedBase must be polynomials)
                   1947:         error
                   1948:      } ifelse
                   1949:      /myring  base 0 get (ring) dc def
                   1950:      /zero (0) myring ,, def
                   1951:      base length 1 sub /n set
                   1952:      /minbase [ 0 1 n { /i set base i get } for ] def
                   1953:      0 1 n {
                   1954:        /i set
                   1955:        minbase i get  /f set
                   1956:        f zero eq {
                   1957:        }
                   1958:        {
                   1959:            0 1 n {
                   1960:                /j set
                   1961:               << minbase j get zero eq >> << i j eq >> or {
                   1962:               }
                   1963:               {
                   1964:                  [(isReducible) << minbase j get >> f] gbext
                   1965:                  {
                   1966:                      minbase j zero put
                   1967:                   }
                   1968:                  {  } ifelse
                   1969:               } ifelse
                   1970:            } for
                   1971:        } ifelse
                   1972:      } for
                   1973:      minbase { minbase.iszero } map /arg1 set
                   1974:   ] pop
                   1975:   popVariables
                   1976:   arg1
                   1977: } def
                   1978:
                   1979: [(reducedBase)
                   1980:  [(base reducedBase reducedBase)
                   1981:   (<<reducedBase>> prunes redundant elements in the Grobner basis <<base>> and)
                   1982:   (returns <<reducedBase>>.)
                   1983:   (Ex. [(x^2+1). (x+1). (x^3).] reducedBase ---> [(x+1).])
                   1984:  ]
                   1985: ] putUsages
                   1986:
                   1987: %% package functions
                   1988: /minbase.iszero {
                   1989:   dup (0). eq {
                   1990:     pop
                   1991:   }
                   1992:   { } ifelse
                   1993: } def
                   1994:
                   1995: /== {
                   1996:   message
                   1997: } def
                   1998: [(==)
                   1999:  [(obj ==)
                   2000:   (Print obj)
                   2001:  ]
                   2002: ] putUsages
                   2003:
                   2004: /@@@.all_variables {
                   2005:   [/n /i] pushVariables
                   2006:   [
                   2007:      /n [(N)] system_variable def
                   2008:      [
                   2009:       0 1 n 1 sub {
                   2010:           /i set
                   2011:           [(x) (var) i] system_variable
                   2012:       } for
                   2013:       0 1 n 1 sub {
                   2014:           /i set
                   2015:           [(D) (var) i] system_variable
                   2016:       } for
                   2017:      ] /arg1 set
                   2018:   ] pop
                   2019:   popVariables
                   2020:   arg1
                   2021: } def
                   2022:
                   2023: /weightv {
                   2024:   @@@.all_variables
                   2025:   2 1 roll w_to_vec
                   2026: } def
                   2027:
                   2028: [(weightv)
                   2029:  [(array weightv weight_vector_for_init)
                   2030:   (cf. init)
                   2031:   (Example: /w [(x) 10 (h) 2] weightv def)
                   2032:   (         ((x-h)^10).  w init ::)
                   2033:  ]
                   2034: ] putUsages
                   2035:
                   2036: /output_order {
                   2037:   /arg1 set
                   2038:   [/vars /vlist /perm /total /ans] pushVariables
                   2039:   [
                   2040:     /vlist arg1 def
                   2041:     /vars @@@.all_variables def
                   2042:     vlist { vars 2 1 roll position } map  /perm set
                   2043:     perm ==
                   2044:     /total [ 0 1 [(N)] system_variable 2 mul 1 sub { } for ] def
                   2045:     perm perm total complement join /ans set
                   2046:     [(outputOrder) ans] system_variable
                   2047:   ] pop
                   2048:   popVariables
                   2049: } def
                   2050:
                   2051: [(output_order)
                   2052:  [$ [(v1) (v2) ...] output_order $
                   2053:   (Set the order of variables to print for the current ring.)
                   2054:   (cf. system_variable)
                   2055:   (Example:  [(y) (x)] output_order)
                   2056:   $           (x*y). ::   ===> y*x $
                   2057:  ]
                   2058: ] putUsages
                   2059:
                   2060: %% destraction.   SSkan/Kan/debug/des.sm1, 1998, 2/27 ,  3/1
                   2061: %% should be included in dr.sm1
                   2062:
                   2063: /factorial {
                   2064:   /arg2 set
                   2065:   /arg1 set
                   2066:   [ /f /n ] pushVariables
                   2067:   [
                   2068:     /f arg1 def
                   2069:     /n arg2 def
                   2070:     /ans (1).. def
                   2071:     n 0 lt { (f n factorial : n must be a non-negative integer)
                   2072:               error } { } ifelse
                   2073:     0 1 n 1 sub {
                   2074:        (universalNumber) dc /i set
                   2075:          ans  << f  i sub >> mul /ans set
                   2076:     } for
                   2077:     /arg1 ans def
                   2078:    ] pop
                   2079:    popVariables
                   2080:    arg1
                   2081: } def
                   2082:
                   2083: [(factorial)
                   2084:  [(f n factorial g)
                   2085:   $integer n,  g is f (f-1) ... (f-n+1)$
                   2086:  ]
                   2087: ] putUsages
                   2088:
                   2089:
                   2090: /destraction1 {
                   2091:   /arg4 set
                   2092:   /arg3 set
                   2093:   /arg2 set
                   2094:   /arg1 set
                   2095:   [/ww /f  /dx /ss /xx /coeff0 /expvec
                   2096:    /coeffvec /expvec2 /ans /one] pushVariables
                   2097:   [
                   2098:     /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
                   2099:     /one (1). def %%
                   2100:     /ww [ xx toString -1 dx toString 1 ] weightv  def
                   2101:     f ww init f sub (0). eq {   }
                   2102:     { [(destraction1 : inhomogeneous with respect to )
                   2103:         xx  ( and )  dx ] cat error } ifelse
                   2104:     f [[xx one]] replace dx coefficients  /coeff0 set
                   2105:     /expvec coeff0 0 get { (integer) dc } map def
                   2106:     /coeffvec coeff0 1 get def
                   2107:     expvec { ss 2 -1 roll factorial } map /expvec2 set
                   2108:     expvec2 coeffvec mul  /ans set
                   2109:     /arg1 ans def
                   2110:    ] pop
                   2111:    popVariables
                   2112:    arg1
                   2113: } def
                   2114:
                   2115:
                   2116: /distraction {
                   2117:   /arg4 set
                   2118:   /arg3 set
                   2119:   /arg2 set
                   2120:   /arg1 set
                   2121:   [/f  /dx /ss /xx  /ans /n /i] pushVariables
                   2122:   [(CurrentRingp)] pushEnv
                   2123:   [
                   2124:     /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
                   2125:     f (0). eq { /dist1.L goto } { f (ring) dc ring_def } ifelse
                   2126:     /n xx length  def
                   2127:     0 1 n 1 sub {
                   2128:        /i set
                   2129:        /f  f xx i get dx i get ss i get destraction1 /f set
                   2130:     } for
                   2131:     /dist1.L
                   2132:     /arg1 f def
                   2133:   ]pop
                   2134:   popEnv
                   2135:   popVariables
                   2136:   arg1
                   2137: } def
                   2138: [(distraction)
                   2139:  [(f [ list of x-variables ] [ list of D-variables ] [ list of s-variables ])
                   2140:   (   distraction  result )
                   2141:   $Example: (x Dx Dy + Dy). [(x). (y).] [(Dx). (Dy).] [(x). (y).] distraction$
                   2142:  ]
                   2143: ] putUsages
                   2144: /destraction { distraction } def
                   2145:
                   2146:
                   2147:
                   2148:
                   2149: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   2150: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                   2151: %%%%%%%%%%%%%%%% sorting
                   2152: %/N 1000 def
                   2153: %/a.shell [N -1 0 { } for ]  def
                   2154: %a.shell 0 -1000 put
                   2155: %% You need gate keeper.
                   2156: [(shell)
                   2157:  [([gate-keeper f1 f2 ... fm] shell result)
                   2158:   (Sort the list. Gate-keeper should be the smallest element)]
                   2159: ] putUsages
                   2160: /shell {
                   2161:  /arg1 set
                   2162:  [/N /a.shell /h /i /v /j] pushVariables
                   2163:  [
                   2164:   /a.shell arg1 def
                   2165:   /N a.shell length  1 sub def
                   2166:
                   2167:   /h 1 def
                   2168:   {/h h 3 mul 1 add def
                   2169:    << h N ge >> break
                   2170:   } loop
                   2171:   {
                   2172:      /h << h 3 idiv >> def
                   2173:      << h 1 add >> 1 N {
                   2174:         /i set
                   2175:         /v a.shell i get def
                   2176:         /j i def
                   2177:         {
                   2178:            %% a.shell print newline
                   2179:            << a.shell << j h sub >> get >>  v  le  break
                   2180:            a.shell j << a.shell << j h sub >> get >> put
                   2181:            /j j h sub def
                   2182:            j  h le break
                   2183:          } loop
                   2184:          a.shell j v put
                   2185:      } for
                   2186:      h 1 lt break
                   2187:   } loop
                   2188:   /arg1 a.shell def
                   2189:  ] pop
                   2190:  popVariables
                   2191:  arg1
                   2192: } def
                   2193: %%%% end of shell sort macro
                   2194:
                   2195: /variableNames {
                   2196:   /arg1 set
                   2197:   [/in-variableNames /rrr /nnn /i /cp] pushVariables
                   2198:   [
                   2199:     /rrr arg1 def
                   2200:     [(CurrentRingp)] system_variable /cp set
                   2201:     [(CurrentRingp) rrr] system_variable
                   2202:     [(N)] system_variable /nnn set
                   2203:     [ 0 1 nnn 1 sub {
                   2204:          /i set [(x) (var) i] system_variable } for ]
                   2205:     [ 0 1 nnn 1 sub {
                   2206:          /i set [(D) (var) i] system_variable } for ]
                   2207:     join /arg1 set
                   2208:     [(CurrentRingp) cp] system_variable
                   2209:    ] pop
                   2210:    popVariables
                   2211:    arg1
                   2212: } def
                   2213:
                   2214:
                   2215: /makeRingMap {
                   2216:   /arg3 set /arg2 set /arg1 set
                   2217:   [/in-makeRingMap /corres /M /N /corresM /corresN
                   2218:     /vars /vars-org /i /p /ans /cp] pushVariables
                   2219:   [
                   2220:     /corres arg1 def /M arg2 def /N arg3 def
                   2221:     /corresM corres 0 get def
                   2222:     /corresN corres 1 get def
                   2223:     [(CurrentRingp)] system_variable /cp set
                   2224:     [(CurrentRingp) M] system_variable
                   2225:     M variableNames /vars set  vars 1 copy /vars-org set
                   2226:     0 1 corresM length 1 sub {
                   2227:       /i set
                   2228:       vars corresM i get position /p set
                   2229:       p -1 gt {
                   2230:         vars p  $($ corresN i get $)$ 3 cat_n put
                   2231:       }  {   } ifelse
                   2232:     } for
                   2233:     /arg1 [vars M  N vars-org] def
                   2234:     [(CurrentRingp) cp] system_variable
                   2235:   ] pop
                   2236:   popVariables
                   2237:   arg1
                   2238: } def
                   2239:
                   2240:
                   2241:
                   2242: /ringmap {
                   2243:   /arg2 set /arg1 set
                   2244:   [/in-ringmap /f /M2N /cp /f2] pushVariables
                   2245:   [
                   2246:     /f arg1 def /M2N arg2 def
                   2247:     [(CurrentRingp)] system_variable /cp set
                   2248:     f (0). eq { /f2 f def }
                   2249:     {
                   2250:        %f (ring) dc M2N 1 get eq
                   2251:        %{ }
                   2252:        %{ (The argument polynomial does not belong to the domain ring.) message
                   2253:        %  error
                   2254:        % } ifelse
                   2255:         [(CurrentRingp) M2N 1 get] system_variable
                   2256:         [(variableNames) M2N 0 get] system_variable
                   2257:         f toString /f2 set
                   2258:         [(variableNames) M2N 3 get] system_variable
                   2259:         f2 M2N 2 get ,, /f2 set
                   2260:     } ifelse
                   2261:     [(CurrentRingp) cp] system_variable
                   2262:     /arg1 f2 def
                   2263:   ] pop
                   2264:   popVariables
                   2265:   arg1
                   2266: } def
                   2267:
                   2268: [(makeRingMap)
                   2269:  [( rule  ring1 ring2 makeRingMap maptable   )
                   2270:   (makeRingMap is an auxiliary function for the macro ringmap. See ringmap)
                   2271:  ]
                   2272: ] putUsages
                   2273: [(ringmap)
                   2274:  [(f mapTable ringmap r)
                   2275:   (f is mapped to r where the map is defined by the mapTable, which is generated)
                   2276:   (by makeRingMap as follows:)
                   2277:   ( rule  ring1 ring2 makeRingMap maptable   )
                   2278:   $Example:$
                   2279:   $[(x,y) ring_of_differential_operators ( ) elimination_order 0] define_ring$
                   2280:   $/R1 set$
                   2281:   $[(t,y,z) ring_of_differential_operators ( ) elimination_order 0] define_ring$
                   2282:   $/R2 set$
                   2283:   $[[(x) (Dx)] [((t-1) Dt) (z)]] /r0 set$
                   2284:   $r0 R1 R2 makeRingMap /maptable set$
                   2285:   $(Dx-1) R1 ,, /ff set$
                   2286:   $ ff maptable ringmap :: $
                   2287:  ]
                   2288: ] putUsages
                   2289:
                   2290:
                   2291: /getVariableNames {
                   2292:   [/in-getVariableNames /ans /i /n] pushVariables
                   2293:   [
                   2294:      /n [(N)] system_variable def
                   2295:      [
                   2296:        n 1 sub -1 0 {
                   2297:          /i set
                   2298:          [(x) (var) i] system_variable
                   2299:        } for
                   2300:        n 1 sub -1 0{
                   2301:          /i set
                   2302:          [(D) (var) i] system_variable
                   2303:        } for
                   2304:       ] /arg1 set
                   2305:    ] pop
                   2306:   popVariables
                   2307:   arg1
                   2308: } def
                   2309: [(getVariableNames)
                   2310:  [(getVariableNames list-of-variables)
                   2311:   (Example: getVariableNames :: [e,x,y,E,H,Dx,Dy,h])
                   2312:  ]
                   2313: ] putUsages
                   2314:
                   2315: /tolower {
                   2316:   /arg1 set
                   2317:   [/in-tolower /s /sl] pushVariables
                   2318:   [
                   2319:     /s arg1 def
                   2320:     s (array) dc /s set
                   2321:     s { tolower.aux (string) dc } map /sl set
                   2322:     sl aload length cat_n /arg1 set
                   2323:   ] pop
                   2324:   popVariables
                   2325:   arg1
                   2326: } def
                   2327:
                   2328: /tolower.aux {
                   2329:   /arg1 set
1.9       takayama 2330:   arg1 64 gt  arg1 91 lt and
1.1       maekawa  2331:   { arg1 32 add }
                   2332:   { arg1 } ifelse
                   2333: } def
                   2334: [(tolower)
                   2335:  [(string tolower string2)
                   2336:   (Capital letters in string are converted to lower case letters.)
                   2337:   $Example:  (Hello World) tolower :: (hello world)$
                   2338:  ]
                   2339: ] putUsages
                   2340:
                   2341: /hilbert {
                   2342:   /arg2 set
                   2343:   /arg1 set
                   2344:   [/in-hilb /base /vlist /rrrorg /rrr /ff /strf] pushVariables
                   2345:   [
                   2346:      /base arg1 def
                   2347:      /vlist arg2 def
                   2348:      [(CurrentRingp)] system_variable /rrrorg set
                   2349:      /strf 0 def
                   2350:      vlist isString
                   2351:      {  /vlist [ vlist to_records pop ] def }
                   2352:      {  } ifelse
                   2353:      base isArray {  }
                   2354:      { (hilb : the first argument must be an array of polynomials.)
                   2355:         error
                   2356:      } ifelse
                   2357:      vlist isArray {  }
                   2358:      { (hilb : the second argument must be an array of polynomials.)
                   2359:         error
                   2360:      } ifelse
                   2361:
                   2362:      vlist 0 get isString{ /strf 1 def } { } ifelse
                   2363:      base 0 get isPolynomial {
                   2364:        base 0 get (ring) dc /rrr set
                   2365:      }
                   2366:      {
                   2367:        [  vlist { (,) } map  aload length cat_n ring_of_polynomials 0 ] define_ring
                   2368:        /rrr set
                   2369:        base { . } map /base set
                   2370:      } ifelse
                   2371:      vlist { dup isPolynomial {  } { rrr ,, } ifelse } map /vlist set
                   2372:
                   2373:      [(hilbert) base vlist] extension /ff set
                   2374:      [(CurrentRingp) rrrorg] system_variable
                   2375:      /arg1 ff def
                   2376:   ] pop
                   2377:   popVariables
                   2378:   arg1
                   2379: } def
                   2380:
                   2381: /hilbReduce {
                   2382:   /arg2 set
                   2383:   /arg1 set
                   2384:   [/hhh /f /d /vv /ans] pushVariables
                   2385:   [
                   2386:      /hhh arg1 def %% hilbert function
                   2387:      /vv arg2 def
                   2388:      /f hhh 1 get def
                   2389:      f (0). eq { /ans [0] def /hilbReduce.label goto } { } ifelse
                   2390:      f vv << f (ring) dc >> ,,  degree /vv set
                   2391:      hhh 0 get /d set
                   2392:      d   d  (integer) dc factorial /d set
                   2393:      d << vv (universalNumber) dc vv factorial >> idiv /d set
                   2394:      [(divByN) f d] gbext /ans set
                   2395:      ans 1 get (0). eq
                   2396:      {  }
                   2397:      { (hilbReduce : Invalid hilbert function ) error } ifelse
                   2398:      /hilbReduce.label
                   2399:      ans 0 get /arg1 set
                   2400:   ]  pop
                   2401:   popVariables
                   2402:   arg1
                   2403: } def
                   2404:
                   2405:
                   2406: [(hilbReduce)
                   2407:  [([f,g] v hilbReduce p)
                   2408:   (output of hilbert [f,g];  string v; poly p)
                   2409:   (p is  (g/(f!))*deg(g)!)
                   2410:   $ [(x) (y^3)] (x,y,z) hilbert (h) hilbReduce $
                   2411:  ]
                   2412: ] putUsages
                   2413: [(hilbert)
                   2414:  [(base vlist hilbert [m f])
                   2415:   (array of poly base; array of poly vlist; number m; poly f;)
                   2416:   (array of string base; array of string vlist; number m; poly f;)
                   2417:   (array of string base; string vlist; number m; poly f;)
                   2418:   ([m f] represents the hilbert function (a_d x^d + ...)/m! where f=a_d x^d + ...)
                   2419:   (The << base >> should be a reduced Grobner basis.)
                   2420:   (Or, when the << base >> is an array of string,)
                   2421:   (all entries should be monomials.)
                   2422:   (Example: [(x^2) (x y )] (x,y)  hilbert ::  [2, 2 h + 4] )
                   2423:   (Example: [(x^2) (y^2)] (x,y) hilbert (h) hilbReduce ::  4)
                   2424:   (Example: [(x^2) (y^2) (x y)] [(x) (y)] hilbert (h) hilbReduce ::  3)
                   2425:   (cf. hilb,    hilbReduce)
                   2426:  ]
                   2427: ] putUsages
                   2428:
                   2429: /hilb {
                   2430:   hilbert (h) hilbReduce
                   2431: } def
                   2432: [(hilb)
                   2433:  [(base vlist hilb f)
                   2434:   (array of poly base; array of poly vlist;  poly f;)
                   2435:   (array of string base; array of string vlist; poly f;)
                   2436:   (array of string base; string vlist; number m; poly f;)
                   2437:   (f is the hilbert function (a_d x^d + ...)/m!)
                   2438:   (The << base >> should be a reduced Grobner basis.)
                   2439:   (Or, when the << base >> is an array of string,)
                   2440:   (all entries should be monomials.)
                   2441:   (Example: [(x^2) (x y )] (x,y)  hilb ::   h + 2 )
                   2442:   (Example: [(x^2) (y^2)] (x,y) hilb  4)
                   2443:   (Example: [(x^2) (y^2) (x y)] [(x) (y)] hilb ::  3)
                   2444:   (cf. hilbert,    hilbReduce)
                   2445:  ]
                   2446: ] putUsages
                   2447:
                   2448: [(diff0)
                   2449:  [ (f v n diff0 fn)
                   2450:    (<poly> fn, v ; <integer>  n ; <poly> fn)
                   2451:    (fn = v^n f where v^n is the operator to take the n-th differential.)
                   2452:    (We can use diff0 only in the ring of differential operators.)
                   2453:    (Example: [(x) ring_of_differential_operators 0] define_ring )
                   2454:    (         (x^10-x). (Dx). 1 diff0 ::)
                   2455:  ]
                   2456: ] putUsages
                   2457: /diff0 {
                   2458:   /arg3 set /arg2 set /arg1 set
                   2459:   [/in-diff /f /v /n /fn /rrr] pushVariables
                   2460:   [
                   2461:     /f arg1 def /v arg2 def /n arg3 def
                   2462:     f (0). eq
                   2463:     { /fn (0). def }
                   2464:     {
                   2465:        f (ring) dc /rrr set
                   2466:        v toString (^) n toString 3 cat_n rrr ,,
                   2467:        f mul
                   2468:        [[v (0).] [(h) rrr ,, (1) rrr ,,]] replace /fn set
                   2469:      } ifelse
                   2470:      fn /arg1 set
                   2471:   ] pop
                   2472:   popVariables
                   2473:   arg1
                   2474: } def
                   2475:
                   2476: [(action)
                   2477:  [( f g action p )
                   2478:   (<poly> f,g,p)
                   2479:   (Act f on g. The result is p. The homogenization variable h is put to 1.)
                   2480:   (We can use diff0 only in the ring of differential operators.)
                   2481:   (Example: [(x) ring_of_differential_operators 0] define_ring )
                   2482:   (         (Dx^2). (x^2). action ::)
                   2483:  ]
                   2484: ] putUsages
                   2485: /action {
                   2486:   /arg2 set /arg1 set
                   2487:   [/in-action /f /g /h /rr /rr.org /rule] pushVariables
                   2488:   [
                   2489:     /f arg1 def /g arg2 def
                   2490:     /rr.org [(CurrentRingp)] system_variable def
                   2491:     f (0). eq
                   2492:     { /h (0). def }
                   2493:     {
                   2494:         f (ring) dc /rr set
                   2495:         [(CurrentRingp) rr] system_variable
                   2496:         f g mul /h set
                   2497:         /rule getVariableNames def
                   2498:         0 1 rule length 2 idiv { rule rest /rule set } for
                   2499:         rule { . [ 2 1 roll (0). ] } map /rule set
                   2500:         rule << rule length 1 sub >> [(h). (1).] put
                   2501:         %%ex. rule = [[(Dx1). (0).] [(Dx2). (0).] [(h). (1).]]
                   2502:         /h h rule replace def
                   2503:     } ifelse
                   2504:     [(CurrentRingp) rr.org ] system_variable
                   2505:     /arg1 h def
                   2506:   ] pop
                   2507:   popVariables
                   2508:   arg1
                   2509: } def
                   2510:
                   2511: [(ord_w)
                   2512:  [(ff [v1 w1 v2 w2 ... vm wm] ord_w d)
                   2513:   (poly ff; string v1; integer w1; ...)
1.11      takayama 2514:   (order of the initial of ff by the weight vector [w1 w2 ...])
1.1       maekawa  2515:   (Example: [(x,y) ring_of_polynomials 0] define_ring )
                   2516:   (          (x^2 y^3-x). [(x) 2 (y) 1] ord_w ::)
                   2517:  ]
                   2518: ] putUsages
                   2519: /ord_w {
                   2520:   /arg2 set /arg1 set
                   2521:   [/ord_w-in /fff /www /rrr /iii /ddd] pushVariables
                   2522:   [
                   2523:     /fff arg1 def
                   2524:     /www arg2 def
                   2525:     fff (0). eq { /ddd -intInfinity def /ord_w.LLL goto} { } ifelse
                   2526:     fff (ring) dc /rrr set
                   2527:     fff init /fff set
                   2528:     /ddd 0 def
                   2529:     0 2 www length 1 sub {
                   2530:       /iii set
                   2531:       fff << www iii get rrr ,, >> degree
                   2532:       << www iii 1 add get >> mul
                   2533:       ddd add /ddd set
                   2534:     } for
1.12      takayama 2535:     /ord_w.LLL
                   2536:     /arg1 ddd def
                   2537:   ] pop
                   2538:   popVariables
                   2539:   arg1
                   2540: } def
                   2541:
                   2542: [(ord_w_all)
                   2543:  [(ff [v1 w1 v2 w2 ... vm wm] ord_w d)
                   2544:   (poly ff; string v1; integer w1; ...)
                   2545:   (order of ff by the weight vector [w1 w2 ...])
                   2546:   (Example: [(x,y,t) ring_of_polynomials 0] define_ring )
                   2547:   (          (x^2 y^3-x-t). [(t) 1 ] ord_w_all ::)
                   2548:  ]
                   2549: ] putUsages
                   2550: /ord_w_all {
                   2551:   /arg2 set /arg1 set
1.13      takayama 2552:   [/ord_w_all-in /fff /fff-in /www /rrr /iii /ddd /zzz /ddd-tmp] pushVariables
1.12      takayama 2553:   [
                   2554:     /fff arg1 def
                   2555:     /www arg2 def
1.13      takayama 2556:     fff (0). eq { /ddd -intInfinity def /ord_w_all.LLL goto} { } ifelse
                   2557:     /ddd -intInfinity def
1.12      takayama 2558:     fff (ring) dc /rrr set
                   2559:     /zzz (0) rrr ,, def
                   2560:     fff init /fff-in set
                   2561:     fff fff-in sub /fff set
                   2562:     {
1.13      takayama 2563:      /ddd-tmp 0 def
1.12      takayama 2564:      0 2 www length 1 sub {
                   2565:        /iii set
                   2566:        fff-in << www iii get rrr ,, >> degree
                   2567:        << www iii 1 add get >> mul
1.13      takayama 2568:        ddd-tmp add /ddd-tmp set
1.12      takayama 2569:      } for
1.13      takayama 2570:      ddd-tmp ddd gt { /ddd ddd-tmp def }  {  } ifelse
1.12      takayama 2571:      fff zzz eq { exit } {  } ifelse
                   2572:      fff init /fff-in set
                   2573:      fff fff-in sub /fff set
                   2574:     } loop
1.13      takayama 2575:     /ord_w_all.LLL
1.1       maekawa  2576:     /arg1 ddd def
                   2577:   ] pop
                   2578:   popVariables
                   2579:   arg1
                   2580: } def
                   2581:
                   2582: [(laplace0)
                   2583:  [
                   2584:  (f [v1 ... vn] laplace0 g)
                   2585:  (poly f ; string v1 ... vn ; poly g;)
                   2586:  (array of poly f ; string v1 ... vn ; array of poly g;)
                   2587:  ( g is the lapalce transform of f with respect to variables v1, ..., vn.)
                   2588:  $Example: (x Dx + y Dy + z Dz). [(x) (y) (Dx) (Dy)] laplace0$
                   2589:  $ x --> -Dx, Dx --> x,  y --> -Dy, Dy --> y. $
                   2590:  ]
                   2591: ] putUsages
                   2592: /laplace0 {
                   2593:   /arg2 set /arg1 set
                   2594:   [/in-laplace0 /ff /rule /vv /nn /ii /v0 /v1 /rr /ans1 /Dascii
                   2595:   ] pushVariables
                   2596:   [
                   2597:   /ff arg1 def /vv arg2 def
                   2598:   /Dascii @@@.Dsymbol (array) dc 0 get def %%D-clean
                   2599:   /rule [ ] def
                   2600:   ff isPolynomial {
                   2601:    ff (0). eq { /ans1 (0). def }
                   2602:    {
                   2603:      ff (ring) dc /rr set
                   2604:      /nn vv length def
                   2605:      0 1 nn 1 sub {
                   2606:       /ii set
                   2607:       vv ii get (type?) dc 1 eq
                   2608:       {  }  % skip, may be weight [(x) 2 ] is OK.
                   2609:       {
                   2610:          /v0 vv ii get (string) dc def
                   2611:          v0 (array) dc 0 get Dascii eq  %% If the first character is D?
                   2612:          {  rule  %% Dx-->x
                   2613:             [v0 rr ,,
                   2614:             v0 (array) dc rest { (string) dc} map aload length cat_n rr ,,]
                   2615:             append /rule set
                   2616:          }
                   2617:          { rule   %% x --> -Dx
                   2618:            [v0 rr ,,
                   2619:             (0).
                   2620:             [Dascii] v0 (array) dc join { (string) dc } map aload length
                   2621:             cat_n rr ,,  sub
                   2622:            ]
                   2623:            append /rule set
                   2624:          } ifelse
                   2625:       } ifelse
                   2626:      } for
                   2627:      % rule message
                   2628:      ff rule replace [[(h) rr ,, (1) rr ,,]] replace /ans1 set
                   2629:      } ifelse
                   2630:     }
                   2631:    {
                   2632:        ff isArray { /ans1 ff {vv laplace0 } map def }
                   2633:        {
                   2634:          (laplace0 : the first argument must be a polynomial.) error
                   2635:        }ifelse
                   2636:     } ifelse
                   2637:     /arg1 ans1 def
                   2638:   ] pop
                   2639:   popVariables
                   2640:   arg1
                   2641: } def
                   2642:
                   2643: [(ip1)
                   2644:  [( [v1 ... vn] [w1 ... wn] m ip1 [f1 ... fs])
                   2645:   (<poly> v1 ... vn ; <integer> w1 ... wn m)
                   2646:   (<poly> f1 ... fs )
                   2647:   (Example: [(x,y) ring_of_differential_operators 0] define_ring )
                   2648:   (         [(Dx). (Dy).] [2 1] 3 ip1  ::    [(2 Dx Dy). (Dy^3).])
                   2649:   (         Returns Dx^p Dy^q such that  2 p + 1 q = 3.)
                   2650:  ]
                   2651: ] putUsages
                   2652: /ip1 {
                   2653:   /arg3 set /arg2 set /arg1 set
                   2654:   [/in-ip1 /vv /ww /m /ans /k /tt /rr /rr.org /ff /tmp1] pushVariables
                   2655:   [
                   2656:      /vv arg1 def /ww arg2 def /m arg3 def
                   2657:      vv 0 get (ring) dc /rr set
                   2658:      /rr.org [(CurrentRingp)] system_variable def
                   2659:      [(CurrentRingp) rr] system_variable
                   2660:      [(x) (var) [(N)] system_variable 1 sub ] system_variable . /tt set
                   2661:      /ans [ ] def
                   2662:      m 0 lt
                   2663:      {  }
                   2664:      {
                   2665:        vv
                   2666:        ww { tt 2 1 roll power } map mul /tmp1 set
                   2667:  %%      (tmp1 = ) messagen tmp1 message
                   2668:        0 1 m {
                   2669:          /k set
                   2670:          k 0 eq {
                   2671:            /ff (1). def
                   2672:          }
                   2673:          { tmp1 k power /ff set } ifelse
                   2674:          ff [[(h). (1).]] replace /ff set
                   2675:  %%        ff message
                   2676:          {
                   2677:            ff init tt degree m eq {
                   2678:              /ans ans [ ff init [[tt (1).]] replace ] join def
                   2679:            } { } ifelse
                   2680:            ff ff init sub /ff set
                   2681:            ff (0). eq { exit } {  } ifelse
                   2682:          } loop
                   2683:         } for
                   2684:       } ifelse
                   2685:      [(CurrentRingp) rr.org] system_variable
                   2686:      /arg1 ans def
                   2687:   ] pop
                   2688:   popVariables
                   2689:   arg1
                   2690: } def
                   2691:
                   2692: [(findIntegralRoots)
                   2693:  [( f findIntegralRoots vlist)
                   2694:   (poly f; list of integers vlist;)
                   2695:   (string f; list of integers vlist;)
                   2696:   (f is a polynomials in one variable s. vlist the list of integral roots sorted.)
                   2697:   (Example: (s^4-1) findIntegralRoots )
                   2698:  ]
                   2699: ] putUsages
                   2700:
                   2701: /findIntegralRoots { findIntegralRoots.slow } def
                   2702:
                   2703: /findIntegralRoots.slow {  %% by a stupid algorithm
                   2704:   /arg1 set
                   2705:   [/in-findIntegralRoots
                   2706:    /ff /kk /roots /rrr /nn /k0 /d.find
                   2707:   ] pushVariables
                   2708:   [
                   2709:     /ff arg1 def
                   2710:     /roots [  ] def
                   2711:     /rrr [(CurrentRingp)] system_variable def
                   2712:     ff toString /ff set
                   2713:     [(s) ring_of_polynomials ( ) elimination_order 0] define_ring
                   2714:     ff . /ff set
                   2715:
                   2716:     %%ff message  %% Cancel the common numerical factor of the polynomial ff.
                   2717:     ff (s). coeff 1 get { (universalNumber) dc } map ngcd /d.find set
                   2718:     [(divByN) ff d.find] gbext 0 get /ff set
                   2719:     %% d.find message
                   2720:     %% ff message
                   2721:
                   2722:     ff [[(s). (0).]] replace /k0 set
                   2723:     k0 (universalNumber) dc /k0 set
                   2724:     k0 (0).. eq { roots (0).. append /roots set } { } ifelse
                   2725:
                   2726:     {
                   2727:       ff [[(s). (0).]] replace /nn set
                   2728:       nn (universalNumber) dc /nn set
                   2729:       nn (0).. eq
                   2730:       { (s^(-1)). ff mul /ff set }
                   2731:       { exit }
                   2732:       ifelse
                   2733:     } loop
                   2734:     ff [[(s). (0).]] replace /k0 set
                   2735:     k0 (universalNumber) dc /k0 set
                   2736:     k0 (-40000).. gt k0 (40000).. lt and not {
                   2737:      [(Roots of b-function cannot be obtained by a stupid method.) nl
                   2738:       (Use ox_asir for efficient factorizations, or restall and bfm manually.)
                   2739:        nl
                   2740:       (ox_asir server will be distributed from the asir ftp cite.) nl
                   2741:       (See lib/ttt.tex for details.) nl
                   2742:       ] cat
                   2743:       error
                   2744:     } {  } ifelse
                   2745:     nn (0).. lt { (0).. nn sub /nn set } {  } ifelse
                   2746:     /kk  (0).. nn sub  def
                   2747:     /roots [ kk (1).. sub ] roots join def
                   2748:     {
                   2749:        kk nn gt { exit } {  } ifelse
                   2750:        ff [[(s). kk (poly) dc]] replace
                   2751:        (0). eq
                   2752:        { /roots roots kk append def }
                   2753:        {  } ifelse
                   2754:        kk (1).. add /kk set
                   2755:     }  loop
                   2756:     [(CurrentRingp) rrr] system_variable
                   2757:     roots { (integer) dc } map /roots set %% ??  OK?
                   2758:     roots shell rest /roots set
                   2759:     /arg1 roots def
                   2760:   ] pop
                   2761:   popVariables
                   2762:   arg1
                   2763: } def
                   2764:
                   2765: /ngcd {
                   2766:   /arg1 set
                   2767:   [/in-ngcd /nlist /g.ngcd /ans] pushVariables
                   2768:   [
                   2769:      /nlist arg1 def
1.29      takayama 2770:      nlist to_univNum /nlist set
1.1       maekawa  2771:      nlist length 2 lt
                   2772:      { /ans nlist 0 get def /L.ngcd goto }
                   2773:      {
                   2774:         [(gcd) nlist 0 get nlist 1 get] mpzext /g.ngcd set
                   2775:         g.ngcd (1).. eq { /ans (1).. def /L.ngcd goto } { } ifelse
                   2776:         [g.ngcd] nlist rest rest join ngcd /ans set
                   2777:       } ifelse
                   2778:      /L.ngcd
                   2779:      ans /arg1 set
                   2780:   ] pop
                   2781:   popVariables
                   2782:   arg1
                   2783: } def
                   2784:
                   2785: [(ngcd)
                   2786:  [(nlist ngcd d )
                   2787:   (list of numbers nlist; number d;)
                   2788:   (d is the gcd of the numbers in nlist.)
                   2789:   (Example: [(12345).. (67890).. (98765)..] ngcd )
                   2790: ]] putUsages
                   2791:
                   2792: /dehomogenize {
                   2793:   /arg1 set
                   2794:   [/in-dehomogenize /f /rr /ans /cring] pushVariables
                   2795:   [
                   2796:      /f arg1 def
                   2797:      f isPolynomial {
                   2798:        f (0). eq
                   2799:        { f /ans set }
                   2800:        {
                   2801:           f (ring) dc /rr set
                   2802:           [(CurrentRingp)] system_variable /cring set
                   2803:           [(CurrentRingp) rr] system_variable
                   2804:           f [[[(D) (var) 0] system_variable . (1). ]] replace /ans set
                   2805:           [(CurrentRingp) cring] system_variable
                   2806:        } ifelse
                   2807:      }
                   2808:      {
                   2809:         f isArray {
                   2810:          f { dehomogenize } map /ans set
                   2811:         }
                   2812:         {(dehomogenize: argument should be a polynomial.) error }
                   2813:         ifelse
                   2814:      } ifelse
                   2815:      /arg1 ans def
                   2816:   ] pop
                   2817:   popVariables
                   2818:   arg1
                   2819: } def
                   2820:
                   2821: [(dehomogenize)
                   2822:  [(obj dehomogenize obj2)
                   2823:   (dehomogenize puts the homogenization variable to 1.)
                   2824:   (Example:  (x*h+h^2). dehomogenize ::    x+1 )
                   2825:  ]
                   2826: ] putUsages
                   2827:
                   2828:
                   2829: /from_records { { (,) } map aload length cat_n } def
                   2830: [(from_records)
                   2831:  [ ([s1 s2 s3 ... sn] from_records (s1,s2,...,sn,))
                   2832:    (Example : [(x) (y)] from_records ::    (x,y,))
                   2833:    (cf. to_records)
                   2834:  ]
                   2835: ] putUsages
                   2836: /popEnv {
                   2837:   { system_variable pop } map pop
                   2838: } def
                   2839:
                   2840: /pushEnv {
                   2841:    %% opt=[(CurrentRingp) (NN)] ==> [[(CurrentRingp) val] [(NN) val]]
                   2842:    { [ 2 1 roll dup [ 2 1 roll ] system_variable ] } map
                   2843: } def
                   2844: [(pushEnv)
                   2845:  [(keylist pushEnv envlist)
                   2846:   (array of string keylist, array of [string object] envlist;)
                   2847:   (Values <<envlist>> of the global system variables specified )
                   2848:   (by the <<keylist>> is push on the stack.)
                   2849:   (keylist is an array of keywords for system_variable.)
                   2850:   (cf. system_variable, popEnv)
                   2851:   (Example:  [(CurrentRingp) (KanGBmessage)] pushEnv)
                   2852:  ]
                   2853: ] putUsages
                   2854: [(popEnv)
                   2855:  [(envlist popEnv)
                   2856:   (cf. pushEnv)
                   2857:  ]
                   2858: ] putUsages
                   2859:
                   2860: /npower {
                   2861:   /arg2 set
                   2862:   /arg1 set
                   2863:   [/f /k /i /ans] pushVariables
                   2864:   [
                   2865:      /f arg1 def   /k arg2 ..int def
                   2866:      f tag PolyP eq {
                   2867:        /ans (1). def
                   2868:      } {
                   2869:        /ans (1).. def
                   2870:      } ifelse
                   2871:      k 0 lt {
                   2872:        1 1 << 0 k sub >> {
                   2873:          /ans f ans {mul} sendmsg2 def
                   2874:        } for
                   2875:        /ans (1).. ans {div} sendmsg2 def
                   2876:      }
                   2877:      {
                   2878:        1 1 k {
                   2879:          /ans f ans {mul} sendmsg2 def
                   2880:        } for
                   2881:      } ifelse
                   2882:      /arg1 ans def
                   2883:   ] pop
                   2884:   popVariables
                   2885:   arg1
                   2886: } def
                   2887: [(npower)
                   2888:  [(obj1 obj2 npower obj3)
                   2889:   (npower returns obj1^obj2 as obj3)
                   2890:   (The difference between power and npower occurs when we compute f^0)
                   2891:   (where f is a polynomial.)
                   2892:   $power returns number(universalNumber) 1, but npower returns 1$
                   2893:   (in the current ring.)
                   2894:  ]
                   2895: ] putUsages
                   2896:
                   2897: /gensym {
                   2898:   (dollar) dc 2 cat_n
                   2899: } def
                   2900: [(gensym)
                   2901:  [(x i gensym xi)
                   2902:   (string x; integer i; string xi)
                   2903:   (It generate a string x indexed with the number i.)
                   2904:   $Example:  (Dx) 12 gensym (Dx12)$
                   2905:  ]
                   2906: ] putUsages
                   2907:
                   2908: /cat {
                   2909:   { toString } map aload length cat_n
                   2910: } def
                   2911: [(cat)
                   2912:  [(a cat s)
                   2913:   (array a ; string s;)
                   2914:   (cat converts each entry of << a >> to a string and concatenates them.)
                   2915:   (Example: [ (x) 1 2] cat ==> (x12))
                   2916:  ]
                   2917: ] putUsages
                   2918:
                   2919:
                   2920: %%%%%%%%%%%%%%%%%%% pmat-level
                   2921: /pmat-level {
                   2922:   /arg2 set
                   2923:   /arg1 set
                   2924:   [/n /i /m /lev /flag] pushVariables
                   2925:   [
                   2926:     /m arg1 def
                   2927:     /lev arg2 def
                   2928:     m isArray {
                   2929:        /n m length def
                   2930:        n 0 eq { /flag 0 def }
                   2931:        { m 0 get isArray { /flag 1 def } { /flag 0 def} ifelse } ifelse
                   2932:     } {  /flag 0 def } ifelse
                   2933:
                   2934:     flag {
                   2935:       0 1 lev {
                   2936:         pop ( ) messagen
                   2937:       } for
                   2938:       ([ ) message
                   2939:       0 1 n 1 sub {
                   2940:         /i set
                   2941:         m i get lev 1 add pmat-level
                   2942:       } for
                   2943:       0 1 lev {
                   2944:         pop ( ) messagen
                   2945:       } for
                   2946:       (]) message
                   2947:     }
                   2948:     {
                   2949:        0 1 lev {
                   2950:          pop ( ) messagen
                   2951:        } for
                   2952:        ( ) messagen
                   2953:        m message
                   2954:     } ifelse
                   2955:   ] pop
                   2956:   popVariables
                   2957: } def
                   2958:
                   2959: /pmat {  0 pmat-level } def
                   2960:
                   2961: [(pmat)
                   2962:  [(f pmat)
                   2963:   (array f;)
                   2964:   (f is pretty printed.)
                   2965:  ]
                   2966: ] putUsages
                   2967:
                   2968:
                   2969: /adjoint1 {
                   2970:   /arg2 set
                   2971:   /arg1 set
                   2972:   [/in-adjoint1 /f /p /q /xx /dxx /ans /g /one] pushVariables
                   2973:   [
                   2974:      /f arg1 def
                   2975:      /xx arg2 def
                   2976:      f isPolynomial {  }
                   2977:      { (adjoint1: the first argument must be a polynomial.) message
                   2978:        pop popVariables
                   2979:        (adjoint1: the first argument must be a polynomial.)  error
                   2980:      } ifelse
                   2981:      /ans (0). def
                   2982:      f (0). eq {   }
                   2983:      {
                   2984:         /xx xx (string) dc def
                   2985:         /dxx [@@@.Dsymbol xx] cat def
                   2986:         /xx xx f (ring) dc ,, def
                   2987:         /dxx dxx f (ring) dc ,, def
                   2988:         /one (1) f (ring) dc ,, def
                   2989:
                   2990:         {
                   2991:           /g f init def
                   2992:           /f f g sub def
                   2993:           /p g xx degree def
                   2994:           /q g dxx degree def
                   2995:           g [[xx one] [dxx one]] replace /g set
                   2996:           g
                   2997:           << (0). dxx sub q npower    xx p npower mul >>
                   2998:           mul
                   2999:           ans add /ans set
                   3000:           f (0). eq { exit } { } ifelse
                   3001:         } loop
                   3002:         ans dehomogenize /ans set
                   3003:      } ifelse
                   3004:      /arg1 ans def
                   3005:   ] pop
                   3006:   popVariables
                   3007:   arg1
                   3008: } def
                   3009:
                   3010: /adjoint {
                   3011:   /arg2 set
                   3012:   /arg1 set
                   3013:   [/in-adjoint /f /xx /xx0] pushVariables
                   3014:   [
                   3015:      /f arg1 def /xx arg2 def
                   3016:      xx toString /xx set
                   3017:      [xx to_records pop] /xx set
                   3018:      xx { /xx0 set f xx0 adjoint1 /f set } map
                   3019:      /arg1 f def
                   3020:   ]pop
                   3021:   popVariables
                   3022:   arg1
                   3023: } def
                   3024:
                   3025: [(adjoint)
                   3026:  [(f xlist adjoint g)
                   3027:   (poly f; string xlist; poly g;)
                   3028:   (g is the adjoint operator of f.)
                   3029:   (The variables to take adjoint are specified by xlist.)
                   3030:   (Example: [(x,y) ring_of_differential_operators 0] define_ring)
                   3031:   (          (x^2 Dx - y x Dx Dy-2). (x,y) adjoint )
                   3032:   $          ((-Dx) x^2 - (-Dx) (-Dy) x y -2). dehomogenize sub :: ==> 0$
                   3033: ]] putUsages
                   3034:
                   3035: %%%%% diagonal for tensor products
                   3036: %% 1998, 12/4 (Sat)
                   3037: %% s_i = x_i, t_i = x_i - y_i,    Restrict to t_i = 0.
                   3038: %% x_i = x_i, y_i = s_i - t_i,
                   3039: %% Dx_i = Dt_i + Ds_i, Dy_i = -Dt_i.
                   3040: /diagonalx {
                   3041:   /arg2 set
                   3042:   /arg1 set
                   3043:   [/in-diagonalx /f] pushVariables
                   3044:   [
                   3045:     (Not implemented yet.) message
                   3046:   ] pop
                   3047:   popVariables
                   3048:   arg1
                   3049: } def
                   3050:
                   3051:
                   3052:
                   3053: %%%%%%%%%%%  distraction2 for b-function
                   3054: /distraction2 {
                   3055:   /arg4 set
                   3056:   /arg3 set
                   3057:   /arg2 set
                   3058:   /arg1 set
                   3059:   [/f  /dx /ss /xx  /ans /n /i /rr] pushVariables
                   3060:   [
                   3061:     /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
                   3062:     f (0). eq {  }
                   3063:     {
                   3064:       /rr f (ring) dc def
                   3065:       xx {toString rr ,, } map /xx set
                   3066:       dx {toString rr ,, } map /dx set
                   3067:       ss {toString rr ,, } map /ss set
                   3068:       /n xx length  def
                   3069:       0 1 n 1 sub {
                   3070:          /i set
                   3071:          /f  f xx i get dx i get ss i get destraction2.1 /f set
                   3072:       } for
                   3073:     } ifelse
                   3074:     /arg1 f def
                   3075:   ]pop
                   3076:   popVariables
                   3077:   arg1
                   3078: } def
                   3079: [(distraction2)
                   3080:  [(f [ list of x-variables ] [ list of D-variables ] [ list of s-variables ])
                   3081:   (   distraction2  result )
                   3082:   $Example 1: [(x,y) ring_of_differential_operators 0] define_ring $
                   3083:   $  (x^2 Dx Dy + x Dy). [(x). (y).] [(Dx). (Dy).] [(x). (y).] distraction2$
                   3084:   $Example 2: (x^4 Dx^2 + x^2). [(x).] [(Dx). ] [(x).] distraction2$
                   3085:  ]
                   3086: ] putUsages
                   3087: /destraction2.1 {
                   3088:   /arg4 set
                   3089:   /arg3 set
                   3090:   /arg2 set
                   3091:   /arg1 set
                   3092:   [/ww /f  /dx /ss /xx /coeff0 /expvec
                   3093:    /coeffvec /expvec2 /ans /one /rr /dd] pushVariables
                   3094:   [
                   3095:     /f arg1 def /xx arg2 def /dx arg3 def /ss arg4 def
                   3096:     f (ring) dc /rr set
                   3097:     /one (1) rr ,, def %%
                   3098:     /ww [ xx toString -1 dx toString 1 ] weightv  def
                   3099:     f ww init f sub (0). eq {   }
                   3100:     { [(destraction2.1 : inhomogeneous with respect to )
                   3101:         xx  ( and )  dx  nl
                   3102:        (Your weight vector may not be generic.)
                   3103:       ] cat error } ifelse
                   3104:     /dd << f dx degree >> << f xx degree >> sub def
                   3105:     f [[xx one]] replace dx coefficients  /coeff0 set
                   3106:     /expvec coeff0 0 get { (integer) dc } map def
                   3107:     /coeffvec coeff0 1 get def
                   3108:     expvec { ss 2 -1 roll factorial } map /expvec2 set
                   3109:     expvec2 coeffvec mul  /ans set
                   3110:     %% x^p d^q, (p > q) case.  x^2( x^2 Dx^2 + x Dx + 1)
                   3111:     dd 0 lt {
                   3112:       %% (ss+1) (ss+2) ... (ss+d)
                   3113:       one 1 1 0 dd sub { (universalNumber) dc ss add mul} for
                   3114:       ans mul /ans set
                   3115:     }
                   3116:     {  } ifelse
                   3117:     /arg1 ans def
                   3118:    ] pop
                   3119:    popVariables
                   3120:    arg1
1.3       takayama 3121: } def
                   3122:
                   3123: /distraction2* {
                   3124:   /arg1 set
                   3125:   [/in-distraction2* /aa /f /vlist /xlist /dlist /slist ] pushVariables
                   3126:   [(CurrentRingp)] pushEnv
                   3127:   [
                   3128:      /aa arg1 def
                   3129:      /f aa 0 get def
                   3130:      /vlist aa 1 get def
                   3131:      /xlist aa 2 get def
                   3132:      /dlist aa 3 get def
                   3133:      /slist aa 4 get def
                   3134:      vlist isArray
                   3135:      {
                   3136:         vlist { toString } map   /vlist set
                   3137:      }
                   3138:      {
                   3139:         vlist toString to_records  /vlist set
                   3140:       } ifelse
                   3141:      xlist isArray
                   3142:      {
                   3143:         xlist { toString } map   /xlist set
                   3144:      }
                   3145:      {
                   3146:         xlist toString to_records  /xlist set
                   3147:       } ifelse
                   3148:      slist isArray
                   3149:      {
                   3150:         slist { toString } map   /slist set
                   3151:      }
                   3152:      {
                   3153:         slist toString to_records  /slist set
                   3154:       } ifelse
                   3155:      [vlist from_records ring_of_differential_operators 0] define_ring pop
                   3156:      f toString .
                   3157:      xlist { . } map
                   3158:      dlist { toString . } map
                   3159:      slist { toString . } map
                   3160:      distraction2 /arg1 set
                   3161:   ] pop
                   3162:   popEnv
                   3163:   popVariables
                   3164:   arg1
1.1       maekawa  3165: } def
                   3166:
                   3167: /message-quiet  {
                   3168:   @@@.quiet { pop } { message } ifelse
                   3169: } def
                   3170: [(message-quiet)
                   3171:  [(s message-quiet )
                   3172:  (string s;)
                   3173:  (It outputs the message s when @@@.quiet is not equal to 1.)
                   3174:  (@@@.quiet is set to 1 when you start sm1 with the option -q.)
                   3175: ]] putUsages
                   3176: /messagen-quiet  {
                   3177:   @@@.quiet { pop } { messagen } ifelse
                   3178: } def
                   3179: [(messagen-quiet)
                   3180:  [(s messagen-quiet )
                   3181:  (string s;)
                   3182:  (It outputs the message s without the newline when @@@.quiet is not equal to 1.)
                   3183:  (@@@.quiet is set to 1 when you start sm1 with the option -q.)
                   3184: ]] putUsages
                   3185:
                   3186: /getvNames0 {
                   3187:   /arg1 set
                   3188:   [/in-getvNames0 /nlist /nn /i] pushVariables
                   3189:   [
                   3190:     /nlist arg1 def
                   3191:     [(N)] system_variable /nn set
                   3192:     nlist { /i set
                   3193:        i nn lt {
                   3194:          [(x) (var) i] system_variable
                   3195:        } {
                   3196:          [(D) (var) i nn sub] system_variable
                   3197:        } ifelse
                   3198:     } map
                   3199:     /arg1 set
                   3200:   ] pop
                   3201:   popVariables
                   3202:   arg1
                   3203: } def
                   3204:
                   3205: /getvNames {
                   3206:   [/in-getvNames /nn] pushVariables
                   3207:   [
                   3208:     [(N)] system_variable /nn set
                   3209:     [0 1 nn 2 mul 1 sub {  } for] getvNames0 /arg1 set
                   3210:   ] pop
                   3211:   popVariables
                   3212:   arg1
                   3213: } def
                   3214: [(getvNames)
                   3215: [(getvNames vlist)
                   3216:  (list vlist)
                   3217:  (It returns of the list of the variables in the order x0, x1, ..., D0, ...)
                   3218:  (Use with [(variableNames) vlist] system_variable.)
                   3219:  (cf. nlist getvNames0 vlist is used internally. cf. getvNamesC)
                   3220: ]] putUsages
                   3221:
                   3222: /getvNamesC {
                   3223:   [/in-getvNamesC /nn /i] pushVariables
                   3224:   [
                   3225:     [(N)] system_variable /nn set
                   3226:     [nn 1 sub -1 0 {  } for nn 2 mul 1 sub -1 nn { } for ] getvNames0 /arg1 set
                   3227:   ] pop
                   3228:   popVariables
                   3229:   arg1
                   3230: } def
                   3231: [(getvNamesC)
                   3232: [(getvNamesC vlist)
                   3233:  (list vlist)
                   3234:  $It returns of the list of the variables in the order 0, 1, 2, ... $
                   3235:  $(cmo-order and output_order).$
                   3236:  (cf. getvNames)
                   3237: ]] putUsages
                   3238:
                   3239: /getvNamesCR {
                   3240:   /arg1 set
                   3241:   [/in-getvNamesCR /rrr] pushVariables
                   3242:   [(CurrentRingp)] pushEnv
                   3243:   [
                   3244:     /rrr arg1 def
                   3245:     rrr isPolynomial {
                   3246:       rrr (0). eq { (No name field for 0 polynomial.) error }
                   3247:       { rrr (ring) dc /rrr set } ifelse
                   3248:     } { } ifelse
                   3249:     [(CurrentRingp) rrr] system_variable
                   3250:     getvNamesC /arg1 set
                   3251:   ] pop
                   3252:   popEnv
                   3253:   popVariables
                   3254:   arg1
                   3255: } def
                   3256: [(getvNamesCR)
                   3257: [(obj getvNamesCR vlist)
                   3258:  (obj ring | poly ; list vlist)
                   3259:  $It returns of the list of the variables in the order 0, 1, 2, ... (cmo-order)$
                   3260:  (for <<obj>>.)
                   3261:  (Example: ( (x-2)^3 ). /ff set )
                   3262:  (         [(x) ring_of_differential_operators 0] define_ring ff getvNamesCR ::)
                   3263: ]] putUsages
                   3264:
                   3265:
                   3266: /reduction-noH {
                   3267:   /arg2 set
                   3268:   /arg1 set
                   3269:   [/in-reduction-noH /ff /gg] pushVariables
                   3270:   [(Homogenize)] pushEnv
                   3271:   [
                   3272:     /ff arg1 def
                   3273:     /gg arg2 def
                   3274:     [(Homogenize) 0] system_variable
                   3275:     ff gg reduction /arg1 set
                   3276:   ] pop
                   3277:   popEnv
                   3278:   popVariables
                   3279:   arg1
                   3280: } def
                   3281: [(reduction-noH)
                   3282: [(f g reduction-noH r)
                   3283:  (poly f; array g; array r;)
                   3284:  (Apply the normal form algorithm for f with the set g. All computations are)
                   3285:  (done with the rule Dx x = x Dx +1, i.e., no homogenization, but other)
                   3286:  (specifications are the same with reduction. cf. reduction)
                   3287:  (g should be dehomogenized.)
                   3288: ]] putUsages
                   3289:
                   3290: /-intInfinity -999999999  def
                   3291: /intInfinity   999999999  def
                   3292: [(intInfinity)
                   3293: [(intInfinity = 999999999)]
                   3294: ] putUsages
                   3295: [(-intInfinity)
                   3296: [(-intInfinity = -999999999)]
                   3297: ] putUsages
                   3298:
                   3299:
                   3300: /maxInArray {
                   3301:   /arg1 set
                   3302:   [/in-maxInArray /v /ans /i /n] pushVariables
                   3303:   [
                   3304:     /v arg1 def
                   3305:     /n v length def
                   3306:     /maxInArray.pos 0 def
                   3307:     n 0 eq {
                   3308:       /ans null def
                   3309:     } {
                   3310:       /ans v 0 get def
                   3311:       1 1 n 1 sub {
                   3312:         /i set
                   3313:         v i get ans gt {
                   3314:            /ans v i get def
                   3315:            /maxInArray.pos i def
                   3316:         } { } ifelse
                   3317:       } for
                   3318:     } ifelse
                   3319:     /arg1 ans def
                   3320:   ] pop
                   3321:   popVariables
                   3322:   arg1
                   3323: } def
                   3324: [(maxInArray)
                   3325: [( [v1 v2 ....] maxInArray m )
                   3326:  (m is the maximum in [v1 v2 ...].)
                   3327:  (The position of m is stored in the global variable maxInArray.pos.)
                   3328: ]] putUsages
                   3329:
                   3330: /cancelCoeff {
1.18      takayama 3331:   /arg1 set
                   3332:   [(reduceContent) arg1] gbext 0 get
                   3333: } def
                   3334: /cancelCoeff_org {
1.1       maekawa  3335:  /arg1 set
                   3336:  [/in-cancelCoeff /ff /gg /dd /dd2] pushVariables
                   3337:  [  /ff arg1 def
                   3338:     ff (0). eq {
                   3339:       /label.cancelCoeff2 goto
                   3340:     } {  } ifelse
                   3341:     /gg ff def
                   3342:     /dd [(lcoeff) ff init ] gbext (universalNumber) dc def
                   3343:     {
                   3344:        gg (0). eq { exit} {  } ifelse
                   3345:        [(lcoeff) gg init] gbext (universalNumber) dc  /dd2 set
                   3346:        [(gcd) dd dd2] mpzext /dd set
                   3347:        dd (1).. eq {
                   3348:          /label.cancelCoeff goto
                   3349:        } {  } ifelse
                   3350:        /gg gg gg init sub def
                   3351:      } loop
                   3352:      [(divByN)  ff dd] gbext 0 get /ff set
                   3353:     /label.cancelCoeff
                   3354:      [(lcoeff) ff init] gbext (universalNumber) dc (0).. lt
                   3355:      { ff (-1).. mul /ff set } {  } ifelse
                   3356:     /label.cancelCoeff2
                   3357:     /arg1 ff def
                   3358:  ] pop
                   3359:  popVariables
                   3360:  arg1
                   3361: } def
                   3362: [(cancelCoeff)
                   3363:  [(f cancelcoeff g)
                   3364:   (poly f,g;)
                   3365:   (Factor out the gcd of the coefficients.)
                   3366:   (Example: (6 x^2 - 10 x). cancelCoeff)
                   3367:   (See also gbext.)
                   3368: ]] putUsages
                   3369:
                   3370:
                   3371: /flatten {
                   3372:   /arg1 set
                   3373:   [/in-flatten /mylist] pushVariables
                   3374:   [
                   3375:      /mylist arg1 def
                   3376:      mylist isArray {
                   3377:        mylist { dup isArray { aload pop } { } ifelse } map /mylist set
                   3378:      }{ } ifelse
                   3379:      /arg1 mylist def
                   3380:   ] pop
                   3381:   popVariables
                   3382:   arg1
                   3383: } def
                   3384: [(flatten)
                   3385:  [(list flatten list2)
                   3386:   (Flatten the list.)
                   3387:   (Example 1: [ [1 2 3] 4 [2]] flatten    ===> [1 2 3 4 2])
                   3388: ]] putUsages
                   3389:
                   3390: %% Take first N elements.
                   3391: /carN {
                   3392:   /arg2 set
                   3393:   /arg1 set
                   3394:   [/in-res-getN /pp /nn /ans] pushVariables
                   3395:   [
                   3396:      /nn arg2 def
                   3397:      /pp arg1 def
                   3398:      pp isArray {
                   3399:        pp length nn lt {
                   3400:          /ans pp def
                   3401:        } {
                   3402:          [pp aload length nn sub /nn set 1 1 nn { pop pop } for ] /ans set
                   3403:        } ifelse
                   3404:      } {
                   3405:        /ans pp def
                   3406:      } ifelse
                   3407:      /arg1 ans def
                   3408:   ] pop
                   3409:   popVariables
                   3410:   arg1
                   3411: } def
                   3412: [(carN)
                   3413: [([f1 ... fm]  n carN  [f1 ... fn])
                   3414:  (carN extracts the first n elements from the list.)
                   3415: ]] putUsages
                   3416:
                   3417: /getRing {
                   3418:   /arg1 set
                   3419:   [/in-getRing /aa /n /i /ans] pushVariables
                   3420:   [
                   3421:     /aa arg1 def
                   3422:     /ans null def
                   3423:     aa isPolynomial {
                   3424:       aa (0). eq {
                   3425:       } {
                   3426:          /ans aa (ring) dc def
                   3427:       } ifelse
                   3428:     } {
                   3429:      aa isArray {
                   3430:        /n aa length 1 sub def
                   3431:        0 1 n { /i set aa i get getRing /ans set
                   3432:                ans tag 0 eq {  } { /getRing.LLL goto } ifelse
                   3433:        } for
                   3434:      }{ } ifelse
                   3435:     } ifelse
                   3436:     /getRing.LLL
                   3437:     /arg1 ans def
                   3438:   ] pop
                   3439:   popVariables
                   3440:   arg1
                   3441: } def
                   3442: [(getRing)
                   3443: [(obj getRing rr)
                   3444:  (ring rr;)
                   3445:  (getRing obtains the ring structure from obj.)
                   3446:  (If obj is a polynomial, it returns the ring structure associated to)
                   3447:  (the polynomial.)
                   3448:  (If obj is an array, it recursively looks for the ring structure.)
                   3449: ]] putUsages
                   3450: /toVectors {
                   3451:   /arg1 set
                   3452:   [/in-toVectors /gg /n /ans] pushVariables
                   3453:   [
                   3454:     /gg arg1 def
                   3455:     gg isArray {
                   3456:       gg length 0 eq {
                   3457:         /ans [ ] def
                   3458:         /toVectors.LLL goto
                   3459:       } {
                   3460:         gg 0 get isInteger {
                   3461:           gg @@@.toVectors2 /ans set
                   3462:         } {
                   3463:           gg @@@.toVectors /ans set
                   3464:         } ifelse
                   3465:         /toVectors.LLL goto
                   3466:       } ifelse
                   3467:     } {
                   3468:       %% It is not array.
                   3469:       gg (array) dc /ans set
                   3470:     } ifelse
                   3471:     /toVectors.LLL
                   3472:     /arg1 ans def
                   3473:    ] pop
                   3474:    popVariables
                   3475:    arg1
                   3476: } def
                   3477: /@@@.toVectors2 {
                   3478:   /arg1 set
                   3479:   [/in-@@@.toVectors2 /gg /ans /n /tmp /notarray] pushVariables
                   3480:   [
                   3481:     /gg arg1 def
                   3482:     /ans gg 1 get @@@.toVectors def
                   3483:     /n   gg 0 get def
                   3484:     gg 1 get isArray not {
                   3485:        /ans [ans] def
                   3486:        /notarray 1 def
                   3487:     }{ /notarray 0 def} ifelse
                   3488:     ans {
                   3489:       /tmp set
                   3490:       tmp length n lt {
                   3491:         tmp
                   3492:         [1 1 n tmp length sub { pop (0). } for ]
                   3493:         join /tmp set
                   3494:       } {  } ifelse
                   3495:       tmp
                   3496:     } map
                   3497:     /ans set
                   3498:     notarray { ans 0 get /ans set } { } ifelse
                   3499:     /arg1 ans def
                   3500:   ] pop
                   3501:   popVariables
                   3502:   arg1
                   3503: } def
                   3504:
                   3505: /@@@.toVectors {
                   3506:   /arg1 set
                   3507:   [/in-@@@.toVectors /gg ] pushVariables
                   3508:   [
                   3509:     /gg arg1 def
                   3510:     gg isArray {
                   3511:       gg { $array$ data_conversion } map
                   3512:     } {
                   3513:       gg (array) data_conversion
                   3514:     }ifelse
                   3515:     /arg1 set
                   3516:    ] pop
                   3517:    popVariables
                   3518:    arg1
                   3519: } def
                   3520:
                   3521: /toVectors2 { toVectors } def
                   3522:
                   3523: /fromVectors { { fromVectors.aux } map } def
                   3524: /fromVectors.aux {
                   3525:   /arg1 set
                   3526:   [/in-fromVector.aux /vv /mm /ans /i /ee] pushVariables
                   3527:   [(CurrentRingp)] pushEnv
                   3528:   [
                   3529:     /vv arg1 def
                   3530:     /mm vv length def
                   3531:     /ans (0). def
                   3532:     /ee (0). def
                   3533:     0 1 mm 1 sub {
                   3534:       /i set
                   3535:       vv i get (0). eq {
                   3536:       } {
                   3537:         [(CurrentRingp) vv i get (ring) dc] system_variable
                   3538:         [(x) (var) [(N)] system_variable 1 sub] system_variable . /ee set
                   3539:         /fromVector.LLL  goto
                   3540:       } ifelse
                   3541:     } for
                   3542:     /fromVector.LLL
                   3543:     %% vv message
                   3544:     0 1 mm 1 sub {
                   3545:       /i set
                   3546:       vv i get (0). eq {
                   3547:       } {
                   3548:         /ans ans
                   3549:             << vv i get >> << ee i npower >> mul
                   3550:          add def
                   3551:       } ifelse
                   3552:       %% [i ans] message
                   3553:     } for
                   3554:     /arg1 ans def
                   3555:   ] pop
                   3556:   popEnv
                   3557:   popVariables
                   3558:   arg1
                   3559: } def
                   3560: [(fromVectors)
                   3561: [
                   3562: ([v1 v2 ...] fromVectors [s1 s2 ...])
                   3563: (array of poly : v1, v2, ... ; poly : s1, s2 ....)
                   3564: (cf. toVectors. <<e_>> varaible is assumed to be the last )
                   3565: (    variable in x.  @@@.esymbol)
                   3566: $Example: [(x,y) ring_of_differential_operators 0] define_ring$
                   3567: $ [(x).  (y).] /ff set  $
                   3568: $ [ff ff] fromVectors :: $
                   3569: ]] putUsages
                   3570:
                   3571: /getOrderMatrix {
                   3572:   /arg1 set
                   3573:   [/in-getOrderMatrix /obj /rr /ans /ans2 /i] pushVariables
                   3574:   [(CurrentRingp)] pushEnv
                   3575:   [
                   3576:     /obj arg1 def
                   3577:     obj isArray {
                   3578:       obj { getOrderMatrix } map /ans set
                   3579:       ans length 0 {
                   3580:          /ans null def
                   3581:       } {
                   3582:          /ans2 null def
                   3583:          0 1 ans length 1 sub {
                   3584:            /i set
                   3585:            ans i get tag 0 eq
                   3586:            {   }
                   3587:            { /ans2 ans i get def } ifelse
                   3588:          } for
                   3589:          /ans ans2 def
                   3590:       } ifelse
                   3591:       /getOrderMatrix.LLL goto
                   3592:     } {  } ifelse
                   3593:     obj tag 14 eq {
                   3594:       [(CurrentRingp) obj] system_variable
                   3595:       [(orderMatrix)] system_variable /ans set
                   3596:       /getOrderMatrix.LLL goto
                   3597:     } {  } ifelse
                   3598:     obj isPolynomial {
                   3599:       obj (0). eq
                   3600:       { /ans null def
                   3601:       } { obj getRing /rr set
                   3602:         [(CurrentRingp) rr] system_variable
                   3603:         [(orderMatrix)] system_variable /ans set
                   3604:       } ifelse
                   3605:       /getOrderMatrix.LLL goto
                   3606:     } { (getOrderMatrix: wrong argument.)  error } ifelse
                   3607:     /getOrderMatrix.LLL
                   3608:     /arg1 ans def
                   3609:   ] pop
                   3610:   popEnv
                   3611:   popVariables
                   3612:   arg1
                   3613: } def
                   3614:
                   3615:
                   3616: [(getOrderMatrix)
                   3617: [(obj getOrderMatrix m)
                   3618:  (array  m)
                   3619:  (getOrderMatrix obtains the order matrix from obj.)
                   3620:  (If obj is a polynomial, it returns the order matrix associated to)
                   3621:  (the polynomial.)
                   3622:  (If obj is an array, it returns an order matrix of an element.)
                   3623: ]] putUsages
                   3624:
                   3625: /nl {
                   3626:    10 $string$ data_conversion
                   3627: } def
                   3628: [(nl)
                   3629: [(nl is the newline character.)
                   3630:  $Example: [(You can break line) nl (here.)] cat message$
1.4       takayama 3631: ]] putUsages
                   3632:
                   3633: /to_int {
                   3634:   /arg1 set
                   3635:   [/to-int /ob /ans] pushVariables
                   3636:   [
                   3637:     /ob arg1 def
                   3638:     /ans ob def
                   3639:     ob isArray {
                   3640:       ob {to_int} map /ans set
                   3641:       /LLL.to_int goto
                   3642:     } {  } ifelse
                   3643:     ob isInteger {
                   3644:       ob (universalNumber) dc /ans set
                   3645:       /LLL.to_int goto
                   3646:     } {  } ifelse
                   3647:     /LLL.to_int
                   3648:     /arg1 ans def
                   3649:   ] pop
                   3650:   popVariables
                   3651:   arg1
                   3652: } def
                   3653: [(to_int)
                   3654: [(obj to_int obj2)
                   3655:  (All integers in obj are changed to universalNumber.)
                   3656:  (Example: /ff [1 2 [(hello) (0).]] def  ff { tag } map ::)
                   3657:  (         ff to_int { tag } map :: )
1.5       takayama 3658: ]] putUsages
                   3659:
                   3660: /define_ring_variables {
1.6       takayama 3661:   [/in-define_ring_variables /drv._v /drv._p /drv._v0] pushVariables
                   3662: %% You cannot use these names for names for polynomials.
1.5       takayama 3663:   [
1.6       takayama 3664:      /drv._v getVariableNames def
                   3665:      /drv._v0 drv._v def
                   3666:      drv._v { dup /drv._p set (/) 2 1 roll ( $) drv._p ($. def ) } map cat
                   3667:      /drv._v set
                   3668: %     drv._v message
                   3669:      [(parse) drv._v] extension
1.5       takayama 3670:   ] pop
                   3671:   popVariables
                   3672: } def
                   3673: [(define_ring_variables)
                   3674: [(It binds  a variable <<a>> in the current ring to the sm1 variable <<a>>.)
                   3675:  (For example, if x is a variable in the current ring, it defines the sm1)
                   3676:  (variable x by /x (x) def)
                   3677: ]] putUsages
                   3678:
                   3679: /boundp {
                   3680:   /arg1 set
                   3681:   [/a /ans] pushVariables
                   3682:   [
                   3683:     /a arg1 def
                   3684:     [(parse) [(/) a ( load tag 0 eq { /ans 0 def } )
                   3685:                     (               { /ans 1 def } ifelse )] cat ] extension
                   3686:     /arg1 ans def
                   3687:   ] pop
                   3688:   popVariables
                   3689:   arg1
                   3690: } def
                   3691: [(boundp)
                   3692:  [( a boundp b)
                   3693:   (string a, b is 0 or 1.)
                   3694:   (If the variable named << a >> is bounded to a value,)
                   3695:   (it returns 1 else it returns 0.)
                   3696:   $Example: (hoge) boundp ::$
1.1       maekawa  3697: ]] putUsages
1.10      takayama 3698: [(isSubstr)
                   3699:  [
                   3700:   (s1 s2 isSubstr pos)
                   3701:   (If s1 is a substring of s2, isSubstr returns the position in s2 from which)
                   3702:   (s1 is contained in s2.)
                   3703:   (If s1 is not a substring of s2, then isSubstr returns -1.)
                   3704:  ]
                   3705: ] putUsages
                   3706: /isSubstr {
                   3707:   /arg2 set /arg1 set
                   3708:   [/in-isSubstr /s1 /s2 /i1 /i2 /n1 /n2
                   3709:    /ans /flg
                   3710:   ]  pushVariables
                   3711:   [
                   3712:     /s1 arg1 def
                   3713:     /s2 arg2 def
                   3714:     s1 (array) dc /s1 set
                   3715:     s2 (array) dc /s2 set
                   3716:     /n1 s1 length def
                   3717:     /n2 s2 length def
                   3718:     /ans -1 def
                   3719:     0 1 n2 n1 sub {
                   3720:       /i2 set
                   3721:       /flg 1 def
                   3722:       0 1 n1 1 sub {
                   3723:         /i1 set
                   3724:         s1 i1 get s2 i2 i1 add get eq {
                   3725:         } {
                   3726:           /flg 0 def exit
                   3727:         } ifelse
                   3728:       } for
                   3729:       flg {
                   3730:         /ans i2 def
                   3731:         /isSubstr.L2 goto
                   3732:       } { /ans -1 def } ifelse
                   3733:     } for
                   3734:     /isSubstr.L2
                   3735:     /arg1 ans def
                   3736:   ] pop
                   3737:   popVariables
                   3738:   arg1
1.14      takayama 3739: } def
                   3740:
                   3741: [(execve)
                   3742:  [
                   3743:    (command execve)
                   3744:    ([arg0 arg1 arg2 ...] execve )
                   3745:    (It executes the command by the system call execve.)
                   3746:    (cf. system, forkExec)
                   3747:  ]
                   3748: ] putUsages
                   3749:
                   3750: /execve {
                   3751:   /execve.arg set
                   3752:   [(forkExec) execve.arg [ ] 1] extension
1.15      takayama 3753: } def
                   3754:
                   3755: [(beginEcart)
                   3756:  [
                   3757:    (beginEcart)
                   3758:    (Set the environments for the ecart division algorithm.)
                   3759:  ]
                   3760: ] putUsages
                   3761:
1.23      takayama 3762: /ecart.debug_reduction1 0 def
1.15      takayama 3763: /beginEcart {
                   3764:   (red@) (ecart) switch_function
                   3765:   [(Ecart) 1] system_variable
1.16      takayama 3766:   [(CheckHomogenization) 0] system_variable
                   3767:   [(ReduceLowerTerms) 0] system_variable
                   3768:   [(AutoReduce) 0] system_variable
1.17      takayama 3769:   [(EcartAutomaticHomogenization) 0] system_variable
1.23      takayama 3770:   ecart.debug_reduction1 {
                   3771:     (red@) (debug) switch_function
                   3772:   } {  } ifelse
1.15      takayama 3773: } def
                   3774:
                   3775: [(endEcart)
                   3776:  [
                   3777:    (endEcart)
                   3778:    (End of using the ecart division algorithm.)
                   3779:  ]
                   3780: ] putUsages
                   3781:
                   3782: /endEcart {
                   3783:   (red@) (standard) switch_function
                   3784:   [(Ecart) 0] system_variable
1.21      takayama 3785:   [(degreeShift) (reset)] homogenize pop
1.10      takayama 3786: } def
1.19      takayama 3787:
                   3788: /ord_ws_all {
                   3789:   /arg2 set /arg1 set
                   3790:   [(ord_ws_all) arg1 arg2] gbext
                   3791: } def
                   3792: [(ord_ws_all)
                   3793:  [
                   3794:    (fv wv ord_ws_all degree)
                   3795:    (  ord_ws_all returns the ord with respect to the weight vector wv.)
                   3796:    $Example: [(x,y) ring_of_differential_operators 0] define_ring  $
                   3797:    $        (Dx^2+x*Dx*Dy+2). [(Dx) 1 (Dy) 1] weightv ord_ws_all ::  $
                   3798:    (  )
                   3799:    (fv [wv shiftv] ord_ws_all degree)
                   3800:    (  ord_ws_all returns the ord with respect to the weight vector wv and)
                   3801:    (  the shift vector shiftv.)
                   3802:    $Example: [(x,y) ring_of_differential_operators 0] define_ring  $
                   3803:    $        [(Dx^2+x*Dx*Dy+2). (Dx).] [[(Dx) 1 (Dy) 1] weightv [0 2]] ord_ws_all ::$
                   3804:    (  )
                   3805:    (cf: init, gbext.   Obsolete: ord_w, ord_w_all)
                   3806:  ]
                   3807: ] putUsages
1.22      takayama 3808:
                   3809: [(newVector)
                   3810:  [( n newVector vec)
                   3811: ]] putUsages
                   3812: /newVector {
                   3813:   /arg1 set
                   3814:   [/in-newVector /n] pushVariables
                   3815:   [
                   3816:     /n arg1 def
                   3817:     [(newVector) n] extension /arg1 set
                   3818:   ] pop
                   3819:   popVariables
                   3820:   arg1
                   3821: } def
                   3822:
                   3823: [(newMatrix)
                   3824:  [( [m n] newMatrix mat)
                   3825: ]] putUsages
                   3826: /newMatrix {
                   3827:   /arg1 set
                   3828:   [/in-newMatrix /n] pushVariables
                   3829:   [
                   3830:     /n arg1 def
                   3831:     [(newMatrix) n 0 get n 1 get] extension /arg1 set
                   3832:   ] pop
                   3833:   popVariables
                   3834:   arg1
1.25      takayama 3835: } def
                   3836:
                   3837: /addStdoutStderr {
                   3838:   [(>) (stringOut://@@@stdout) (2>) (stringOut://@@@stderr)] join
1.27      takayama 3839: } def
                   3840:
                   3841: [(,,,)
                   3842: [(reparse a polynomial or polynomials)]
                   3843: ] putUsages
                   3844: /,,, {
                   3845:   /arg1 set
                   3846:   [/in-reparse /ff] pushVariables
                   3847:   [
                   3848:     /ff arg1 def
                   3849:     ff tag 6 eq {
                   3850:       ff { ,,, } map /arg1 set
                   3851:     } {
                   3852:       ff toString . /arg1 set
                   3853:     } ifelse
1.29      takayama 3854:   ] pop
                   3855:   popVariables
                   3856:   arg1
                   3857: } def
                   3858:
                   3859: /to_univNum {
                   3860:   /arg1 set
                   3861:   [/rr  ] pushVariables
                   3862:   [
                   3863:     /rr arg1 def
                   3864:     rr isArray {
                   3865:       rr { to_univNum } map /rr set
                   3866:     } {
                   3867:     } ifelse
                   3868:     rr isInteger {
                   3869:       rr (universalNumber) dc /rr set
                   3870:     } {
                   3871:     } ifelse
                   3872:     /arg1 rr def
                   3873:   ] pop
                   3874:   popVariables
                   3875:   arg1
                   3876: } def
                   3877: [(to_univNum)
                   3878: [(obj to_univNum obj2)
                   3879:  (Example. [ 2 (3).. ] to_univNum)
                   3880:  (cf. to_int)
                   3881: ]] putUsages
                   3882:
                   3883: [(lcm)
                   3884:  [ ([a b c ...] lcm r)
                   3885:    (cf. polylcm, mpzext)
                   3886:  ]
                   3887: ] putUsages
                   3888: /lcm {
                   3889:   /arg1 set
                   3890:   [/aa /bb /rr /pp /i] pushVariables
                   3891:   [
                   3892:     /aa arg1 def
                   3893:     /rr (1).. def
                   3894:     /pp 0 def % isPolynomial array?
                   3895:     0 1 aa length 1 sub {
                   3896:       /i set
                   3897:       aa i get  isPolynomial {
                   3898:         /pp 1 def
                   3899:         exit
                   3900:       } {  } ifelse
                   3901:     } for
                   3902:
                   3903:     0 1 aa length 1 sub {
                   3904:       /i set
                   3905:       pp {
                   3906:         [rr aa i get] polylcm /rr set
                   3907:       } {
                   3908:         [(lcm) rr aa i get ] mpzext /rr set
                   3909:       } ifelse
                   3910:     } for
                   3911:
                   3912:     /arg1 rr def
                   3913:   ] pop
                   3914:   popVariables
                   3915:   arg1
                   3916: } def
                   3917: [(gcd)
                   3918:  [ ([a b c ...] gcd r)
                   3919:    (cf. polygcd, mpzext)
                   3920:  ]
                   3921: ] putUsages
                   3922: /gcd {
                   3923:   /arg1 set
                   3924:   [/aa /bb /rr /pp /i] pushVariables
                   3925:   [
                   3926:     /aa arg1 def
                   3927:     /rr (1).. def
                   3928:     /pp 0 def % isPolynomial array?
                   3929:     0 1 aa length 1 sub {
                   3930:       /i set
                   3931:       aa i get  isPolynomial {
                   3932:         /pp 1 def
                   3933:         /rr aa i get def
                   3934:         exit
                   3935:       } {  } ifelse
                   3936:     } for
                   3937:
                   3938:     pp {
                   3939:      0 1 aa length 1 sub {
                   3940:        /i set
                   3941:        [rr aa i get] polygcd /rr set
                   3942:      } for
                   3943:     } {
                   3944:       aa ngcd /rr set
                   3945:     } ifelse
                   3946:
                   3947:     /arg1 rr def
                   3948:   ] pop
                   3949:   popVariables
                   3950:   arg1
                   3951: } def
                   3952:
                   3953: [(denominator)
                   3954:  [ ([a b c ...] denominator r)
                   3955:    ( a denominator r )
                   3956:    (cf. dc, numerator)
1.30    ! takayama 3957:    (Output is Z or a polynomial.)
1.29      takayama 3958:  ]
                   3959: ] putUsages
                   3960: % test data.
                   3961: %  [(1).. (2).. div (1).. (3).. div ] denominator
                   3962: %  [(2).. (3).. (4).. ] denominator
                   3963: /denominator {
                   3964:   /arg1 set
                   3965:   [/pp /dd /ii /rr] pushVariables
                   3966:   [
                   3967:     /pp arg1 def
1.30    ! takayama 3968:     pp to_univNum /pp set
1.29      takayama 3969:     {
                   3970:       pp isArray {
                   3971:         pp { denominator } map /dd set
                   3972:         /rr dd lcm def % rr = lcm(dd[0], dd[1], ... )
                   3973:         rr /dd set
                   3974:         exit
                   3975:       } {  } ifelse
                   3976:
                   3977:       pp (denominator) dc /dd set
                   3978:       exit
                   3979:
                   3980:     } loop
                   3981:     /arg1 dd def
                   3982:   ] pop
                   3983:   popVariables
                   3984:   arg1
                   3985: } def
                   3986:
                   3987: [(numerator)
                   3988:  [ ([a b c ...] numerator r)
                   3989:    ( a numerator r )
                   3990:    (cf. dc, denominator)
1.30    ! takayama 3991:    (Output is a list of Z or polynomials.)
1.29      takayama 3992:  ]
                   3993: ] putUsages
                   3994: % test data.
                   3995: /numerator {
                   3996:   /arg1 set
                   3997:   [/pp /dd /ii /rr] pushVariables
                   3998:   [
                   3999:     /pp arg1 def
1.30    ! takayama 4000:     pp to_univNum /pp set
1.29      takayama 4001:     {
                   4002:       pp isArray {
                   4003:         pp denominator /dd set
                   4004:         pp dd mul /rr set
1.30    ! takayama 4005:         rr cancel /rr set
1.29      takayama 4006:         exit
                   4007:       } {  } ifelse
                   4008:
                   4009:       pp (numerator) dc /rr set
                   4010:       exit
                   4011:
                   4012:     } loop
                   4013:     /arg1 rr def
                   4014:   ] pop
                   4015:   popVariables
                   4016:   arg1
                   4017: } def
                   4018:
1.30    ! takayama 4019: /cancel.Q {
1.29      takayama 4020:   /arg1 set
                   4021:   [/aa /rr /nn /dd /gg]  pushVariables
                   4022:   [
                   4023:     /aa arg1 def
                   4024:     {
                   4025:       aa isRational {
                   4026:          [(cancel) aa] mpzext /rr set
                   4027:          rr (denominator) dc (1).. eq {
                   4028:             /rr rr (numerator) dc def
                   4029:             exit
                   4030:          } { } ifelse
                   4031:          rr (denominator) dc (-1).. eq {
                   4032:             /rr rr (numerator) dc (-1).. mul def
                   4033:          } { } ifelse
                   4034:          exit
                   4035:       } { } ifelse
                   4036:
                   4037:       /rr aa def
                   4038:       exit
                   4039:     } loop
                   4040:     /arg1 rr def
                   4041:   ] pop
                   4042:   popVariables
                   4043:   arg1
                   4044: } def
                   4045:
1.30    ! takayama 4046: /cancel.one {
1.29      takayama 4047:   /arg1 set
                   4048:   [/aa /rr /nn /dd /gg]  pushVariables
                   4049:   [
                   4050:     /aa arg1 def
                   4051:     {
                   4052:       aa isRational {
                   4053:         aa (numerator) dc /nn set
                   4054:         aa (denominator) dc /dd set
                   4055:         nn isUniversalNumber dd isUniversalNumber and {
1.30    ! takayama 4056:           /rr aa cancel.Q def
1.29      takayama 4057:           exit
1.30    ! takayama 4058:         } { (cancel: not implemented) error } ifelse
1.29      takayama 4059:       } { } ifelse
                   4060:
                   4061:       /rr aa def
                   4062:       exit
                   4063:     } loop
                   4064:     /arg1 rr def
                   4065:   ] pop
                   4066:   popVariables
                   4067:   arg1
                   4068: } def
                   4069:
1.30    ! takayama 4070: [(cancel)
        !          4071:  [ (obj cancel r)
1.29      takayama 4072:    (Cancel numerators and denominators)
                   4073:    (The implementation has not yet been completed. It works only for Q.)
                   4074: ]] putUsages
1.30    ! takayama 4075: /cancel {
1.29      takayama 4076:   /arg1 set
                   4077:   [/aa /rr] pushVariables
                   4078:   [
                   4079:     /aa arg1 def
                   4080:     aa isArray {
1.30    ! takayama 4081:       aa {cancel} map /rr set
1.29      takayama 4082:     } {
1.30    ! takayama 4083:       aa cancel.one /rr set
1.29      takayama 4084:     } ifelse
                   4085:     /arg1 rr def
1.27      takayama 4086:   ] pop
                   4087:   popVariables
                   4088:   arg1
1.22      takayama 4089: } def
1.30    ! takayama 4090:
        !          4091: /nnormalize_vec {
        !          4092:   /arg1 set
        !          4093:   [/pp /rr /dd ] pushVariables
        !          4094:   [
        !          4095:     /pp arg1 def
        !          4096:     pp denominator /dd set
        !          4097:     dd (0).. lt { (nnormalize_vec: internal error) error } { } ifelse
        !          4098:     pp numerator dd mul cancel /pp set
        !          4099:     /@@@.nnormalize_vec_c dd def
        !          4100:     pp gcd /dd set
        !          4101:     dd (0).. lt { (nnormalize_vec: internal error) error } { } ifelse
        !          4102:     pp (1).. dd div mul cancel /rr set
        !          4103:     @@@.nnormalize_vec_c dd div cancel /@@@.nnormalize_vec_c set
        !          4104:     /arg1 rr def
        !          4105:   ] pop
        !          4106:   popVariables
        !          4107:   arg1
        !          4108: } def
        !          4109: [(nnormalize_vec)
        !          4110: [(pp nnormalize_vec npp)
        !          4111:  (It normalizes a given vector of Q into a vector of Z with relatively prime)
        !          4112:  (entries by multiplying a postive number.)
        !          4113: ]] putUsages
1.22      takayama 4114:
1.24      takayama 4115: /usages {
                   4116:   /arg1 set
                   4117:   [/name /flag /n /k /slist /m /i /sss] pushVariables
                   4118:   [
                   4119:     /name arg1 def
                   4120:     /flag true def
                   4121:
                   4122:  %BUG: should use regular expression in a future.
                   4123:  name tag 1 eq {
                   4124:    @.usages { 0 get } map shell { (, ) nl } map /sss set
                   4125:  } {
                   4126:
                   4127:     /sss [ ] def
                   4128:    @.usages length /n set
                   4129:    0 1 << n 1 sub >>
                   4130:    {
                   4131:       /k set
                   4132:       name << @.usages k get 0 get >> eq
                   4133:       {
                   4134:         /slist @.usages k get 1 get def
                   4135:         /m slist length def
                   4136:         0 1 << m 1 sub >> {
                   4137:           /i set
                   4138:           sss slist i get append nl append /sss set
                   4139:         } for
                   4140:         /flag false def
                   4141:       }
                   4142:       { }
                   4143:       ifelse
                   4144:    } for
                   4145:
                   4146:    %BUG:  cannot get usages of primitives.
                   4147:    flag
                   4148:    {name Usage  /sss [(Usage of ) name ( could not obtained.) nl ] def}
                   4149:    { }
                   4150:    ifelse
                   4151:  } ifelse
                   4152:    /arg1 sss cat def
                   4153:    ] pop
                   4154:    popVariables
                   4155:    arg1
                   4156: } def
                   4157: [(usages)
                   4158:  [(key usages usages-as-a-string)
                   4159:   (num usages list-of-key-words)
                   4160: ]] putUsages
1.1       maekawa  4161:
                   4162: ;
                   4163:
                   4164:
                   4165:
                   4166:
                   4167:
                   4168:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>