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

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

1.6     ! takayama    1: /* $OpenXM: OpenXM/src/k097/help.k,v 1.5 2000/12/28 00:08:13 takayama Exp $ */
1.1       maekawa     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:
1.6     ! takayama  273: HelpAdd(["IsRing",
        !           274: ["IsRing(obj) returns true if << obj >> is a ring (object obj)."
        !           275: ]]);
        !           276:
1.1       maekawa   277:
                    278: HelpAdd(["IsSm1Integer",
                    279: ["IsSm1Integer(obj) returns true if << obj >> is an integer of sm1(object obj)."]]);
                    280:
                    281: HelpAdd(["sm1",
                    282: ["sm1(arg1,arg2,...) is used to embed sm1 native code in the kxx program.",
                    283:  "Example: sm1( 2, 2, \" add print \"); ",
                    284:  "Example: def myadd(a,b) { sm1(a,b,\" add /FunctionValue set \"); }" ]]);
                    285:
                    286: HelpAdd(["DC",
                    287: ["DC(obj,key) converts << obj >> to a new object in the primitive",
                    288:  "class << key >> (object obj, string key)",
                    289:  "Example:  DC(\" (x+1)^10 \", \"polynomial\"): "]]);
                    290:
                    291: HelpAdd(["Length",
                    292: ["Length(vec) returns the length of the array << vec >>",
                    293:  "(array vec)"]]);
                    294:
                    295: HelpAdd(["Transpose",
                    296: ["Transpose(m) return the transpose of the matrix << m >>",
                    297:  "(array of array m)."]]);
                    298:
                    299: HelpAdd(["Save",
                    300: ["Save(obj) appends << obj >> to the file sm1out.txt (object obj)."]]);
                    301:
                    302: HelpAdd(["Coefficients",
                    303: ["Coefficients(f,v) returns [exponents, coefficients] of << f >>",
                    304:  "with respect to the variable << v >>",
                    305:  "(polynomial f,v).",
                    306:  "Example: Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "]]);
                    307:
                    308: HelpAdd(["System",
                    309: ["System(comm) executes the unix system command << comm >>",
                    310:  "(string comm)",
                    311:  "Example: System(\"ls\");"]]);
                    312:
                    313: HelpAdd(["Exponent",
                    314:  ["Expoent(f,vars) returns the vector of exponents of the polynomial f",
                    315:   "Ex. Exponent( x^2*y-1,[x,y])"]]);
                    316:
                    317: HelpAdd(["Protect",
                    318:  ["Protect(name) protects the symbol <<name>> (string)",
                    319:   "Protect(name,level) protects the symbol <<name>> (string) with ",
                    320:   "<<level>> "]]);
                    321:
                    322: HelpAdd(["IsPolynomial",
                    323:  ["IsPolynomial(f) returns true if <<f>> (object) is a polynomial."]]);
                    324:
                    325:
                    326:
                    327: /* -----------------------------------------------
                    328:    functions on tests.    */
                    329: /* ------------  Developping functions  --------------------- */
                    330:
                    331: def RingPoly(vList,weightMatrix,pp) {
                    332:   local new0,tmp,size,n,i,j,newtmp,ringpp,argsize;
                    333:   argsize = Length(Arglist);
                    334:   if (argsize == 1) {
                    335:     sm1("[", vList,
                    336:         "ring_of_polynomials ( ) elimination_order 0 ] define_ring
                    337:          /tmp set ");
1.3       takayama  338:     SetRingVariables();
1.1       maekawa   339:     return(tmp);
                    340:   } else ;
                    341:   if (argsize == 2) {
                    342:     pp = 0;
                    343:   }
                    344:   pp = IntegerToSm1Integer(pp);
                    345:   size = Length(weightMatrix);
                    346:   new0 = NewVector(size);
                    347:   sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def ");
                    348:   sm1(" 0 @@@.indexMode ");
                    349:   for (i=0; i<size; i++) {
                    350:     tmp = weightMatrix[i];
                    351:     n = Length(tmp);
                    352:     newtmp = NewVector(n);
                    353:     for (j=1; j<n; j = j+2) {
                    354:        newtmp[j-1] = tmp[j-1];
                    355:        newtmp[j] = IntegerToSm1Integer( tmp[j] );
                    356:     }
                    357:     new0[i] = newtmp;
                    358:   }
1.3       takayama  359:   SetRingVariables();
1.1       maekawa   360:   ringpp =
                    361:   sm1("[", vList,
                    362:       "ring_of_polynomials ", new0, " weight_vector", pp, " ] define_ring");
                    363:   sm1(" @@@.indexMode.flag.save @@@.indexMode ");
                    364:   return( ringpp );
                    365: }
                    366:
                    367: def IsString(ob) {
                    368:   sm1(ob , " isString /FunctionValue set ");
                    369: }
                    370:
                    371: def IsSm1Integer(ob) {
                    372:   sm1(ob , " isInteger /FunctionValue set ");
1.6     ! takayama  373: }
        !           374:
        !           375: def IsRing(ob) {
        !           376:   sm1(ob , " isRing /FunctionValue set ");
1.1       maekawa   377: }
                    378:
                    379:
                    380: def CancelNumber(rn) {
                    381:   local tmp;
                    382:   sm1(" [(cancel) ",rn," ] mpzext /tmp set ");
                    383:   if (IsInteger(tmp)) return(tmp);
                    384:   sm1(" tmp (denominator) dc (1).. eq { /FunctionValue tmp (numerator) dc def} { /FunctionValue tmp def } ifelse ");
                    385: }
                    386:
1.5       takayama  387: def DC_polynomial(obj) {
                    388:   return(DC(obj,"polynomial"));
                    389: }
1.1       maekawa   390: def DC(obj,key) {
1.5       takayama  391:   if (IsArray(obj) && key=="polynomial") {
                    392:     return(Map(obj,"DC_polynomial"));
                    393:   }
1.1       maekawa   394:   if (key == "string") { return(ToString(obj)); }
                    395:   else if (key == "integer") { key = "universalNumber"; }
                    396:   else if (key == "sm1integer") { key = "integer"; }
                    397:   else if (key == "polynomial") { key = "poly"; }
                    398:   else ;
                    399:   sm1( obj , key, " data_conversion /FunctionValue set ");
                    400: }
                    401:
                    402: def Transpose(m) {
                    403:   sm1(m, " transpose /FunctionValue set ");
                    404: }
                    405:
                    406: def Save(obj) {
                    407:   sm1(obj, " output ");
                    408: }
                    409:
                    410:
                    411: def void System(comm) {
                    412:   sm1(comm, " system ");
                    413: }
                    414:
                    415:
                    416: def IsReducible(f,g) {
                    417:   sm1("[ (isReducible) ",f,g," ] gbext /FunctionValue set ");
                    418: }
                    419:
                    420: def IsPolynomial(f) {
                    421:   sm1(" f isPolynomial /FunctionValue set ");
                    422: }
                    423: sm1(" /k00.toric0.mydegree {2 1 roll degree} def ");
                    424: def Exponent(f,vars) {
                    425:   local n,i,ans;
                    426:   if (f == Poly("0")) return([ ] );
                    427:   sm1(f," /ff.tmp set ", vars ,
                    428:       " {ff.tmp k00.toric0.mydegree (universalNumber) dc }map /FunctionValue set ");
                    429: }
                    430: def void Protect(name,level) {
                    431:   local n,str;
                    432:   n = Length(Arglist);
                    433:   if (n == 1) {
                    434:     level = 1;
                    435:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
                    436:                      " ] extension pop "]);
                    437:     /* Println(str); */
                    438:     sm1(" [(parse) ",str ," ] extension pop ");
                    439:   } else if (n ==2) {
                    440:     str = AddString(["[(chattr) ",ToString(level)," /",name," ",
                    441:                      " ] extension pop "]);
                    442:     /* Println(str); */
                    443:     sm1(" [(parse) ",str ," ] extension pop ");
                    444:   } else {
                    445:      k00_error("Protect","Arguments must be one or two. ");sm1(" error ");
                    446:   }
                    447: }
                    448:
                    449: def void k00_error(name,msg) {
                    450:   Print("Error in "); Print(name); Print(". ");
                    451:   Println(msg);
                    452: }
                    453:
                    454: def Init(f) {
                    455:   if (IsArray(f)) {
                    456:      return(Map(f,"Init"));
                    457:   } else if (IsPolynomial(f)) {
                    458:      sm1(f,"  init  /FunctionValue set ");
                    459:   } else {
                    460:      k00_error("Init","Argment must be polynomial or an array of polynomials");
                    461:      sm1(" error ");
                    462:   }
                    463: }
                    464: HelpAdd(["Init",
                    465:  ["Init(f) returns the initial term of the polynomial <<f>> (polynomial)",
                    466:   "Init(list) returns the array of initial terms of the array of polynomials",
                    467:   "<< list >> (array)"]]);
                    468:
                    469: HelpAdd(["NewMatrix",
                    470:  ["NewMatrix(m,n) returns the (m,n)-matrix (array) with the entries 0."]]);
                    471:
                    472: def Eliminatev(list,var)  /* [(x-y). (y-z).] [(z) ] */
                    473: {
                    474:    sm1(list, var, " eliminatev /FunctionValue set ");
                    475: }
                    476: HelpAdd(["Eliminatev",
                    477: ["Eliminatev(list,var) prunes polynomials in << list >>(array of polynomials)",
                    478:  "which contains the variables in << var >> ( array of strings )",
                    479:  "Example: Eliminatev([Poly(\" x+h \"),Poly(\" x \")],[ \"h\" ]): "]]);
                    480:
                    481: def ReducedBase(base) {
                    482:   sm1( base, " reducedBase /FunctionValue set ");
                    483: }
                    484: HelpAdd(["ReducedBase",
                    485:  ["ReducedBase[base] prunes redundant elements in the Grobner basis <<base>> (array)."
                    486: ]]);
                    487:
                    488: def IndexedVariables(name,size) {
                    489:   local result,i,result2;
                    490:   result = [ ];
                    491:   for (i=0; i<size-1; i++) {
                    492:     result = Append(result,Indexed(name,i));
                    493:     result = Append(result,",");
                    494:   }
                    495:   if (size-1 >= 0) {
                    496:     result = Append(result,Indexed(name,size-1));
                    497:   }
                    498:   result2 = Join(["{"],result);
                    499:   result2 = Join(result2,["}"]);
                    500:   return(AddString(result2));
                    501: }
                    502: HelpAdd(["IndexedVariables",
                    503: ["IndexedVariables(name,size) returns the string ",
                    504:  " {name[0],name[1],...,name[size-1]} which can be used as inputs to ",
                    505:  " the function RingD  (string name, integer size).",
                    506:  " cf. RingDonIndexedVariables.",
                    507:  " Ex. R = RingD(IndexedVariables(\"a\",3)); ",
                    508:  "     h = Poly(\"h\");",
                    509:  "     a = NewArray(3);",
                    510:  "     for (i=0; i<3; i++) {a[i] = Poly(Indexed(\"a\",i));} ;"]]);
                    511:
                    512:
                    513: def RingDonIndexedVariables(vList, size, weightMatrix,pp) {
                    514:   local myring,tmp,k00_i,argsize,vListD;
                    515:   /* You cannot use these local varialbes as a name of global ring
                    516:      variables. Change these names to names that start with k00_ */
                    517:   argsize = Length(Arglist);
                    518:   if (argsize == 1) {
                    519:     Println("Error (IndexedRingD): ");
                    520:     return(null);
                    521:   }
                    522:   if (argsize == 2) {
                    523:     vListD = AddString(["D",vList]);
                    524:     myring = RingD(IndexedVariables(vList,size));
                    525:     tmp = NewArray(size);
                    526:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
                    527:     sm1(vList, " (literal) dc ", tmp, " def ");
                    528:     tmp = NewArray(size);
                    529:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vListD,k00_i));}
                    530:     sm1(vListD, " (literal) dc ", tmp, " def ");
                    531:     if (SetRingVariables_Verbose) {
                    532:       Print("Set the global variables ");
                    533:       sm1("[(parse) ",vList," ] extension pop print ");
                    534:       sm1("[(parse) ",vListD," ] extension pop print "); Ln();
                    535:     }else {
                    536:       sm1("[(parse) ",vList," ] extension pop  ");
                    537:       sm1("[(parse) ",vListD," ] extension pop ");
                    538:     }
                    539:     return( myring );
                    540:   }
                    541:   if (argsize == 3 || argsize == 4) {
                    542:    if (argsize == 3) { pp = 0; }
                    543:    vListD = AddString(["D",vList]);
                    544:    myring = RingD(IndexedVariables(vList,size),weightMatrix,pp);
                    545:     SetRingVariables();
                    546:     tmp = NewArray(size);
                    547:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
                    548:     sm1(vList, " (literal) dc ", tmp, " def ");
                    549:     tmp = NewArray(size);
                    550:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vListD,k00_i));}
                    551:     sm1(vListD, " (literal) dc ", tmp, " def ");
                    552:     if (SetRingVariables_Verbose) {
                    553:       Print("Set the global variables ");
                    554:       sm1("[(parse) ",vList," ] extension pop print ");
                    555:       sm1("[(parse) ",vListD," ] extension pop print "); Ln();
                    556:     } else {
                    557:       sm1("[(parse) ",vList," ] extension pop  ");
                    558:       sm1("[(parse) ",vListD," ] extension pop ");
                    559:     }
                    560:     return( myring );
                    561:   }
                    562:   return(-1);
                    563: }
                    564:
                    565: def Ringp(f) {
                    566:   sm1(f, " (ring) dc /FunctionValue set ");
                    567: }
                    568: HelpAdd(["Ringp",
                    569:  ["Ringp(f) ( polynomial f ) returns the ring to which the polynomial << f >>",
                    570:   "belongs."]]);
                    571:
                    572: def Coefficients(f,v) {
                    573:   local ans,exp;
                    574:   ans = sm1(f,v, " coefficients ");
                    575:   exp = ans[0];
                    576:   exp = sm1(exp," { (universalNumber) dc } map ");
                    577:   return([exp,ans[1]]);
                    578: }
                    579:
                    580: def IsInteger(a) {
                    581:   sm1(a , " isUniversalNumber /FunctionValue set ");
                    582: }
                    583: HelpAdd(["IsInteger",
                    584: ["IsInteger(a) returns true if << a >> is an integer (object a).",
                    585:  "It returns false if << a >> is not.",
                    586:  "cf. IsSm1Integer"]]);
                    587:
                    588: def IsRational(a) {
                    589:   sm1(a , " isRational /FunctionValue set ");
                    590: }
                    591: HelpAdd(["IsRational",
                    592: ["IsRational(a) returns true if << a >> is a rational (object a).",
                    593:  "It returns false if << a >> is not."]]);
                    594:
                    595:
                    596: def IsDouble(a) {
                    597:   sm1(a , " isDouble /FunctionValue set ");
                    598: }
                    599: HelpAdd(["IsDouble",
                    600: ["IsDouble(a) returns true if << a >> is a double (object a).",
                    601:  "It returns false if << a >> is not."]]);
                    602:
                    603:
                    604: sm1(" /cs { this  [ ] Cleards  } def ");
                    605:
                    606:
                    607: def Init_w(f,vars,weight) {
                    608:   local w,w2,w3,ans,i,n;
                    609:   if (f == Poly("0")) return( Poly("0") );
                    610:   w = Map(vars,"ToString");
                    611:   w2 = sm1(weight," {$integer$ data_conversion} map ");
                    612:   n = Length(w);
                    613:   w3 = NewArray(n*2);
                    614:   for (i=0; i<n ; i++) {
                    615:     w3[2*i] = w[i]; w3[2*i+1] = w2[i];
                    616:   }
                    617:   ans = sm1(f,w3, " weightv init ");
                    618:   return(ans);
                    619: }
                    620:
                    621: HelpAdd(["Mapto",
                    622:  ["Mapto(obj,ring) parses << obj >> as elements of the << ring >>.",
                    623:   "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).",
                    624:   "Ex. R = RingD(\"x,y\"); SetRingVariables();",
                    625:   "    f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ",
                    626:   "    f2 = Mapto(f,R2); f2: "]]);
                    627:
                    628: def Mapto(obj,ring) {
                    629:    local ans,i,n;
                    630:    if (IsArray(obj)) {
                    631:       n = Length(obj);
                    632:       ans = Map(obj,"ToString");
                    633:       for (i=0; i<n; i++) {
                    634:          ans[i] = PolyR(ans[i],ring);
                    635:       }
                    636:    }else{
                    637:       ans = ToString(obj);
                    638:       ans = PolyR(ans,ring);
                    639:    }
                    640:    return(ans);
                    641: }
                    642:
                    643:
                    644: HelpAdd(["ToDouble",
                    645:  ["ToDouble(f) translates << f >> into double when it is possible",
                    646:   "object << f >>.",
                    647:   "Example: ToDouble([1,1/2,[5]]): "]]);
                    648: def k00_toDouble(f) {   return(DC(f,"double")); }
                    649: def ToDouble(f) {
                    650:   if (IsArray(f)) return(Map(f,"ToDouble"));
                    651:   if (IsDouble(f)) return(f);
                    652:   return(k00_toDouble(f));
                    653: }
                    654:
                    655:
                    656: def RingPonIndexedVariables(vList, size, weightMatrix) {
                    657:   local myring,tmp,k00_i,argsize,vListD;
                    658:   /* You cannot use these local varialbes as a name of global ring
                    659:      variables. Change these names to names that start with k00_ */
                    660:   argsize = Length(Arglist);
                    661:   if (argsize == 1) {
                    662:     Println("Error (RingPonIndexedVariables): ");
                    663:     return(null);
                    664:   }
                    665:   if (argsize == 2) {
                    666:     myring = RingPoly(IndexedVariables(vList,size));
                    667:     SetRingVariables();
                    668:     tmp = NewArray(size);
                    669:     for (k00_i=0; k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
                    670:     sm1(vList, " (literal) dc ", tmp, " def ");
                    671:     if (SetRingVariables_Verbose) {
                    672:      Print("Set the global variables ");
                    673:      sm1("[(parse) ",vList," ] extension pop print "); Ln();
                    674:     }else {
                    675:      sm1("[(parse) ",vList," ] extension pop  ");
                    676:     }
                    677:     return( myring );
                    678:   }
                    679:   if (argsize == 3) {
                    680:     myring = RingPoly(IndexedVariables(vList,size),weightMatrix);
                    681:     SetRingVariables();
                    682:     tmp = NewArray(size);
                    683:     for (k00_i=0;k00_i<size; k00_i++) {tmp[k00_i]=Poly(Indexed(vList,k00_i));}
                    684:     sm1(vList, " (literal) dc ", tmp, " def ");
                    685:     if (SetRingVariables_Verbose) {
                    686:       Print("Set the global variables ");
                    687:       sm1("[(parse) ",vList," ] extension pop print "); Ln();
                    688:     } else {
                    689:       sm1("[(parse) ",vList," ] extension pop ");
                    690:     }
                    691:     return( myring );
                    692:   }
                    693:   return(-1);
                    694: }
                    695:
                    696: HelpAdd(["RingPonIndexedVariables",
                    697:  ["RingPonIndexedVariables(name,n) defines and returns the ring of",
                    698:   "polynomials",
                    699:   "Q<h, name[0], ..., name[n-1] >",
                    700:   "where <<name>> is a string and <<n>> is an integer.",
                    701:   "Note that this function defines global variables",
                    702:   "h, name[0], ..., name[n-1].",
                    703:   "Example: RingPonIndexedVariables(\"x\",3).",
                    704:   "RingPonIndexedVariables(name,n,w) defines and returns the ring of",
                    705:   "polynomials with the ordering defined by ",
                    706:   "the weight vector <<w>> (array)",
                    707:   "Example: RingPonIndexedVariables(\"x\",3,[[\"x[0]\",1,\"x[2]\",3]])."]]);
                    708:
                    709:
                    710: def Mod(f,n) {
                    711:    if (IsPolynomial(f)) {
                    712:      sm1("[(mod) ",f,n,"] gbext  /FunctionValue set ");
                    713:    } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); }
                    714: }
                    715: HelpAdd(["Mod",
                    716:  ["Mod(f,p) returns f modulo n  where << f >> (polynomial) and",
                    717:   " << p >> (integer). "]]);
                    718:
                    719:
                    720:
                    721:
                    722: def Characteristic(ringp) {
                    723:   local r,p;
                    724:   r = sm1(" [(CurrentRingp)] system_variable ");
                    725:   sm1("[(CurrentRingp) ",ringp, " ] system_variable ");
                    726:   p = sm1("[(P)] system_variable (universalNumber) dc ");
                    727:   sm1("[(CurrentRingp) ",r, " ] system_variable ");
                    728:   return(p);
                    729: }
                    730: HelpAdd(["Characteristic",
                    731: ["Characteristic(ring) returns the characteristic of the << ring >>."
                    732: ]]);
                    733:
                    734: def IsConstant(f) {
                    735:   if (Length(f) > 1) return(false);
                    736:   sm1("[(isConstant) ", f," ] gbext /FunctionValue set ");
                    737: }
                    738: HelpAdd(["IsConstant",
                    739: ["IsConstant(f) returns true if the polynomial << f >> is a constant."
                    740: ]]);
                    741:
                    742: Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h");
                    743:
                    744: def Substitute(f,xx,g) {
                    745:   local tmp, coeff0,ex,i,n,newex;
                    746:   if (IsInteger(f)) return(f);
                    747:   if (! IsPolynomial(f)) {
                    748:     k00_error("Substitute","The first argument must be polynomial.");
                    749:   }
                    750:   tmp = Coefficients(f,xx);
                    751:   coeff0 = tmp[1];
                    752:   ex = tmp[0];   /* [3, 2, 0] */
                    753:   n = Length(ex);
                    754:   newex = NewVector(n);
                    755:   if (n>0) { newex[n-1] = g^ex[n-1]; }
                    756:   for (i=n-2; i>=0; i--) {
                    757:     newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1]));
                    758:   }
                    759:   return(Cancel(coeff0*newex));
                    760: }
                    761: HelpAdd(["Substitute",
                    762: ["Substitute(f,xx,g) replaces << xx >> in << f >> by << g >>.",
                    763:   "This function takes coeffients of << f >> with respect to << xx >>",
                    764:   "and returns the inner product of the vector of coefficients and the vector",
                    765:   "of which elements are g^(corresponding exponent).",
                    766:   "Note that it may cause an unexpected result in non-commutative rings."
                    767: ]]);
                    768:
                    769: def Tag(f) {
                    770:   local ans;
                    771:   if (IsArray(f)) {
                    772:     return(Map(f,"Tag"));
                    773:   }else {
1.4       takayama  774:     ans = sm1(f," etag (universalNumber) dc ");
1.1       maekawa   775:     return(ans);
                    776:   }
                    777: }
                    778: HelpAdd(["Tag",
                    779: ["Tag(f) returns the datatype tags of f where",
                    780:  "5: string,  9: polynomial, 15: integer(big-num), 16: rational, ",
1.4       takayama  781:  "18:double, 257: Error ",
1.1       maekawa   782:  "Ex. Tag([Poly(\"0\"), 0]):"
                    783: ]]);
                    784:
1.4       takayama  785: def Error(s) {
                    786:   sm1(" s error ");
                    787: }
                    788: HelpAdd(["Error",
                    789: ["Error(s) causes an error and outputs a message s."]]);
1.1       maekawa   790:
                    791: OutputPrompt ;

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