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

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

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

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