[BACK]Return to help.k CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097

Annotation of OpenXM/src/k097/help.k, Revision 1.9

1.9     ! takayama    1: /* $OpenXM: OpenXM/src/k097/help.k,v 1.8 2001/01/05 11:14:25 takayama Exp $ */
1.1       maekawa     2: if (K00_verbose)
1.8       takayama    3:   Println("help.k:  8/6, 1996 --- 8/7, 1996. 3/6, 1997 --- 12/21, 1997.");
1.1       maekawa     4:
                      5: def help(x) {
                      6:   if (Length(Arglist) < 1) {
                      7:      ShowKeyWords(" ");
                      8:   } else {
                      9:      Help(x);
                     10:   }
                     11: }
                     12:
                     13:
                     14: def Help(key) {
                     15:   local n,i,item,m,item1,j;
                     16:   if (Length(Arglist) < 1) {
                     17:      ShowKeyWords(" ");
                     18:      return( [ ] );
                     19:   }
                     20:
                     21:   if (key == "ALL") {
                     22:     ShowKeyWords("ALL"); return(0);
                     23:   }
                     24:   n = Length(Helplist);
                     25:   PSfor (i=0; i<n; i++) {
1.9     ! takayama   26:     item = Helplist[i,1];
1.1       maekawa    27:     if (item[0] == key) {
                     28:        if (IsArray(item[1])) {
                     29:          item1 = item[1];
                     30:          m = Length(item1);
                     31:          for (j=0; j<m; j++) {
                     32:            Println(item1[j]);
                     33:          }
                     34:        }else{
                     35:          Println(item[1]);
                     36:        }
                     37:        return(item);
                     38:     }
                     39:   }
                     40:   Print("The key word <<"); Print(key); Println(">> could not be found.");
                     41:   return([ ]);
                     42: }
                     43:
                     44:
                     45: def ShowKeyWords(ss) {
                     46:   local i,j,n,keys,max,width,m,k,kk,tmp0;
                     47:   Ln();
                     48:   n = Length(Helplist);
                     49:   keys = [" " ];  /* This is a gate keeper for shell. */
                     50:   PSfor (i=0; i< n; i++ ) {
1.9     ! takayama   51:     keys = Append(keys,Helplist[i,1,0]);
1.1       maekawa    52:   }
                     53:   keys = sm1(keys," shell ");
                     54:   n = Length(keys);
                     55:   if (ss == "ALL") {
                     56:     PSfor (i=1; i<n; i++) {
                     57:       Print("# "); Print(keys[i]); Ln();
                     58:       Help(keys[i]); Ln();
                     59:     }
                     60:     return(0);
                     61:   }
                     62:   max = 0;
                     63:   PSfor (i=1; i<n; i++) {
                     64:      if (Length(keys[i]) > max) {
                     65:         max = Length(keys[i]);
                     66:      }
                     67:   }
                     68:   /* Println(max); */
                     69:   max = max+3;
                     70:   width = 80;
                     71:   m = 0;
                     72:   while ((m*max) < 80) {
                     73:      m = m+1;
                     74:   }
                     75:   if (m > 1) m = m-1;
                     76:   k = 0; kk = 0;
                     77:   PSfor (i=1; i<n; i++) {
                     78:     Print(keys[i]); kk = kk+1;
                     79:     k = k+Length(keys[i]);
                     80:     tmp0 = max-Length(keys[i]);
                     81:     /*for (j=0; j < tmp0 ; j++) {
                     82:        k = k+1;
                     83:        if (kk < m) {Print(" ");}
                     84:     }*/
                     85:     k = k+tmp0;
                     86:     if (kk < m) {
                     87:         sm1(" [ 0 1 ", tmp0, " (integer) dc 1 sub { pop $ $ } for ] aload length cat_n messagen ");
                     88:     }
                     89:     if (kk >= m) {
                     90:       kk = 0; k=0; Ln();
                     91:     }
                     92:   }
                     93:   Ln();
                     94:   Println("Type in Help(keyword);  to see a help message (string keyword).");
1.9     ! takayama   95:   Println("A new help system can be used as man() or man(keyword).");
1.1       maekawa    96:
                     97:   /* Println(keys); */
                     98: }
                     99:
                    100: def ShowKeyWordsOfSm1(ss) {
                    101:   local i,j,n,keys,max,width,m,k,kk,tmp0;
                    102:   Ln();
                    103:   sm1(" /help_Sm1Macro @.usages def ");
                    104:   n = Length(help_Sm1Macro);
                    105:   keys = [" " ];
                    106:   for (i=0; i< n; i++ ) {
                    107:     keys = Append(keys,help_Sm1Macro[i,0]);
                    108:   }
                    109:   keys = sm1(keys," shell ");
                    110:   n = Length(keys);
                    111:   if (ss == "ALL") {
                    112:     for (i=1; i<n; i++) {
                    113:       tmp0 = keys[i];
                    114:       Print("# "); Print(tmp0); Ln();
                    115:       sm1(tmp0," usage "); Ln();
                    116:     }
                    117:     return(0);
                    118:   }
                    119:
                    120:   max = 0;
                    121:   for (i=1; i<n; i++) {
                    122:      if (Length(keys[i]) > max) {
                    123:         max = Length(keys[i]);
                    124:      }
                    125:   }
                    126:   /* Println(max); */
                    127:   max = max+3;
                    128:   width = 80;
                    129:   m = 0;
                    130:   while ((m*max) < 80) {
                    131:      m = m+1;
                    132:   }
                    133:   k = 0; kk = 0;
                    134:   for (i=1; i<n; i++) {
                    135:     Print(keys[i]); kk = kk+1;
                    136:     k = k+Length(keys[i]);
                    137:     tmp0 = max-Length(keys[i]);
                    138:     if (kk >= m) {
                    139:     }else {
                    140:       for (j=0; j < tmp0 ; j++) {
                    141:          k = k+1;
                    142:          Print(" ");
                    143:       }
                    144:     }
                    145:     if (kk >= m) {
                    146:       kk = 0; k=0; Ln();
                    147:     }
                    148:   }
                    149:   Ln();
                    150:   Ln();
                    151:   Println("Type in (keyword) usage ;  to see a help message.");
                    152:
                    153:   /* Println(keys); */
                    154: }
                    155:
1.9     ! takayama  156: /* Start of HelpAdd */
        !           157: HelpAdd(
        !           158: ["Map",
        !           159:  ["Map(<<karg>>,<<func>>) applies the function <<func>> to the <<karg>> (string <<func>>).",
        !           160:   " Ex. Map([82,83,85],\"AsciiToString\"):"],
        !           161:  ["karg","func"],
        !           162:  null,
        !           163:  "apply a function to each element of a list."
        !           164: ]);
        !           165: HelpAdd(["Position",
        !           166:  ["Position(<<list>>,<<elem>>) returns the position p of the element <<elem>> in",
        !           167:   " the array <<list>>. If <<elem>> is not in <<list>>, it return -1",
        !           168:   " (array <<list>>).",
        !           169:   "Ex. Position([1,34,2],34): "],
        !           170:  ["list","elem"],
        !           171:  null,
        !           172:  "find a position of an element in a list."
        !           173: ]);
        !           174: HelpAdd(["StringToAsciiArray",
        !           175:  ["StringToAsciiArray(<<s>>) decomposes the string <<s>> into an array of ",
        !           176:   "ascii codes of <<s>>.",
        !           177:   "cf. AsciiToString."],
        !           178:  ["s"],
        !           179:  ["AsciiToString"],
        !           180:  "translate a string to an array of ascii codes."
        !           181: ]);
        !           182:
        !           183: HelpAdd(["NewArray",
        !           184:  ["NewArray(<<n>>) returns an array of size integer <<n>>."],
        !           185:  ["n"],
        !           186:  ["NewMatrix"],
        !           187:  "it returns an array of a given size."
        !           188: ]);
        !           189: HelpAdd(["GetEnv",
        !           190:  ["GetEnv(<<s>>) returns the value of the environmental variable string <<s>>."],
        !           191:  ["s"],
        !           192:  null,
        !           193:  "value of an environmental variable."
        !           194: ]);
        !           195: HelpAdd(["Boundp",
        !           196:  ["Boundp(<<s>>) checks if the symbol <<s>> is bounded to a value or not (string <<s>>)."],
        !           197:  ["s"],
        !           198:  null,
        !           199:  "check if a symbol is assigned a value or not."
        !           200: ]);
        !           201: HelpAdd(["Rest",
        !           202:  ["Rest(<<a>>) returns the rest (cdr) of  <<a>> (list <<a>>)."],
        !           203:  ["a"],
        !           204:  ["Append","Join"],
        !           205:  "it returns the rest of a given list."
        !           206: ]);
        !           207: HelpAdd(["GetPathName",
        !           208:  ["GetPathName(<<s>>) checks if the file <<s>> exists in the current directory or",
        !           209:  "in LOAD_K_PATH. If there exists, it returns the path name (string <<s>>)."],
        !           210:  ["s"],
        !           211:  ["GetEnv"],
        !           212:  "find a file in the search path."
        !           213: ]);
        !           214: HelpAdd(["Load_sm1",
        !           215: ["Load_sm1(<<s>>,<<flag>>) loads a sm1 program from <<s>>[0], <<s>>[1], ....",
        !           216:  "If loading is succeeded, the already-loaded <<flag>> is set to true.",
        !           217:  "(list <<s>>, string <<flag>>)."],
        !           218:  ["s","flag"],
        !           219:  ["load"],
        !           220:  "load a sm1 program"
        !           221: ]);
        !           222: HelpAdd(["ReParse",
        !           223:  ["Reparse(<<obj>>): ",
        !           224:  "It parses the given object <<obj>> in the current ring."],
        !           225:  ["obj"],
        !           226:  ["Mapto","RingD"],
        !           227:  "parses a given object in the current ring."
        !           228: ]);
        !           229: HelpAdd(["Pmat",
        !           230:  ["Pmat(<<m>>): ",
        !           231:   "Print the array <<m>> in a pretty way."],
        !           232:  ["m"],
        !           233:  ["Println"],
        !           234:  "print an given array in a pretty way."
        !           235: ]);
        !           236: HelpAdd(["Tag",
        !           237: ["Tag(<<f>>) returns the datatype tag of <<f>> where",
        !           238:  "0: null, 5: string,  6: array, 9: polynomial, 15: integer(big-num),  ",
        !           239:  "16: rational, 18:double, 257: Error ",
        !           240:  "Ex. Tag([Poly(\"0\"), 0]):"],
        !           241:  ["f"],
        !           242:  ["Is*"],
        !           243:  "return the tag of a given object."
        !           244: ]);
        !           245: HelpAdd(["Error",
        !           246:  ["Error(<<s>>) causes an error and outputs a message <<s>>."],
        !           247:  ["s"],
        !           248:  null,
        !           249:  "cause an error."
        !           250: ]);
        !           251:
        !           252: HelpAdd(["Help",
        !           253:  ["Help(<<key>>) or help(<<key>>) shows an explanation on the <<key>> (string <<key>>)."],
        !           254:  ["key"],
        !           255:  ["HelpAdd","help","man"],
        !           256:  "display a help message."
        !           257: ]);
1.1       maekawa   258: HelpAdd(["HelpAdd",
1.9     ! takayama  259:  ["HelpAdd([<<key>>,<<explanation>>]) (string <<key>>, string <<explanation>>)",
        !           260:   " or (string <<key>>, array <<explanation>>).",
        !           261:   "   ",
        !           262:   "HelpAdd([<<key>>,<<explanation>>,<<category>>]) is used to specify ",
        !           263:   "the <<category>> of the topics."],
        !           264:   ["key","explanation"],
        !           265:   ["help","man"],
        !           266:   "Add a help message in the system."
        !           267: ]);
        !           268:
1.1       maekawa   269: HelpAdd(["load",
1.9     ! takayama  270:  ["load(<<fname>>) loads the file << fname >>(string <<fname>>).",
        !           271:   "load <<fname>>  loads the file << fname >>.",
        !           272:   "load[<<fname>>] loads the file << fname >> with the preprocessing by /lib/cpp."
        !           273: ],
        !           274: ["fname"],
        !           275: ["Load_sm1"],
        !           276: "load a given file."]);
        !           277:
        !           278: HelpAdd(["Ln","Print newline.",
        !           279: [ ],
        !           280: ["Print","Println"],
        !           281: "print newline."]);
        !           282: HelpAdd(["Println",
        !           283:  ["Println(<<f>>) prints <<f>> and goes to the new line."],
        !           284:  ["f"],
        !           285:  ["Ln","Print","Stderr."],
        !           286:  "display a given object with the newline."
        !           287: ]);
        !           288: HelpAdd(["Print",
        !           289:  ["Print(<<f>>) prints <<f>> without the newline."],
        !           290:  ["f"],
        !           291:  ["Println"],
        !           292:  "display a given object."
        !           293: ]);
1.1       maekawa   294: HelpAdd(["Poly",
1.9     ! takayama  295:  ["Poly(<<name>>) parses a given string <<name>> in the current ring ",
        !           296:   "and returns a polynomial."
        !           297:  ],
        !           298:  ["name"],
        !           299:  ["DC","PolyR","ReParse","RingD"],
        !           300:  "translate a string to a polynomial."
        !           301: ]);
1.1       maekawa   302: HelpAdd(["PolyR",
1.9     ! takayama  303:  ["PolyR(<<name>>,<<r>>) parses a string <<name>> in the ring <<r>> ",
        !           304:  "Ex. r = RingD(\"x,y\"); y = PolyR(\"x+2*y\",r); "],
        !           305:  ["name","r"],
        !           306:  ["Poly"],
        !           307:  "translate a string to a polynomial in a given ring."
        !           308: ]);
1.1       maekawa   309: HelpAdd(["RingD",
1.9     ! takayama  310:  ["RingD(<<names>>) defines a new ring of differential operators (string <<names>>).",
        !           311:   "RingD(<<names>>,<<weight_vector>>) defines a new ring with the weight vector",
        !           312:   "(string <<names>>, array <<weight_vector>>).",
        !           313:   "RingD(<<names>>,<<weight_vector>>,<<characteristic>>)",
        !           314:   "Dx is the associated variable to x where Dx*x - x*Dx = 1 holds.",
        !           315:   " Ex. RingD(\"x,y\",[[\"x\",2,\"y\",1]]) "],
        !           316:   ["names","weight_vector"],
        !           317:   ["GetRing","PolyR","ReParse","SetRing"],
        !           318:   "define a new ring of differential operators."
        !           319: ]);
        !           320: HelpAdd(["Reduction",
        !           321:  ["Reduction(<<f>>,<<G>>) returns the remainder and sygygies when
        !           322:    <<f>> is devided by <<G>> (polynomial <<f>>, array <<G>>)."],
        !           323:  ["f","g"],
        !           324:  ["Gb"],
        !           325:  "get the remainder and the quotients."
        !           326: ]);
        !           327: HelpAdd(["AddString","AddString(<<list>>) returns the concatnated string (array <<list>>).",
        !           328:  ["list"],
        !           329:  null,
        !           330:  "concatenate strings."
        !           331: ]);
        !           332: HelpAdd(["AsciiToString",
        !           333:  "AsciiToString(<<ascii_code>>) returns the string of which
        !           334:   ascii code is <<ascii_code>> (integer <<ascii_code>>).",
        !           335:  ["ascii_code"],
        !           336:  ["!ReservedNames","AddString","StringToAsciiArray"],
        !           337:  "translate from ascii code to a string."
        !           338: ]);
        !           339: HelpAdd(["ToString",
        !           340:  "ToString(<<obj>>) transforms the <<obj>> to a string.",
        !           341:  ["obj"],
        !           342:  ["DC"],
        !           343:  "translate a given object to a string."
        !           344: ]);
        !           345: HelpAdd(["Numerator",
        !           346:  "Numerator(<<f>>) returns the numerator of the rational <<f>>.",
        !           347:  ["f"],
        !           348:  ["Cancel","Denominator"],
        !           349:  "numerator"
        !           350: ]);
        !           351: HelpAdd(["Denominator",
        !           352:  "Denominator(<<f>>) returns the denominator of the rational <<f>>.",
        !           353:  ["f"],
        !           354:  ["Cancel","Numerator"],
        !           355:  "denominator"
        !           356: ]);
1.7       takayama  357: HelpAdd(["Replace",
1.9     ! takayama  358:   ["Replace(<<f>>,<<rule>>) rewrites <<f>> by the <<rule>> (polynomial <<f>>, array <<rule>>).  ",
        !           359:    "Ex. RingD(\"x,y\"); Replace( (x+y)^3, [[x,Poly(\"1\")]])"],
        !           360:   ["f","rule"],
        !           361:   ["replace (sm1)"],
        !           362:   "substitute variables by given values"
        !           363: ]);
1.1       maekawa   364: HelpAdd(["SetRingVariables",
1.9     ! takayama  365:  "Set the generators of the current ring as global variables.
        !           366:   You do not need explicitly call this function which is called from RingD.
        !           367:   cf. RingD(), Poly(), PolyR()",
        !           368:   [ ],
        !           369:   ["RingD"],
        !           370:   "  "
        !           371: ]);
        !           372: HelpAdd(["Append",
        !           373:  "Append([<<f1>>,...,<<fn>>],<<g>>) returns the list [<<f1>>,...,<<fn>>,<<g>>]",
        !           374:  ["f1","fn","g"],
        !           375:  ["Join","NewArray","Rest"],
        !           376:  "append two lists or arrays."
        !           377: ]);
1.1       maekawa   378: HelpAdd(["Join",
1.9     ! takayama  379:  "Join([<<f1>>,...,<<fn>>],[<<g1>>,...,<<gm>>]) returns the list
        !           380:   [<<f1>>,...,<<fn>>,<<g1>>,...,<<gm>>]",
        !           381:   ["f1","fn","g1","gm"],
        !           382:   ["Append","NewArray","Rest"],
        !           383:   "join two lists or arrays"
        !           384: ]);
1.1       maekawa   385:
1.8       takayama  386: HelpAdd(["!ReservedNames",
1.1       maekawa   387:  ["The names k00*, K00*, sm1* , arg1,arg2,arg3,arg4,....," ,
                    388:   "Helplist, Arglist, FunctionValue,",
1.9     ! takayama  389:   "@@*, db.*, k.*, tmp002*, tmp00* are used for system functions.",
        !           390:   "Percent, LeftBracket, RightBracket, Dollar, Newline are constants"],
        !           391:   null,
        !           392:   null,
        !           393:   "reserved symbols."
        !           394: ]);
1.1       maekawa   395:
                    396: HelpAdd(["IntegerToSm1Integer",
1.9     ! takayama  397:  "IntegerToSm1Integer(<<i>>) translates integer <<i>>
        !           398:   to sm1 integer (integer <<i>>).",
        !           399:  ["i"],
        !           400:  null,
        !           401:  "translates integer to 32 bit integer (sm1 integer)"
        !           402: ]);
        !           403: HelpAdd(["true","true returns sm1 integer 1.",null,null," "]);
        !           404: HelpAdd(["false","false returns sm1 integer 0.",null,null," "]);
1.1       maekawa   405: HelpAdd(["IsArray",
1.9     ! takayama  406:  ["If <<f>> is an array (or list) object, then IsArray(<<f>>) returns true,",
        !           407:   "else IsArray(<<f>>) returns false."],
        !           408:  ["f"],
        !           409:  ["Is*","Tag"],
        !           410:  "check if an given object is an array."
        !           411: ]);
1.1       maekawa   412:
                    413: HelpAdd(["Init_w",
1.9     ! takayama  414:  ["Init_w(<<f>>,<<vars>>,<<w>>) returns the initial terms with respect to the",
1.1       maekawa   415:   "weight vector <<w>> (array of integer) of the polynomial <<f>>",
                    416:   "(polynomial).  Here, <<f>> is regarded as a polynomial with respect",
                    417:   "to the variables <<vars>> (array of polynomials).",
1.9     ! takayama  418:   "Ex. RingD(\"x,y\"); Init_w(x^2+y^2+x,[x,y],[1,1]):"],
        !           419:   ["f","vars","w"],
        !           420:   ["Gb","Init"],
        !           421:   "return the initial terms."
        !           422: ]);
1.1       maekawa   423:
                    424:
                    425: HelpAdd(["Groebner",
1.9     ! takayama  426:  ["Groebner(<<input>>) returns Groebner basis of the left ideal or the submodule",
1.1       maekawa   427:   "defined by <<input>> (array of polynomials)",
                    428:   "The order is that of the ring to which each element of <<input>>",
                    429:   "belongs.",
                    430:   "The input is automatically homogenized.",
1.9     ! takayama  431:   "Ex. RingD(\"x,y\",[[\"x\", 10, \"y\", 1]]);",
        !           432:   "          Groebner([Poly(\" x^2+y^2-4\"),Poly(\" x*y-1 \")]):",
        !           433:   "cf. RingD, Homogenize"],
        !           434:   ["input"],
        !           435:   ["Gb","Init_w","RingD","groebner (sm1)"],
        !           436:   "compute the Grobner basis."
        !           437: ]);
1.1       maekawa   438:
                    439:
                    440: HelpAdd(["RingPoly",
1.9     ! takayama  441:  ["RingPoly(<<names>>) defines a ring of polyomials (string <<names>>).",
1.1       maekawa   442:   "The names of variables of that ring are <<names>>  and ",
                    443:   "the homogenization variable h.",
                    444:   "cf. SetRingVariables, RingD",
1.9     ! takayama  445:   "Ex. R=RingPoly(\"x,y\");",
1.1       maekawa   446:   "  ",
1.9     ! takayama  447:   "RingPoly(<<names>>,<<weight_vector>>) defines a ring of polynomials",
        !           448:   "with the order defined by the <<weight_vector>>",
        !           449:   "(string <<names>>, array of array <<weight_vector>>).",
        !           450:   "RingPoly(<<names>>,<<weight_vector>>,<<characteristic>>)",
1.1       maekawa   451:   "Example: R=RingPoly(\"x,y\",[[\"x\",10,\"y\",1]]);",
1.9     ! takayama  452:   "         (x+y)^10: "],
        !           453:   ["names","weight_vector"],
        !           454:   ["GetRing","RingD","SetRing"],
        !           455:   "define a ring of polynomials."
        !           456: ]);
1.1       maekawa   457:
                    458:
                    459: HelpAdd(["CancelNumber",
1.9     ! takayama  460: ["CancelNumber(<<rn>>) reduces the rational number <<rn>>",
        !           461:  "(rational <<rn>>).",
        !           462:  "Ex. CancelNumber( 2/6 ) : "],
        !           463:  ["rn"],
        !           464:  ["Cancel"],
        !           465:  "factor out the greatest common divisor."
        !           466: ]);
1.1       maekawa   467:
                    468: HelpAdd(["IsString",
1.9     ! takayama  469: ["IsString(<<obj>>) returns true if << obj >> is a string (object <<obj>>).",
        !           470:  "Ex.  if (IsString(\"abc\")) Println(\"Hello\"); ;"],
        !           471:  ["obj"],
        !           472:  ["DC","Is*","Tag"],
        !           473:  "check if a given object is a string."
        !           474: ]);
1.1       maekawa   475:
1.6       takayama  476: HelpAdd(["IsRing",
1.9     ! takayama  477:  ["IsRing(<<obj>>) returns true if << obj >> is a ring (object <<obj>>)."
        !           478:  ],
        !           479:  ["obj"],
        !           480:  ["DC","Is*","Tag"],
        !           481:  "check if a given object is a ring."
        !           482: ]);
1.6       takayama  483:
1.1       maekawa   484:
                    485: HelpAdd(["IsSm1Integer",
1.9     ! takayama  486: ["IsSm1Integer(<<obj>>) returns true if << obj >> is an integer of sm1(object <<obj>>)."],
        !           487:  ["obj"],
        !           488:  ["DC","Is*","Tag"],
        !           489:  "check if a given object is a 32 bit integer."
        !           490: ]);
1.1       maekawa   491:
                    492: HelpAdd(["sm1",
1.9     ! takayama  493: ["sm1(<<arg1>>,<<arg2>>,...) is used to embed sm1 native code in the kxx program.",
        !           494:  "Ex. sm1( 2, 2, \" add print \"); ",
        !           495:  "Ex. def myadd(a,b) { sm1(\" a b add /FunctionValue set \"); }" ],
        !           496:  ["arg1","arg2"],
        !           497:  ["usage (sm1)"],
        !           498:  "execute sm1 commands"
        !           499: ]);
1.1       maekawa   500:
                    501: HelpAdd(["DC",
1.9     ! takayama  502: ["DC(<<obj>>,<<key>>) converts << obj >> to a new object in the primitive",
        !           503:  "class << key >> (object <<obj>>, string <<key>>)",
        !           504:  "Ex.  DC(\" (x+1)^10 \", \"polynomial\"): "],
        !           505:  ["obj","key"],
        !           506:  ["ToString"],
        !           507:  "translate data types."
        !           508: ]);
1.1       maekawa   509:
                    510: HelpAdd(["Length",
1.9     ! takayama  511: ["Length(<<vec>>) returns the length of the array << vec >>",
        !           512:  "(array <<vec>>)"],
        !           513:  ["vec"],
        !           514:  null,
        !           515:  "length of a given array or a list."
        !           516: ]);
1.1       maekawa   517:
                    518: HelpAdd(["Transpose",
1.9     ! takayama  519:  ["Transpose(<<m>.) return the transpose of the matrix << m >>",
        !           520:   "(array of array <<m>>)."],
        !           521:  ["m"],
        !           522:  ["NewMatrix"],
        !           523:  "transposition"
        !           524: ]);
1.1       maekawa   525:
                    526: HelpAdd(["Save",
1.9     ! takayama  527:  ["Save(<<obj>>) appends << obj >> to the file sm1out.txt (object <<obj>>)."],
        !           528:  ["obj"],
        !           529:  null,
        !           530:  "write a given object to a file."
        !           531: ]);
1.1       maekawa   532:
                    533: HelpAdd(["Coefficients",
1.9     ! takayama  534: ["Coefficients(<<f>>,<<v>>) returns [exponents, coefficients] of << f >>",
1.1       maekawa   535:  "with respect to the variable << v >>",
1.9     ! takayama  536:  "(polynomial <<f>>,<<v>>).",
        !           537:  "Ex.  Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "],
        !           538:  ["f","v"],
        !           539:  ["Exponent","Init","Init_w"],
        !           540:  "get the exponents and coefficients."
        !           541: ]);
1.1       maekawa   542:
                    543: HelpAdd(["System",
1.9     ! takayama  544: ["System(<<comm>>) executes the unix system command << comm >>",
        !           545:  "(string <<comm>>)",
        !           546:  "Ex. System(\"ls\");"],
        !           547:  ["comm"],
        !           548:  null,
        !           549:  "call the unix shell."
        !           550: ]);
1.1       maekawa   551:
                    552: HelpAdd(["Exponent",
1.9     ! takayama  553:  ["Expoent(<<f>>,<<vars>>) returns the vector of exponents of the polynomial <<f>>",
        !           554:   "Ex. Exponent( x^2*y-1,[x,y])"],
        !           555:  ["f","vars"],
        !           556:  ["Coefficients"],
        !           557:  "exponents of a given polynomial."
        !           558: ]);
1.1       maekawa   559:
                    560: HelpAdd(["Protect",
1.9     ! takayama  561:  ["Protect(<<name>>) protects the symbol <<name>> (string)",
        !           562:   "Protect(<<name>>,<<level>>) protects the symbol <<name>> (string) with ",
        !           563:   "<<level>> "],
        !           564:  ["name","level"],
        !           565:  ["extension (sm1)"],
        !           566:  "add read-only property for a given variable."
        !           567: ]);
1.1       maekawa   568:
                    569: HelpAdd(["IsPolynomial",
1.9     ! takayama  570:  ["IsPolynomial(<<f>>) returns true if <<f>> (object) is a polynomial."],
        !           571:  ["obj"],
        !           572:  ["DC","Is*","Tag"],
        !           573:  "check if a given object is a polynomial."
        !           574: ]);
1.1       maekawa   575:
                    576:
                    577:
                    578: /* -----------------------------------------------
                    579:    functions on tests.    */
                    580: /* ------------  Developping functions  --------------------- */
                    581:
                    582: def RingPoly(vList,weightMatrix,pp) {
                    583:   local new0,tmp,size,n,i,j,newtmp,ringpp,argsize;
                    584:   argsize = Length(Arglist);
                    585:   if (argsize == 1) {
                    586:     sm1("[", vList,
                    587:         "ring_of_polynomials ( ) elimination_order 0 ] define_ring
                    588:          /tmp set ");
1.3       takayama  589:     SetRingVariables();
1.1       maekawa   590:     return(tmp);
                    591:   } else ;
                    592:   if (argsize == 2) {
                    593:     pp = 0;
                    594:   }
                    595:   pp = IntegerToSm1Integer(pp);
                    596:   size = Length(weightMatrix);
                    597:   new0 = NewVector(size);
                    598:   sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def ");
                    599:   sm1(" 0 @@@.indexMode ");
                    600:   for (i=0; i<size; i++) {
                    601:     tmp = weightMatrix[i];
                    602:     n = Length(tmp);
                    603:     newtmp = NewVector(n);
                    604:     for (j=1; j<n; j = j+2) {
                    605:        newtmp[j-1] = tmp[j-1];
                    606:        newtmp[j] = IntegerToSm1Integer( tmp[j] );
                    607:     }
                    608:     new0[i] = newtmp;
                    609:   }
1.3       takayama  610:   SetRingVariables();
1.1       maekawa   611:   ringpp =
                    612:   sm1("[", vList,
                    613:       "ring_of_polynomials ", new0, " weight_vector", pp, " ] define_ring");
                    614:   sm1(" @@@.indexMode.flag.save @@@.indexMode ");
                    615:   return( ringpp );
                    616: }
                    617:
                    618: def IsString(ob) {
                    619:   sm1(ob , " isString /FunctionValue set ");
                    620: }
                    621:
                    622: def IsSm1Integer(ob) {
                    623:   sm1(ob , " isInteger /FunctionValue set ");
1.6       takayama  624: }
                    625:
                    626: def IsRing(ob) {
                    627:   sm1(ob , " isRing /FunctionValue set ");
1.1       maekawa   628: }
                    629:
                    630:
                    631: def CancelNumber(rn) {
                    632:   local tmp;
                    633:   sm1(" [(cancel) ",rn," ] mpzext /tmp set ");
                    634:   if (IsInteger(tmp)) return(tmp);
                    635:   sm1(" tmp (denominator) dc (1).. eq { /FunctionValue tmp (numerator) dc def} { /FunctionValue tmp def } ifelse ");
                    636: }
                    637:
1.5       takayama  638: def DC_polynomial(obj) {
                    639:   return(DC(obj,"polynomial"));
                    640: }
1.1       maekawa   641: def DC(obj,key) {
1.5       takayama  642:   if (IsArray(obj) && key=="polynomial") {
                    643:     return(Map(obj,"DC_polynomial"));
                    644:   }
1.1       maekawa   645:   if (key == "string") { return(ToString(obj)); }
                    646:   else if (key == "integer") { key = "universalNumber"; }
                    647:   else if (key == "sm1integer") { key = "integer"; }
                    648:   else if (key == "polynomial") { key = "poly"; }
                    649:   else ;
                    650:   sm1( obj , key, " data_conversion /FunctionValue set ");
                    651: }
                    652:
                    653: def Transpose(m) {
                    654:   sm1(m, " transpose /FunctionValue set ");
                    655: }
                    656:
                    657: def Save(obj) {
                    658:   sm1(obj, " output ");
                    659: }
                    660:
                    661:
                    662: def void System(comm) {
                    663:   sm1(comm, " system ");
                    664: }
                    665:
                    666:
                    667: def IsReducible(f,g) {
                    668:   sm1("[ (isReducible) ",f,g," ] gbext /FunctionValue set ");
                    669: }
                    670:
                    671: def IsPolynomial(f) {
                    672:   sm1(" f isPolynomial /FunctionValue set ");
                    673: }
                    674: sm1(" /k00.toric0.mydegree {2 1 roll degree} def ");
                    675: def Exponent(f,vars) {
                    676:   local n,i,ans;
                    677:   if (f == Poly("0")) return([ ] );
                    678:   sm1(f," /ff.tmp set ", vars ,
                    679:       " {ff.tmp k00.toric0.mydegree (universalNumber) dc }map /FunctionValue set ");
                    680: }
                    681: def void Protect(name,level) {
                    682:   local n,str;
                    683:   n = Length(Arglist);
                    684:   if (n == 1) {
                    685:     level = 1;
                    686:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
                    687:                      " ] extension pop "]);
                    688:     /* Println(str); */
                    689:     sm1(" [(parse) ",str ," ] extension pop ");
                    690:   } else if (n ==2) {
                    691:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
                    692:                      " ] extension pop "]);
                    693:     /* Println(str); */
                    694:     sm1(" [(parse) ",str ," ] extension pop ");
                    695:   } else {
                    696:      k00_error("Protect","Arguments must be one or two. ");sm1(" error ");
                    697:   }
                    698: }
                    699:
                    700: def void k00_error(name,msg) {
                    701:   Print("Error in "); Print(name); Print(". ");
                    702:   Println(msg);
                    703: }
                    704:
                    705: def Init(f) {
                    706:   if (IsArray(f)) {
                    707:      return(Map(f,"Init"));
                    708:   } else if (IsPolynomial(f)) {
                    709:      sm1(f,"  init  /FunctionValue set ");
                    710:   } else {
                    711:      k00_error("Init","Argment must be polynomial or an array of polynomials");
                    712:      sm1(" error ");
                    713:   }
                    714: }
                    715: HelpAdd(["Init",
1.9     ! takayama  716:  ["Init(<<f>>) returns the initial term of the polynomial <<f>> (polynomial)",
        !           717:   "Init(<<list>>) returns the array of initial terms of the array of polynomials",
        !           718:   "<< list >> (array)"],
        !           719:   ["f"],
        !           720:   ["Init_w"],
        !           721:   "return the initial term."
        !           722: ]);
1.1       maekawa   723:
                    724: HelpAdd(["NewMatrix",
1.9     ! takayama  725:  ["NewMatrix(<<m>>,<<n>>) returns the (<<m>>,<<n>>)-matrix (array) with the entries 0."],
        !           726:  ["m","n"],
        !           727:  ["NewArray"],
        !           728:  "generate a matrix of a given size."
        !           729: ]);
1.1       maekawa   730:
                    731: def Eliminatev(list,var)  /* [(x-y). (y-z).] [(z) ] */
                    732: {
                    733:    sm1(list, var, " eliminatev /FunctionValue set ");
                    734: }
                    735: HelpAdd(["Eliminatev",
1.9     ! takayama  736: ["Eliminatev(<<list>>,<<var>>) prunes polynomials in << list >>(array of polynomials)",
1.1       maekawa   737:  "which contains the variables in << var >> ( array of strings )",
1.9     ! takayama  738:  "Ex. Eliminatev([Poly(\" x+h \"),Poly(\" x \")],[ \"h\" ]): "],
        !           739:  ["list","var"],
        !           740:  ["eliminatev (sm1)"],
        !           741:  "  "
        !           742: ]);
1.1       maekawa   743:
                    744: def ReducedBase(base) {
                    745:   sm1( base, " reducedBase /FunctionValue set ");
                    746: }
                    747: HelpAdd(["ReducedBase",
1.9     ! takayama  748:  ["ReducedBase(<<base>>) prunes redundant elements in the Grobner basis <<base>> (array)."
        !           749: ],
        !           750:  ["base"],
        !           751:  ["Gb","Groebner"],
        !           752:  "remove unnecessary elements."
        !           753: ]);
1.1       maekawa   754:
                    755:
                    756: def Coefficients(f,v) {
                    757:   local ans,exp;
                    758:   ans = sm1(f,v, " coefficients ");
                    759:   exp = ans[0];
                    760:   exp = sm1(exp," { (universalNumber) dc } map ");
                    761:   return([exp,ans[1]]);
                    762: }
                    763:
                    764: def IsInteger(a) {
                    765:   sm1(a , " isUniversalNumber /FunctionValue set ");
                    766: }
                    767: HelpAdd(["IsInteger",
1.9     ! takayama  768: ["IsInteger(<<a>>) returns true if << a >> is an integer (object <<a>>).",
1.1       maekawa   769:  "It returns false if << a >> is not.",
1.9     ! takayama  770:  "cf. IsSm1Integer"],
        !           771:  ["a"],
        !           772:  ["DC","Is*","Tag"],
        !           773:  "check if a given object is an integer."
        !           774: ]);
1.1       maekawa   775:
                    776: def IsRational(a) {
                    777:   sm1(a , " isRational /FunctionValue set ");
                    778: }
                    779: HelpAdd(["IsRational",
1.9     ! takayama  780: ["IsRational(<<a>>) returns true if << a >> is a rational (object <<a>>).",
        !           781:  "It returns false if << a >> is not."],
        !           782:  ["a"],
        !           783:  ["DC","Is*","Tag"],
        !           784:  "check if a given object is a rational."
        !           785: ]);
1.1       maekawa   786:
                    787:
                    788: def IsDouble(a) {
                    789:   sm1(a , " isDouble /FunctionValue set ");
                    790: }
                    791: HelpAdd(["IsDouble",
1.9     ! takayama  792: ["IsDouble(<<a>>) returns true if << a >> is a double (object <<a>>).",
        !           793:  "It returns false if << a >> is not."],
        !           794:  ["a"],
        !           795:  ["DC","Is*","Tag"],
        !           796:  "check if a given object is double."
        !           797: ]);
1.1       maekawa   798:
                    799:
                    800: sm1(" /cs { this  [ ] Cleards  } def ");
                    801:
                    802:
                    803: def Init_w(f,vars,weight) {
                    804:   local w,w2,w3,ans,i,n;
                    805:   if (f == Poly("0")) return( Poly("0") );
                    806:   w = Map(vars,"ToString");
                    807:   w2 = sm1(weight," {$integer$ data_conversion} map ");
                    808:   n = Length(w);
                    809:   w3 = NewArray(n*2);
                    810:   for (i=0; i<n ; i++) {
                    811:     w3[2*i] = w[i]; w3[2*i+1] = w2[i];
                    812:   }
                    813:   ans = sm1(f,w3, " weightv init ");
                    814:   return(ans);
                    815: }
                    816:
                    817: HelpAdd(["Mapto",
1.9     ! takayama  818:  ["Mapto(<<obj>>,<<ring>>) parses << obj >> as elements of the << ring >>.",
1.1       maekawa   819:   "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).",
                    820:   "Ex. R = RingD(\"x,y\"); SetRingVariables();",
                    821:   "    f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ",
1.9     ! takayama  822:   "    f2 = Mapto(f,R2); f2: "],
        !           823:   ["obj","ring"],
        !           824:   ["ReParse"],
        !           825:   "parse a polynomial in a given ring."
        !           826: ]);
1.1       maekawa   827:
                    828: def Mapto(obj,ring) {
                    829:    local ans,i,n;
                    830:    if (IsArray(obj)) {
                    831:       n = Length(obj);
                    832:       ans = Map(obj,"ToString");
                    833:       for (i=0; i<n; i++) {
                    834:          ans[i] = PolyR(ans[i],ring);
                    835:       }
                    836:    }else{
                    837:       ans = ToString(obj);
                    838:       ans = PolyR(ans,ring);
                    839:    }
                    840:    return(ans);
                    841: }
                    842:
                    843:
                    844: HelpAdd(["ToDouble",
1.9     ! takayama  845:  ["ToDouble(<<f>>) translates << f >> into double when it is possible",
1.1       maekawa   846:   "object << f >>.",
1.9     ! takayama  847:   "Ex. ToDouble([1,1/2,[5]]): "],
        !           848:  ["f"],
        !           849:  ["DC","Is*","Tag"],
        !           850:  "translate a given object to double."
        !           851: ]);
1.1       maekawa   852: def k00_toDouble(f) {   return(DC(f,"double")); }
                    853: def ToDouble(f) {
                    854:   if (IsArray(f)) return(Map(f,"ToDouble"));
                    855:   if (IsDouble(f)) return(f);
                    856:   return(k00_toDouble(f));
                    857: }
                    858:
                    859:
                    860:
                    861: def Mod(f,n) {
                    862:    if (IsPolynomial(f)) {
                    863:      sm1("[(mod) ",f,n,"] gbext  /FunctionValue set ");
                    864:    } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); }
                    865: }
                    866: HelpAdd(["Mod",
1.9     ! takayama  867:  ["Mod(<<f>>,<<p>>) returns f modulo <<n>>  where << f >> (polynomial) and",
        !           868:   " << p >> (integer). "],
        !           869:  ["f","p"],
        !           870:  ["gbext (sm1)"],
        !           871:  "modulo"
        !           872: ]);
1.1       maekawa   873:
                    874:
                    875:
                    876:
                    877: def Characteristic(ringp) {
                    878:   local r,p;
                    879:   r = sm1(" [(CurrentRingp)] system_variable ");
                    880:   sm1("[(CurrentRingp) ",ringp, " ] system_variable ");
                    881:   p = sm1("[(P)] system_variable (universalNumber) dc ");
                    882:   sm1("[(CurrentRingp) ",r, " ] system_variable ");
                    883:   return(p);
                    884: }
                    885: HelpAdd(["Characteristic",
1.9     ! takayama  886:  ["Characteristic(<<ring>>) returns the characteristic of the << ring >>."],
        !           887:  ["ring"],
        !           888:  ["GetRing","RingD","RingPoly","SetRing"],
        !           889:  "get the characteristic of a given ring."
        !           890: ]);
1.1       maekawa   891:
                    892: def IsConstant(f) {
                    893:   if (Length(f) > 1) return(false);
                    894:   sm1("[(isConstant) ", f," ] gbext /FunctionValue set ");
                    895: }
                    896: HelpAdd(["IsConstant",
1.9     ! takayama  897: ["IsConstant(<<f>>) returns true if the polynomial << f >> is a constant."
        !           898: ],
        !           899:  ["f"],
        !           900:  ["DC","Is*","Tag"],
        !           901:  "check if a given object is a constant."
        !           902: ]);
1.1       maekawa   903:
                    904: Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h");
                    905:
                    906: def Substitute(f,xx,g) {
1.7       takayama  907:   local tmp, coeff0,ex,i,n,newex,ans;
1.1       maekawa   908:   if (IsInteger(f)) return(f);
1.7       takayama  909:   if (IsArray(f)) {
                    910:      n = Length(f);
                    911:      ans = NewVector(n);
                    912:      for (i=0; i<n; i++) {
                    913:        ans[i] = Substitute(f[i],xx,g);
                    914:      }
                    915:      return(ans);
                    916:   }
1.1       maekawa   917:   if (! IsPolynomial(f)) {
                    918:     k00_error("Substitute","The first argument must be polynomial.");
                    919:   }
                    920:   tmp = Coefficients(f,xx);
                    921:   coeff0 = tmp[1];
                    922:   ex = tmp[0];   /* [3, 2, 0] */
                    923:   n = Length(ex);
                    924:   newex = NewVector(n);
                    925:   if (n>0) { newex[n-1] = g^ex[n-1]; }
                    926:   for (i=n-2; i>=0; i--) {
                    927:     newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1]));
                    928:   }
                    929:   return(Cancel(coeff0*newex));
                    930: }
                    931: HelpAdd(["Substitute",
1.9     ! takayama  932: ["Substitute(<<f>>,<<xx>>,<<g>>) replaces << xx >> in << f >> by << g >>.",
1.1       maekawa   933:   "This function takes coeffients of << f >> with respect to << xx >>",
                    934:   "and returns the inner product of the vector of coefficients and the vector",
                    935:   "of which elements are g^(corresponding exponent).",
                    936:   "Note that it may cause an unexpected result in non-commutative rings."
1.9     ! takayama  937: ],
        !           938:  ["f","xx","g"],
        !           939:  ["Replace"],
        !           940:  "  "
        !           941: ]);
        !           942:
        !           943:
        !           944: HelpAdd(["OutputPrompt",
        !           945:  ["Output the prompt. Files should end with this command."],
        !           946:  null,
        !           947:  null,
        !           948:  "output the prompt."]);
        !           949:
        !           950: Protect("Percent");
        !           951: Protect("LeftBracket");
        !           952: Protect("RightBracket");
        !           953: Protect("Dollar");
        !           954: Protect("Newline");
1.1       maekawa   955:
                    956: OutputPrompt ;

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