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

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

1.8     ! takayama    1: /* $OpenXM: OpenXM/src/k097/help.k,v 1.7 2001/01/04 12:29:31 takayama Exp $ */
1.1       maekawa     2: if (K00_verbose)
1.8     ! takayama    3:   Println("help.k:  8/6, 1996 --- 8/7, 1996. 3/6, 1997 --- 12/21, 1997.");
1.1       maekawa     4:
                      5: def help(x) {
                      6:   if (Length(Arglist) < 1) {
                      7:      ShowKeyWords(" ");
                      8:   } else {
                      9:      Help(x);
                     10:   }
                     11: }
                     12:
                     13:
                     14: def Help(key) {
                     15:   local n,i,item,m,item1,j;
                     16:   if (Length(Arglist) < 1) {
                     17:      ShowKeyWords(" ");
                     18:      return( [ ] );
                     19:   }
                     20:
                     21:   if (key == "ALL") {
                     22:     ShowKeyWords("ALL"); return(0);
                     23:   }
                     24:   n = Length(Helplist);
                     25:   PSfor (i=0; i<n; i++) {
                     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",
1.7       takayama  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); "]]);
1.1       maekawa   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)."]);
1.7       takayama  188: HelpAdd(["Replace",
                    189:   ["Replace(f,rule) (polynomial f, array rule).  ",
                    190:    "Ex. Replace( (x+y)^3, [[x,Poly(\"1\")]])"]]);
1.1       maekawa   191: HelpAdd(["SetRingVariables",
                    192:  "SetRingVariables()
                    193:   Set the generators of the current ring as global variables.
                    194:   cf. RingD(), Poly(), PolyR()"]);
                    195: HelpAdd(["Append","Append([f1,...,fn],g) returns the list [f1,...,fn,g]"]);
                    196: HelpAdd(["Join",
                    197:  "Join([f1,...,fn],[g1,...,gm]) returns the list
                    198:   [f1,...,fn,g1,...,gm]"]);
                    199:
1.8     ! takayama  200: HelpAdd(["!ReservedNames",
1.1       maekawa   201:  ["The names k00*, K00*, sm1* , arg1,arg2,arg3,arg4,....," ,
                    202:   "Helplist, Arglist, FunctionValue,",
                    203:   "@@@*, db.*, k.*, tmp002*, tmp00* are used for system functions."]]);
                    204:
                    205: HelpAdd(["IntegerToSm1Integer",
                    206:  "IntegerToSm1Integer(i) translates integer i
                    207:   to sm1.integer (integer i)."]);
                    208: HelpAdd(["true","true returns sm1.integer 1."]);
                    209: HelpAdd(["false","false returns sm1.integer 0."]);
                    210: HelpAdd(["IsArray",
                    211:  ["If f is the array object, then IsArray(f) returns true,",
                    212:   "else IsArray(f) returns false."]]);
                    213:
                    214:
                    215:
                    216: HelpAdd(["Init_w",
                    217:  ["Init_w(f,vars,w) returns the initial terms with respect to the",
                    218:   "weight vector <<w>> (array of integer) of the polynomial <<f>>",
                    219:   "(polynomial).  Here, <<f>> is regarded as a polynomial with respect",
                    220:   "to the variables <<vars>> (array of polynomials).",
                    221:   "Example: Init_w(x^2+y^2+x,[x,y],[1,1]):"]]);
                    222:
                    223:
                    224: HelpAdd(["Groebner",
                    225:  ["Groebner(input) returns Groebner basis of the left module (or ideal)",
                    226:   "defined by <<input>> (array of polynomials)",
                    227:   "The order is that of the ring to which each element of <<input>>",
                    228:   "belongs.",
                    229:   "The input is automatically homogenized.",
                    230:   "Example: RingD(\"x,y\",[[\"x\", 10, \"y\", 1]]);",
                    231:   "         Groebner([Poly(\" x^2+y^2-4\"),Poly(\" x*y-1 \")]):",
                    232:   "cf. RingD, Homogenize"]]);
                    233:
                    234:
                    235: HelpAdd(["RingPoly",
                    236:  ["RingPoly(names) defines a Ring of Polyomials (string names).",
                    237:   "The names of variables of that ring are <<names>>  and ",
                    238:   "the homogenization variable h.",
                    239:   "cf. SetRingVariables, RingD",
                    240:   "Example: R=RingPoly(\"x,y\");",
                    241:   "  ",
                    242:   "RingPoly(names,weight_vector) defines a Ring of Polynomials",
                    243:   "with the order defined by the << weight_vector >>",
                    244:   "(string names, array of array weight_vector).",
                    245:   "RingPoly(names,weight_vector,characteristic)",
                    246:   "Example: R=RingPoly(\"x,y\",[[\"x\",10,\"y\",1]]);",
                    247:   "         (x+y)^10: "]]);
                    248:
                    249:
                    250: HelpAdd(["CancelNumber",
                    251: ["CancelNumber(rn) reduces the rational number <<rn>>",
                    252:  "(rational rn).",
                    253:  "Example: CancelNumber( 2/6 ) : "]]);
                    254:
                    255: HelpAdd(["IsString",
                    256: ["IsString(obj) returns true if << obj >> is a string (object obj).",
                    257:  "Example:  if (IsString(\"abc\")) Println(\"Hello\"); ;"]]);
                    258:
1.6       takayama  259: HelpAdd(["IsRing",
                    260: ["IsRing(obj) returns true if << obj >> is a ring (object obj)."
                    261: ]]);
                    262:
1.1       maekawa   263:
                    264: HelpAdd(["IsSm1Integer",
                    265: ["IsSm1Integer(obj) returns true if << obj >> is an integer of sm1(object obj)."]]);
                    266:
                    267: HelpAdd(["sm1",
                    268: ["sm1(arg1,arg2,...) is used to embed sm1 native code in the kxx program.",
                    269:  "Example: sm1( 2, 2, \" add print \"); ",
                    270:  "Example: def myadd(a,b) { sm1(a,b,\" add /FunctionValue set \"); }" ]]);
                    271:
                    272: HelpAdd(["DC",
                    273: ["DC(obj,key) converts << obj >> to a new object in the primitive",
                    274:  "class << key >> (object obj, string key)",
                    275:  "Example:  DC(\" (x+1)^10 \", \"polynomial\"): "]]);
                    276:
                    277: HelpAdd(["Length",
                    278: ["Length(vec) returns the length of the array << vec >>",
                    279:  "(array vec)"]]);
                    280:
                    281: HelpAdd(["Transpose",
                    282: ["Transpose(m) return the transpose of the matrix << m >>",
                    283:  "(array of array m)."]]);
                    284:
                    285: HelpAdd(["Save",
                    286: ["Save(obj) appends << obj >> to the file sm1out.txt (object obj)."]]);
                    287:
                    288: HelpAdd(["Coefficients",
                    289: ["Coefficients(f,v) returns [exponents, coefficients] of << f >>",
                    290:  "with respect to the variable << v >>",
                    291:  "(polynomial f,v).",
                    292:  "Example: Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "]]);
                    293:
                    294: HelpAdd(["System",
                    295: ["System(comm) executes the unix system command << comm >>",
                    296:  "(string comm)",
                    297:  "Example: System(\"ls\");"]]);
                    298:
                    299: HelpAdd(["Exponent",
                    300:  ["Expoent(f,vars) returns the vector of exponents of the polynomial f",
                    301:   "Ex. Exponent( x^2*y-1,[x,y])"]]);
                    302:
                    303: HelpAdd(["Protect",
                    304:  ["Protect(name) protects the symbol <<name>> (string)",
                    305:   "Protect(name,level) protects the symbol <<name>> (string) with ",
                    306:   "<<level>> "]]);
                    307:
                    308: HelpAdd(["IsPolynomial",
                    309:  ["IsPolynomial(f) returns true if <<f>> (object) is a polynomial."]]);
                    310:
                    311:
                    312:
                    313: /* -----------------------------------------------
                    314:    functions on tests.    */
                    315: /* ------------  Developping functions  --------------------- */
                    316:
                    317: def RingPoly(vList,weightMatrix,pp) {
                    318:   local new0,tmp,size,n,i,j,newtmp,ringpp,argsize;
                    319:   argsize = Length(Arglist);
                    320:   if (argsize == 1) {
                    321:     sm1("[", vList,
                    322:         "ring_of_polynomials ( ) elimination_order 0 ] define_ring
                    323:          /tmp set ");
1.3       takayama  324:     SetRingVariables();
1.1       maekawa   325:     return(tmp);
                    326:   } else ;
                    327:   if (argsize == 2) {
                    328:     pp = 0;
                    329:   }
                    330:   pp = IntegerToSm1Integer(pp);
                    331:   size = Length(weightMatrix);
                    332:   new0 = NewVector(size);
                    333:   sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def ");
                    334:   sm1(" 0 @@@.indexMode ");
                    335:   for (i=0; i<size; i++) {
                    336:     tmp = weightMatrix[i];
                    337:     n = Length(tmp);
                    338:     newtmp = NewVector(n);
                    339:     for (j=1; j<n; j = j+2) {
                    340:        newtmp[j-1] = tmp[j-1];
                    341:        newtmp[j] = IntegerToSm1Integer( tmp[j] );
                    342:     }
                    343:     new0[i] = newtmp;
                    344:   }
1.3       takayama  345:   SetRingVariables();
1.1       maekawa   346:   ringpp =
                    347:   sm1("[", vList,
                    348:       "ring_of_polynomials ", new0, " weight_vector", pp, " ] define_ring");
                    349:   sm1(" @@@.indexMode.flag.save @@@.indexMode ");
                    350:   return( ringpp );
                    351: }
                    352:
                    353: def IsString(ob) {
                    354:   sm1(ob , " isString /FunctionValue set ");
                    355: }
                    356:
                    357: def IsSm1Integer(ob) {
                    358:   sm1(ob , " isInteger /FunctionValue set ");
1.6       takayama  359: }
                    360:
                    361: def IsRing(ob) {
                    362:   sm1(ob , " isRing /FunctionValue set ");
1.1       maekawa   363: }
                    364:
                    365:
                    366: def CancelNumber(rn) {
                    367:   local tmp;
                    368:   sm1(" [(cancel) ",rn," ] mpzext /tmp set ");
                    369:   if (IsInteger(tmp)) return(tmp);
                    370:   sm1(" tmp (denominator) dc (1).. eq { /FunctionValue tmp (numerator) dc def} { /FunctionValue tmp def } ifelse ");
                    371: }
                    372:
1.5       takayama  373: def DC_polynomial(obj) {
                    374:   return(DC(obj,"polynomial"));
                    375: }
1.1       maekawa   376: def DC(obj,key) {
1.5       takayama  377:   if (IsArray(obj) && key=="polynomial") {
                    378:     return(Map(obj,"DC_polynomial"));
                    379:   }
1.1       maekawa   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:
                    475: def Ringp(f) {
                    476:   sm1(f, " (ring) dc /FunctionValue set ");
                    477: }
                    478: HelpAdd(["Ringp",
                    479:  ["Ringp(f) ( polynomial f ) returns the ring to which the polynomial << f >>",
                    480:   "belongs."]]);
                    481:
                    482: def Coefficients(f,v) {
                    483:   local ans,exp;
                    484:   ans = sm1(f,v, " coefficients ");
                    485:   exp = ans[0];
                    486:   exp = sm1(exp," { (universalNumber) dc } map ");
                    487:   return([exp,ans[1]]);
                    488: }
                    489:
                    490: def IsInteger(a) {
                    491:   sm1(a , " isUniversalNumber /FunctionValue set ");
                    492: }
                    493: HelpAdd(["IsInteger",
                    494: ["IsInteger(a) returns true if << a >> is an integer (object a).",
                    495:  "It returns false if << a >> is not.",
                    496:  "cf. IsSm1Integer"]]);
                    497:
                    498: def IsRational(a) {
                    499:   sm1(a , " isRational /FunctionValue set ");
                    500: }
                    501: HelpAdd(["IsRational",
                    502: ["IsRational(a) returns true if << a >> is a rational (object a).",
                    503:  "It returns false if << a >> is not."]]);
                    504:
                    505:
                    506: def IsDouble(a) {
                    507:   sm1(a , " isDouble /FunctionValue set ");
                    508: }
                    509: HelpAdd(["IsDouble",
                    510: ["IsDouble(a) returns true if << a >> is a double (object a).",
                    511:  "It returns false if << a >> is not."]]);
                    512:
                    513:
                    514: sm1(" /cs { this  [ ] Cleards  } def ");
                    515:
                    516:
                    517: def Init_w(f,vars,weight) {
                    518:   local w,w2,w3,ans,i,n;
                    519:   if (f == Poly("0")) return( Poly("0") );
                    520:   w = Map(vars,"ToString");
                    521:   w2 = sm1(weight," {$integer$ data_conversion} map ");
                    522:   n = Length(w);
                    523:   w3 = NewArray(n*2);
                    524:   for (i=0; i<n ; i++) {
                    525:     w3[2*i] = w[i]; w3[2*i+1] = w2[i];
                    526:   }
                    527:   ans = sm1(f,w3, " weightv init ");
                    528:   return(ans);
                    529: }
                    530:
                    531: HelpAdd(["Mapto",
                    532:  ["Mapto(obj,ring) parses << obj >> as elements of the << ring >>.",
                    533:   "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).",
                    534:   "Ex. R = RingD(\"x,y\"); SetRingVariables();",
                    535:   "    f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ",
                    536:   "    f2 = Mapto(f,R2); f2: "]]);
                    537:
                    538: def Mapto(obj,ring) {
                    539:    local ans,i,n;
                    540:    if (IsArray(obj)) {
                    541:       n = Length(obj);
                    542:       ans = Map(obj,"ToString");
                    543:       for (i=0; i<n; i++) {
                    544:          ans[i] = PolyR(ans[i],ring);
                    545:       }
                    546:    }else{
                    547:       ans = ToString(obj);
                    548:       ans = PolyR(ans,ring);
                    549:    }
                    550:    return(ans);
                    551: }
                    552:
                    553:
                    554: HelpAdd(["ToDouble",
                    555:  ["ToDouble(f) translates << f >> into double when it is possible",
                    556:   "object << f >>.",
                    557:   "Example: ToDouble([1,1/2,[5]]): "]]);
                    558: def k00_toDouble(f) {   return(DC(f,"double")); }
                    559: def ToDouble(f) {
                    560:   if (IsArray(f)) return(Map(f,"ToDouble"));
                    561:   if (IsDouble(f)) return(f);
                    562:   return(k00_toDouble(f));
                    563: }
                    564:
                    565:
                    566:
                    567: def Mod(f,n) {
                    568:    if (IsPolynomial(f)) {
                    569:      sm1("[(mod) ",f,n,"] gbext  /FunctionValue set ");
                    570:    } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); }
                    571: }
                    572: HelpAdd(["Mod",
                    573:  ["Mod(f,p) returns f modulo n  where << f >> (polynomial) and",
                    574:   " << p >> (integer). "]]);
                    575:
                    576:
                    577:
                    578:
                    579: def Characteristic(ringp) {
                    580:   local r,p;
                    581:   r = sm1(" [(CurrentRingp)] system_variable ");
                    582:   sm1("[(CurrentRingp) ",ringp, " ] system_variable ");
                    583:   p = sm1("[(P)] system_variable (universalNumber) dc ");
                    584:   sm1("[(CurrentRingp) ",r, " ] system_variable ");
                    585:   return(p);
                    586: }
                    587: HelpAdd(["Characteristic",
                    588: ["Characteristic(ring) returns the characteristic of the << ring >>."
                    589: ]]);
                    590:
                    591: def IsConstant(f) {
                    592:   if (Length(f) > 1) return(false);
                    593:   sm1("[(isConstant) ", f," ] gbext /FunctionValue set ");
                    594: }
                    595: HelpAdd(["IsConstant",
                    596: ["IsConstant(f) returns true if the polynomial << f >> is a constant."
                    597: ]]);
                    598:
                    599: Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h");
                    600:
                    601: def Substitute(f,xx,g) {
1.7       takayama  602:   local tmp, coeff0,ex,i,n,newex,ans;
1.1       maekawa   603:   if (IsInteger(f)) return(f);
1.7       takayama  604:   if (IsArray(f)) {
                    605:      n = Length(f);
                    606:      ans = NewVector(n);
                    607:      for (i=0; i<n; i++) {
                    608:        ans[i] = Substitute(f[i],xx,g);
                    609:      }
                    610:      return(ans);
                    611:   }
1.1       maekawa   612:   if (! IsPolynomial(f)) {
                    613:     k00_error("Substitute","The first argument must be polynomial.");
                    614:   }
                    615:   tmp = Coefficients(f,xx);
                    616:   coeff0 = tmp[1];
                    617:   ex = tmp[0];   /* [3, 2, 0] */
                    618:   n = Length(ex);
                    619:   newex = NewVector(n);
                    620:   if (n>0) { newex[n-1] = g^ex[n-1]; }
                    621:   for (i=n-2; i>=0; i--) {
                    622:     newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1]));
                    623:   }
                    624:   return(Cancel(coeff0*newex));
                    625: }
                    626: HelpAdd(["Substitute",
                    627: ["Substitute(f,xx,g) replaces << xx >> in << f >> by << g >>.",
                    628:   "This function takes coeffients of << f >> with respect to << xx >>",
                    629:   "and returns the inner product of the vector of coefficients and the vector",
                    630:   "of which elements are g^(corresponding exponent).",
                    631:   "Note that it may cause an unexpected result in non-commutative rings."
                    632: ]]);
                    633:
                    634: def Tag(f) {
                    635:   local ans;
                    636:   if (IsArray(f)) {
                    637:     return(Map(f,"Tag"));
                    638:   }else {
1.4       takayama  639:     ans = sm1(f," etag (universalNumber) dc ");
1.1       maekawa   640:     return(ans);
                    641:   }
                    642: }
                    643: HelpAdd(["Tag",
                    644: ["Tag(f) returns the datatype tags of f where",
                    645:  "5: string,  9: polynomial, 15: integer(big-num), 16: rational, ",
1.4       takayama  646:  "18:double, 257: Error ",
1.1       maekawa   647:  "Ex. Tag([Poly(\"0\"), 0]):"
                    648: ]]);
                    649:
1.4       takayama  650: def Error(s) {
                    651:   sm1(" s error ");
                    652: }
                    653: HelpAdd(["Error",
                    654: ["Error(s) causes an error and outputs a message s."]]);
1.1       maekawa   655:
                    656: OutputPrompt ;

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