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

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

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

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