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

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

1.1     ! maekawa     1:
        !             2: if (K00_verbose)
        !             3:   Println("help.k (help.ccc).  8/6, 1996 --- 8/7, 1996. 3/6, 1997 --- 12/21, 1997.");
        !             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++) {
        !            26:     item = Helplist[i];
        !            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++ ) {
        !            51:     keys = Append(keys,Helplist[i,0]);
        !            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).");
        !            95:
        !            96:   /* Println(keys); */
        !            97: }
        !            98:
        !            99: def ShowKeyWordsOfSm1(ss) {
        !           100:   local i,j,n,keys,max,width,m,k,kk,tmp0;
        !           101:   Ln();
        !           102:   sm1(" /help_Sm1Macro @.usages def ");
        !           103:   n = Length(help_Sm1Macro);
        !           104:   keys = [" " ];
        !           105:   for (i=0; i< n; i++ ) {
        !           106:     keys = Append(keys,help_Sm1Macro[i,0]);
        !           107:   }
        !           108:   keys = sm1(keys," shell ");
        !           109:   n = Length(keys);
        !           110:   if (ss == "ALL") {
        !           111:     for (i=1; i<n; i++) {
        !           112:       tmp0 = keys[i];
        !           113:       Print("# "); Print(tmp0); Ln();
        !           114:       sm1(tmp0," usage "); Ln();
        !           115:     }
        !           116:     return(0);
        !           117:   }
        !           118:
        !           119:   max = 0;
        !           120:   for (i=1; i<n; i++) {
        !           121:      if (Length(keys[i]) > max) {
        !           122:         max = Length(keys[i]);
        !           123:      }
        !           124:   }
        !           125:   /* Println(max); */
        !           126:   max = max+3;
        !           127:   width = 80;
        !           128:   m = 0;
        !           129:   while ((m*max) < 80) {
        !           130:      m = m+1;
        !           131:   }
        !           132:   k = 0; kk = 0;
        !           133:   for (i=1; i<n; i++) {
        !           134:     Print(keys[i]); kk = kk+1;
        !           135:     k = k+Length(keys[i]);
        !           136:     tmp0 = max-Length(keys[i]);
        !           137:     if (kk >= m) {
        !           138:     }else {
        !           139:       for (j=0; j < tmp0 ; j++) {
        !           140:          k = k+1;
        !           141:          Print(" ");
        !           142:       }
        !           143:     }
        !           144:     if (kk >= m) {
        !           145:       kk = 0; k=0; Ln();
        !           146:     }
        !           147:   }
        !           148:   Ln();
        !           149:   Ln();
        !           150:   Println("Type in (keyword) usage ;  to see a help message.");
        !           151:
        !           152:   /* Println(keys); */
        !           153: }
        !           154:
        !           155: HelpAdd(["Help", "Help(key) shows an explanation on the key (string key)."]);
        !           156: HelpAdd(["HelpAdd",
        !           157:  ["HelpAdd([key,explanation]) (string key, string explanation)",
        !           158:   " or (string key, array explanation)."]]);
        !           159: HelpAdd(["load",
        !           160:  ["load(fname) loads the file << fname >>(string fname).",
        !           161:   "load fname  loads the file << fname >>.",
        !           162:   "load[fname] loads the file << fname >> with the preprocessing by /lib/cpp."
        !           163: ]]);
        !           164: HelpAdd(["Ln","Ln() newline."]);
        !           165: HelpAdd(["Println","Println(f) prints f and goes to the new line."]);
        !           166: HelpAdd(["Print","Print(f) prints f."]);
        !           167: HelpAdd(["Poly",
        !           168:  "Poly(name) returns the polynomial name in the current ring
        !           169:   (string name)."]);
        !           170: HelpAdd(["PolyR",
        !           171:  "PolyR(name,r) returns the polynomial name in the ring r
        !           172:  (string name, ring r).
        !           173:  Ex. r = RingD(\"x,y\"); y = PolyR(\"y\",r); "]);
        !           174: HelpAdd(["RingD",
        !           175:  ["RingD(names) defines a new ring (string names).",
        !           176:   "RingD(names,weight_vector) defines a new ring with the weight vector",
        !           177:   "(string names, array weight_vector).",
        !           178:   "RingD(names,weight_vector,characteristic)",
        !           179:   " Ex. RingD(\"x,y\",[[\"x\",2,\"y\",1]]) "]]);
        !           180: HelpAdd(["Reduction","Reduction(f,G) returns the remainder and sygygies when
        !           181: f is devided by G (polynomial f, array G)."]);
        !           182: HelpAdd(["AddString","AddString(list) returns the concatnated string (array list)."]);
        !           183: HelpAdd(["AsciiToString","AsciiToString(ascii_code) returns the string of which
        !           184: ascii code is ascii_code (integer ascii_code)."]);
        !           185: HelpAdd(["ToString","ToString(obj) transforms the <<obj>> to a string."]);
        !           186: HelpAdd(["Numerator","Numerator(f) returns the numerator of <<f>> (rational f)."]);
        !           187: HelpAdd(["Denominator","Denominator(f) returns the denominator of <<f>> (rational f)."]);
        !           188: HelpAdd(["Replace","Replace(f,rule) (polynomial f, array rule).
        !           189:            Ex. Replace( (x+y)^3, [[x,Poly(\"1\")]])"]);
        !           190: HelpAdd(["SetRingVariables",
        !           191:  "SetRingVariables()
        !           192:   Set the generators of the current ring as global variables.
        !           193:   cf. RingD(), Poly(), PolyR()"]);
        !           194: HelpAdd(["Append","Append([f1,...,fn],g) returns the list [f1,...,fn,g]"]);
        !           195: HelpAdd(["Join",
        !           196:  "Join([f1,...,fn],[g1,...,gm]) returns the list
        !           197:   [f1,...,fn,g1,...,gm]"]);
        !           198: HelpAdd(["Indexed",
        !           199:  "Indexed(name,i) returns the string name[i]
        !           200:   (string name, integer i)"]);
        !           201:
        !           202: HelpAdd(["-ReservedName1",
        !           203:  ["The names k00*, K00*, sm1* , arg1,arg2,arg3,arg4,....," ,
        !           204:   "Helplist, Arglist, FunctionValue,",
        !           205:   "@@@*, db.*, k.*, tmp002*, tmp00* are used for system functions."]]);
        !           206:
        !           207: HelpAdd(["IntegerToSm1Integer",
        !           208:  "IntegerToSm1Integer(i) translates integer i
        !           209:   to sm1.integer (integer i)."]);
        !           210: HelpAdd(["true","true returns sm1.integer 1."]);
        !           211: HelpAdd(["false","false returns sm1.integer 0."]);
        !           212: HelpAdd(["IsArray",
        !           213:  ["If f is the array object, then IsArray(f) returns true,",
        !           214:   "else IsArray(f) returns false."]]);
        !           215:
        !           216:
        !           217:
        !           218: HelpAdd(["Init_w",
        !           219:  ["Init_w(f,vars,w) returns the initial terms with respect to the",
        !           220:   "weight vector <<w>> (array of integer) of the polynomial <<f>>",
        !           221:   "(polynomial).  Here, <<f>> is regarded as a polynomial with respect",
        !           222:   "to the variables <<vars>> (array of polynomials).",
        !           223:   "Example: Init_w(x^2+y^2+x,[x,y],[1,1]):"]]);
        !           224:
        !           225: HelpAdd(["RingDonIndexedVariables",
        !           226:  ["RingDonIndexedVariables(name,n) defines and returns the ring of",
        !           227:   "homogenized differential operators",
        !           228:   "Q<h, name[0], ..., name[n-1], Dname[0], ..., Dname[n-1]>",
        !           229:   "where <<name>> is a string and <<n>> is an integer.",
        !           230:   "Note that this function defines global variables",
        !           231:   "h, name[0], ..., name[n-1], Dname[0], ..., Dname[n-1].",
        !           232:   "Example: RingDonIndexedVariables(\"x\",3).",
        !           233:   "RingDonIndexedVariables(name,n,w) defines and returns the ring of",
        !           234:   "homogenized differential operators with the ordering defined by ",
        !           235:   "the weight vector <<w>> (array)",
        !           236:   "Example: RingDonIndexedVariables(\"x\",3,[[\"x[0]\",1,\"x[2]\",3]])."]]);
        !           237:
        !           238: HelpAdd(["Groebner",
        !           239:  ["Groebner(input) returns Groebner basis of the left module (or ideal)",
        !           240:   "defined by <<input>> (array of polynomials)",
        !           241:   "The order is that of the ring to which each element of <<input>>",
        !           242:   "belongs.",
        !           243:   "The input is automatically homogenized.",
        !           244:   "Example: RingD(\"x,y\",[[\"x\", 10, \"y\", 1]]);",
        !           245:   "         Groebner([Poly(\" x^2+y^2-4\"),Poly(\" x*y-1 \")]):",
        !           246:   "cf. RingD, Homogenize"]]);
        !           247:
        !           248:
        !           249: HelpAdd(["RingPoly",
        !           250:  ["RingPoly(names) defines a Ring of Polyomials (string names).",
        !           251:   "The names of variables of that ring are <<names>>  and ",
        !           252:   "the homogenization variable h.",
        !           253:   "cf. SetRingVariables, RingD",
        !           254:   "Example: R=RingPoly(\"x,y\");",
        !           255:   "  ",
        !           256:   "RingPoly(names,weight_vector) defines a Ring of Polynomials",
        !           257:   "with the order defined by the << weight_vector >>",
        !           258:   "(string names, array of array weight_vector).",
        !           259:   "RingPoly(names,weight_vector,characteristic)",
        !           260:   "Example: R=RingPoly(\"x,y\",[[\"x\",10,\"y\",1]]);",
        !           261:   "         (x+y)^10: "]]);
        !           262:
        !           263:
        !           264: HelpAdd(["CancelNumber",
        !           265: ["CancelNumber(rn) reduces the rational number <<rn>>",
        !           266:  "(rational rn).",
        !           267:  "Example: CancelNumber( 2/6 ) : "]]);
        !           268:
        !           269: HelpAdd(["IsString",
        !           270: ["IsString(obj) returns true if << obj >> is a string (object obj).",
        !           271:  "Example:  if (IsString(\"abc\")) Println(\"Hello\"); ;"]]);
        !           272:
        !           273:
        !           274: HelpAdd(["IsSm1Integer",
        !           275: ["IsSm1Integer(obj) returns true if << obj >> is an integer of sm1(object obj)."]]);
        !           276:
        !           277: HelpAdd(["sm1",
        !           278: ["sm1(arg1,arg2,...) is used to embed sm1 native code in the kxx program.",
        !           279:  "Example: sm1( 2, 2, \" add print \"); ",
        !           280:  "Example: def myadd(a,b) { sm1(a,b,\" add /FunctionValue set \"); }" ]]);
        !           281:
        !           282: HelpAdd(["DC",
        !           283: ["DC(obj,key) converts << obj >> to a new object in the primitive",
        !           284:  "class << key >> (object obj, string key)",
        !           285:  "Example:  DC(\" (x+1)^10 \", \"polynomial\"): "]]);
        !           286:
        !           287: HelpAdd(["Length",
        !           288: ["Length(vec) returns the length of the array << vec >>",
        !           289:  "(array vec)"]]);
        !           290:
        !           291: HelpAdd(["Transpose",
        !           292: ["Transpose(m) return the transpose of the matrix << m >>",
        !           293:  "(array of array m)."]]);
        !           294:
        !           295: HelpAdd(["Save",
        !           296: ["Save(obj) appends << obj >> to the file sm1out.txt (object obj)."]]);
        !           297:
        !           298: HelpAdd(["Coefficients",
        !           299: ["Coefficients(f,v) returns [exponents, coefficients] of << f >>",
        !           300:  "with respect to the variable << v >>",
        !           301:  "(polynomial f,v).",
        !           302:  "Example: Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "]]);
        !           303:
        !           304: HelpAdd(["System",
        !           305: ["System(comm) executes the unix system command << comm >>",
        !           306:  "(string comm)",
        !           307:  "Example: System(\"ls\");"]]);
        !           308:
        !           309: HelpAdd(["Exponent",
        !           310:  ["Expoent(f,vars) returns the vector of exponents of the polynomial f",
        !           311:   "Ex. Exponent( x^2*y-1,[x,y])"]]);
        !           312:
        !           313: HelpAdd(["Protect",
        !           314:  ["Protect(name) protects the symbol <<name>> (string)",
        !           315:   "Protect(name,level) protects the symbol <<name>> (string) with ",
        !           316:   "<<level>> "]]);
        !           317:
        !           318: HelpAdd(["IsPolynomial",
        !           319:  ["IsPolynomial(f) returns true if <<f>> (object) is a polynomial."]]);
        !           320:
        !           321:
        !           322:
        !           323: /* -----------------------------------------------
        !           324:    functions on tests.    */
        !           325: /* ------------  Developping functions  --------------------- */
        !           326:
        !           327: def RingPoly(vList,weightMatrix,pp) {
        !           328:   local new0,tmp,size,n,i,j,newtmp,ringpp,argsize;
        !           329:   argsize = Length(Arglist);
        !           330:   if (argsize == 1) {
        !           331:     sm1("[", vList,
        !           332:         "ring_of_polynomials ( ) elimination_order 0 ] define_ring
        !           333:          /tmp set ");
        !           334:     return(tmp);
        !           335:   } else ;
        !           336:   if (argsize == 2) {
        !           337:     pp = 0;
        !           338:   }
        !           339:   pp = IntegerToSm1Integer(pp);
        !           340:   size = Length(weightMatrix);
        !           341:   new0 = NewVector(size);
        !           342:   sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def ");
        !           343:   sm1(" 0 @@@.indexMode ");
        !           344:   for (i=0; i<size; i++) {
        !           345:     tmp = weightMatrix[i];
        !           346:     n = Length(tmp);
        !           347:     newtmp = NewVector(n);
        !           348:     for (j=1; j<n; j = j+2) {
        !           349:        newtmp[j-1] = tmp[j-1];
        !           350:        newtmp[j] = IntegerToSm1Integer( tmp[j] );
        !           351:     }
        !           352:     new0[i] = newtmp;
        !           353:   }
        !           354:   ringpp =
        !           355:   sm1("[", vList,
        !           356:       "ring_of_polynomials ", new0, " weight_vector", pp, " ] define_ring");
        !           357:   sm1(" @@@.indexMode.flag.save @@@.indexMode ");
        !           358:   return( ringpp );
        !           359: }
        !           360:
        !           361: def IsString(ob) {
        !           362:   sm1(ob , " isString /FunctionValue set ");
        !           363: }
        !           364:
        !           365: def IsSm1Integer(ob) {
        !           366:   sm1(ob , " isInteger /FunctionValue set ");
        !           367: }
        !           368:
        !           369:
        !           370: def CancelNumber(rn) {
        !           371:   local tmp;
        !           372:   sm1(" [(cancel) ",rn," ] mpzext /tmp set ");
        !           373:   if (IsInteger(tmp)) return(tmp);
        !           374:   sm1(" tmp (denominator) dc (1).. eq { /FunctionValue tmp (numerator) dc def} { /FunctionValue tmp def } ifelse ");
        !           375: }
        !           376:
        !           377: def DC(obj,key) {
        !           378:   if (key == "string") { return(ToString(obj)); }
        !           379:   else if (key == "integer") { key = "universalNumber"; }
        !           380:   else if (key == "sm1integer") { key = "integer"; }
        !           381:   else if (key == "polynomial") { key = "poly"; }
        !           382:   else ;
        !           383:   sm1( obj , key, " data_conversion /FunctionValue set ");
        !           384: }
        !           385:
        !           386: def Transpose(m) {
        !           387:   sm1(m, " transpose /FunctionValue set ");
        !           388: }
        !           389:
        !           390: def Save(obj) {
        !           391:   sm1(obj, " output ");
        !           392: }
        !           393:
        !           394:
        !           395: def void System(comm) {
        !           396:   sm1(comm, " system ");
        !           397: }
        !           398:
        !           399:
        !           400: def IsReducible(f,g) {
        !           401:   sm1("[ (isReducible) ",f,g," ] gbext /FunctionValue set ");
        !           402: }
        !           403:
        !           404: def IsPolynomial(f) {
        !           405:   sm1(" f isPolynomial /FunctionValue set ");
        !           406: }
        !           407: sm1(" /k00.toric0.mydegree {2 1 roll degree} def ");
        !           408: def Exponent(f,vars) {
        !           409:   local n,i,ans;
        !           410:   if (f == Poly("0")) return([ ] );
        !           411:   sm1(f," /ff.tmp set ", vars ,
        !           412:       " {ff.tmp k00.toric0.mydegree (universalNumber) dc }map /FunctionValue set ");
        !           413: }
        !           414: def void Protect(name,level) {
        !           415:   local n,str;
        !           416:   n = Length(Arglist);
        !           417:   if (n == 1) {
        !           418:     level = 1;
        !           419:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
        !           420:                      " ] extension pop "]);
        !           421:     /* Println(str); */
        !           422:     sm1(" [(parse) ",str ," ] extension pop ");
        !           423:   } else if (n ==2) {
        !           424:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
        !           425:                      " ] extension pop "]);
        !           426:     /* Println(str); */
        !           427:     sm1(" [(parse) ",str ," ] extension pop ");
        !           428:   } else {
        !           429:      k00_error("Protect","Arguments must be one or two. ");sm1(" error ");
        !           430:   }
        !           431: }
        !           432:
        !           433: def void k00_error(name,msg) {
        !           434:   Print("Error in "); Print(name); Print(". ");
        !           435:   Println(msg);
        !           436: }
        !           437:
        !           438: def Init(f) {
        !           439:   if (IsArray(f)) {
        !           440:      return(Map(f,"Init"));
        !           441:   } else if (IsPolynomial(f)) {
        !           442:      sm1(f,"  init  /FunctionValue set ");
        !           443:   } else {
        !           444:      k00_error("Init","Argment must be polynomial or an array of polynomials");
        !           445:      sm1(" error ");
        !           446:   }
        !           447: }
        !           448: HelpAdd(["Init",
        !           449:  ["Init(f) returns the initial term of the polynomial <<f>> (polynomial)",
        !           450:   "Init(list) returns the array of initial terms of the array of polynomials",
        !           451:   "<< list >> (array)"]]);
        !           452:
        !           453: HelpAdd(["NewMatrix",
        !           454:  ["NewMatrix(m,n) returns the (m,n)-matrix (array) with the entries 0."]]);
        !           455:
        !           456: def Eliminatev(list,var)  /* [(x-y). (y-z).] [(z) ] */
        !           457: {
        !           458:    sm1(list, var, " eliminatev /FunctionValue set ");
        !           459: }
        !           460: HelpAdd(["Eliminatev",
        !           461: ["Eliminatev(list,var) prunes polynomials in << list >>(array of polynomials)",
        !           462:  "which contains the variables in << var >> ( array of strings )",
        !           463:  "Example: Eliminatev([Poly(\" x+h \"),Poly(\" x \")],[ \"h\" ]): "]]);
        !           464:
        !           465: def ReducedBase(base) {
        !           466:   sm1( base, " reducedBase /FunctionValue set ");
        !           467: }
        !           468: HelpAdd(["ReducedBase",
        !           469:  ["ReducedBase[base] prunes redundant elements in the Grobner basis <<base>> (array)."
        !           470: ]]);
        !           471:
        !           472: def IndexedVariables(name,size) {
        !           473:   local result,i,result2;
        !           474:   result = [ ];
        !           475:   for (i=0; i<size-1; i++) {
        !           476:     result = Append(result,Indexed(name,i));
        !           477:     result = Append(result,",");
        !           478:   }
        !           479:   if (size-1 >= 0) {
        !           480:     result = Append(result,Indexed(name,size-1));
        !           481:   }
        !           482:   result2 = Join(["{"],result);
        !           483:   result2 = Join(result2,["}"]);
        !           484:   return(AddString(result2));
        !           485: }
        !           486: HelpAdd(["IndexedVariables",
        !           487: ["IndexedVariables(name,size) returns the string ",
        !           488:  " {name[0],name[1],...,name[size-1]} which can be used as inputs to ",
        !           489:  " the function RingD  (string name, integer size).",
        !           490:  " cf. RingDonIndexedVariables.",
        !           491:  " Ex. R = RingD(IndexedVariables(\"a\",3)); ",
        !           492:  "     h = Poly(\"h\");",
        !           493:  "     a = NewArray(3);",
        !           494:  "     for (i=0; i<3; i++) {a[i] = Poly(Indexed(\"a\",i));} ;"]]);
        !           495:
        !           496:
        !           497: def RingDonIndexedVariables(vList, size, weightMatrix,pp) {
        !           498:   local myring,tmp,k00_i,argsize,vListD;
        !           499:   /* You cannot use these local varialbes as a name of global ring
        !           500:      variables. Change these names to names that start with k00_ */
        !           501:   argsize = Length(Arglist);
        !           502:   if (argsize == 1) {
        !           503:     Println("Error (IndexedRingD): ");
        !           504:     return(null);
        !           505:   }
        !           506:   if (argsize == 2) {
        !           507:     vListD = AddString(["D",vList]);
        !           508:     myring = RingD(IndexedVariables(vList,size));
        !           509:     SetRingVariables();
        !           510:     tmp = NewArray(size);
        !           511:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
        !           512:     sm1(vList, " (literal) dc ", tmp, " def ");
        !           513:     tmp = NewArray(size);
        !           514:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vListD,k00_i));}
        !           515:     sm1(vListD, " (literal) dc ", tmp, " def ");
        !           516:     if (SetRingVariables_Verbose) {
        !           517:       Print("Set the global variables ");
        !           518:       sm1("[(parse) ",vList," ] extension pop print ");
        !           519:       sm1("[(parse) ",vListD," ] extension pop print "); Ln();
        !           520:     }else {
        !           521:       sm1("[(parse) ",vList," ] extension pop  ");
        !           522:       sm1("[(parse) ",vListD," ] extension pop ");
        !           523:     }
        !           524:     return( myring );
        !           525:   }
        !           526:   if (argsize == 3 || argsize == 4) {
        !           527:    if (argsize == 3) { pp = 0; }
        !           528:    vListD = AddString(["D",vList]);
        !           529:    myring = RingD(IndexedVariables(vList,size),weightMatrix,pp);
        !           530:     SetRingVariables();
        !           531:     tmp = NewArray(size);
        !           532:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
        !           533:     sm1(vList, " (literal) dc ", tmp, " def ");
        !           534:     tmp = NewArray(size);
        !           535:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vListD,k00_i));}
        !           536:     sm1(vListD, " (literal) dc ", tmp, " def ");
        !           537:     if (SetRingVariables_Verbose) {
        !           538:       Print("Set the global variables ");
        !           539:       sm1("[(parse) ",vList," ] extension pop print ");
        !           540:       sm1("[(parse) ",vListD," ] extension pop print "); Ln();
        !           541:     } else {
        !           542:       sm1("[(parse) ",vList," ] extension pop  ");
        !           543:       sm1("[(parse) ",vListD," ] extension pop ");
        !           544:     }
        !           545:     return( myring );
        !           546:   }
        !           547:   return(-1);
        !           548: }
        !           549:
        !           550: def Ringp(f) {
        !           551:   sm1(f, " (ring) dc /FunctionValue set ");
        !           552: }
        !           553: HelpAdd(["Ringp",
        !           554:  ["Ringp(f) ( polynomial f ) returns the ring to which the polynomial << f >>",
        !           555:   "belongs."]]);
        !           556:
        !           557: def Coefficients(f,v) {
        !           558:   local ans,exp;
        !           559:   ans = sm1(f,v, " coefficients ");
        !           560:   exp = ans[0];
        !           561:   exp = sm1(exp," { (universalNumber) dc } map ");
        !           562:   return([exp,ans[1]]);
        !           563: }
        !           564:
        !           565: def IsInteger(a) {
        !           566:   sm1(a , " isUniversalNumber /FunctionValue set ");
        !           567: }
        !           568: HelpAdd(["IsInteger",
        !           569: ["IsInteger(a) returns true if << a >> is an integer (object a).",
        !           570:  "It returns false if << a >> is not.",
        !           571:  "cf. IsSm1Integer"]]);
        !           572:
        !           573: def IsRational(a) {
        !           574:   sm1(a , " isRational /FunctionValue set ");
        !           575: }
        !           576: HelpAdd(["IsRational",
        !           577: ["IsRational(a) returns true if << a >> is a rational (object a).",
        !           578:  "It returns false if << a >> is not."]]);
        !           579:
        !           580:
        !           581: def IsDouble(a) {
        !           582:   sm1(a , " isDouble /FunctionValue set ");
        !           583: }
        !           584: HelpAdd(["IsDouble",
        !           585: ["IsDouble(a) returns true if << a >> is a double (object a).",
        !           586:  "It returns false if << a >> is not."]]);
        !           587:
        !           588:
        !           589: sm1(" /cs { this  [ ] Cleards  } def ");
        !           590:
        !           591:
        !           592: def Init_w(f,vars,weight) {
        !           593:   local w,w2,w3,ans,i,n;
        !           594:   if (f == Poly("0")) return( Poly("0") );
        !           595:   w = Map(vars,"ToString");
        !           596:   w2 = sm1(weight," {$integer$ data_conversion} map ");
        !           597:   n = Length(w);
        !           598:   w3 = NewArray(n*2);
        !           599:   for (i=0; i<n ; i++) {
        !           600:     w3[2*i] = w[i]; w3[2*i+1] = w2[i];
        !           601:   }
        !           602:   ans = sm1(f,w3, " weightv init ");
        !           603:   return(ans);
        !           604: }
        !           605:
        !           606: HelpAdd(["Mapto",
        !           607:  ["Mapto(obj,ring) parses << obj >> as elements of the << ring >>.",
        !           608:   "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).",
        !           609:   "Ex. R = RingD(\"x,y\"); SetRingVariables();",
        !           610:   "    f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ",
        !           611:   "    f2 = Mapto(f,R2); f2: "]]);
        !           612:
        !           613: def Mapto(obj,ring) {
        !           614:    local ans,i,n;
        !           615:    if (IsArray(obj)) {
        !           616:       n = Length(obj);
        !           617:       ans = Map(obj,"ToString");
        !           618:       for (i=0; i<n; i++) {
        !           619:          ans[i] = PolyR(ans[i],ring);
        !           620:       }
        !           621:    }else{
        !           622:       ans = ToString(obj);
        !           623:       ans = PolyR(ans,ring);
        !           624:    }
        !           625:    return(ans);
        !           626: }
        !           627:
        !           628:
        !           629: HelpAdd(["ToDouble",
        !           630:  ["ToDouble(f) translates << f >> into double when it is possible",
        !           631:   "object << f >>.",
        !           632:   "Example: ToDouble([1,1/2,[5]]): "]]);
        !           633: def k00_toDouble(f) {   return(DC(f,"double")); }
        !           634: def ToDouble(f) {
        !           635:   if (IsArray(f)) return(Map(f,"ToDouble"));
        !           636:   if (IsDouble(f)) return(f);
        !           637:   return(k00_toDouble(f));
        !           638: }
        !           639:
        !           640:
        !           641: def RingPonIndexedVariables(vList, size, weightMatrix) {
        !           642:   local myring,tmp,k00_i,argsize,vListD;
        !           643:   /* You cannot use these local varialbes as a name of global ring
        !           644:      variables. Change these names to names that start with k00_ */
        !           645:   argsize = Length(Arglist);
        !           646:   if (argsize == 1) {
        !           647:     Println("Error (RingPonIndexedVariables): ");
        !           648:     return(null);
        !           649:   }
        !           650:   if (argsize == 2) {
        !           651:     myring = RingPoly(IndexedVariables(vList,size));
        !           652:     SetRingVariables();
        !           653:     tmp = NewArray(size);
        !           654:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
        !           655:     sm1(vList, " (literal) dc ", tmp, " def ");
        !           656:     if (SetRingVariables_Verbose) {
        !           657:      Print("Set the global variables ");
        !           658:      sm1("[(parse) ",vList," ] extension pop print "); Ln();
        !           659:     }else {
        !           660:      sm1("[(parse) ",vList," ] extension pop  ");
        !           661:     }
        !           662:     return( myring );
        !           663:   }
        !           664:   if (argsize == 3) {
        !           665:     myring = RingPoly(IndexedVariables(vList,size),weightMatrix);
        !           666:     SetRingVariables();
        !           667:     tmp = NewArray(size);
        !           668:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
        !           669:     sm1(vList, " (literal) dc ", tmp, " def ");
        !           670:     if (SetRingVariables_Verbose) {
        !           671:       Print("Set the global variables ");
        !           672:       sm1("[(parse) ",vList," ] extension pop print "); Ln();
        !           673:     } else {
        !           674:       sm1("[(parse) ",vList," ] extension pop ");
        !           675:     }
        !           676:     return( myring );
        !           677:   }
        !           678:   return(-1);
        !           679: }
        !           680:
        !           681: HelpAdd(["RingPonIndexedVariables",
        !           682:  ["RingPonIndexedVariables(name,n) defines and returns the ring of",
        !           683:   "polynomials",
        !           684:   "Q<h, name[0], ..., name[n-1] >",
        !           685:   "where <<name>> is a string and <<n>> is an integer.",
        !           686:   "Note that this function defines global variables",
        !           687:   "h, name[0], ..., name[n-1].",
        !           688:   "Example: RingPonIndexedVariables(\"x\",3).",
        !           689:   "RingPonIndexedVariables(name,n,w) defines and returns the ring of",
        !           690:   "polynomials with the ordering defined by ",
        !           691:   "the weight vector <<w>> (array)",
        !           692:   "Example: RingPonIndexedVariables(\"x\",3,[[\"x[0]\",1,\"x[2]\",3]])."]]);
        !           693:
        !           694:
        !           695: def Mod(f,n) {
        !           696:    if (IsPolynomial(f)) {
        !           697:      sm1("[(mod) ",f,n,"] gbext  /FunctionValue set ");
        !           698:    } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); }
        !           699: }
        !           700: HelpAdd(["Mod",
        !           701:  ["Mod(f,p) returns f modulo n  where << f >> (polynomial) and",
        !           702:   " << p >> (integer). "]]);
        !           703:
        !           704:
        !           705:
        !           706:
        !           707: def Characteristic(ringp) {
        !           708:   local r,p;
        !           709:   r = sm1(" [(CurrentRingp)] system_variable ");
        !           710:   sm1("[(CurrentRingp) ",ringp, " ] system_variable ");
        !           711:   p = sm1("[(P)] system_variable (universalNumber) dc ");
        !           712:   sm1("[(CurrentRingp) ",r, " ] system_variable ");
        !           713:   return(p);
        !           714: }
        !           715: HelpAdd(["Characteristic",
        !           716: ["Characteristic(ring) returns the characteristic of the << ring >>."
        !           717: ]]);
        !           718:
        !           719: def IsConstant(f) {
        !           720:   if (Length(f) > 1) return(false);
        !           721:   sm1("[(isConstant) ", f," ] gbext /FunctionValue set ");
        !           722: }
        !           723: HelpAdd(["IsConstant",
        !           724: ["IsConstant(f) returns true if the polynomial << f >> is a constant."
        !           725: ]]);
        !           726:
        !           727: Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h");
        !           728:
        !           729: def Substitute(f,xx,g) {
        !           730:   local tmp, coeff0,ex,i,n,newex;
        !           731:   if (IsInteger(f)) return(f);
        !           732:   if (! IsPolynomial(f)) {
        !           733:     k00_error("Substitute","The first argument must be polynomial.");
        !           734:   }
        !           735:   tmp = Coefficients(f,xx);
        !           736:   coeff0 = tmp[1];
        !           737:   ex = tmp[0];   /* [3, 2, 0] */
        !           738:   n = Length(ex);
        !           739:   newex = NewVector(n);
        !           740:   if (n>0) { newex[n-1] = g^ex[n-1]; }
        !           741:   for (i=n-2; i>=0; i--) {
        !           742:     newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1]));
        !           743:   }
        !           744:   return(Cancel(coeff0*newex));
        !           745: }
        !           746: HelpAdd(["Substitute",
        !           747: ["Substitute(f,xx,g) replaces << xx >> in << f >> by << g >>.",
        !           748:   "This function takes coeffients of << f >> with respect to << xx >>",
        !           749:   "and returns the inner product of the vector of coefficients and the vector",
        !           750:   "of which elements are g^(corresponding exponent).",
        !           751:   "Note that it may cause an unexpected result in non-commutative rings."
        !           752: ]]);
        !           753:
        !           754: def Tag(f) {
        !           755:   local ans;
        !           756:   if (IsArray(f)) {
        !           757:     return(Map(f,"Tag"));
        !           758:   }else {
        !           759:     ans = sm1(f," tag (universalNumber) dc ");
        !           760:     return(ans);
        !           761:   }
        !           762: }
        !           763: HelpAdd(["Tag",
        !           764: ["Tag(f) returns the datatype tags of f where",
        !           765:  "5: string,  9: polynomial, 15: integer(big-num), 16: rational, ",
        !           766:  "17: object, 18:double.",
        !           767:  "Ex. Tag([Poly(\"0\"), 0]):"
        !           768: ]]);
        !           769:
        !           770:
        !           771:
        !           772:
        !           773: OutputPrompt ;

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