[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.13

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

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