Annotation of OpenXM/src/k097/help.k, Revision 1.12
1.12 ! takayama 1: /* $OpenXM: OpenXM/src/k097/help.k,v 1.11 2003/11/20 09:20:36 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++) {
1.9 takayama 26: item = Helplist[i,1];
1.1 maekawa 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++ ) {
1.9 takayama 51: keys = Append(keys,Helplist[i,1,0]);
1.1 maekawa 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).");
1.9 takayama 95: Println("A new help system can be used as man() or man(keyword).");
1.1 maekawa 96:
97: /* Println(keys); */
98: }
99:
100: def ShowKeyWordsOfSm1(ss) {
101: local i,j,n,keys,max,width,m,k,kk,tmp0;
102: Ln();
103: sm1(" /help_Sm1Macro @.usages def ");
104: n = Length(help_Sm1Macro);
105: keys = [" " ];
106: for (i=0; i< n; i++ ) {
107: keys = Append(keys,help_Sm1Macro[i,0]);
108: }
109: keys = sm1(keys," shell ");
110: n = Length(keys);
111: if (ss == "ALL") {
112: for (i=1; i<n; i++) {
113: tmp0 = keys[i];
114: Print("# "); Print(tmp0); Ln();
115: sm1(tmp0," usage "); Ln();
116: }
117: return(0);
118: }
119:
120: max = 0;
121: for (i=1; i<n; i++) {
122: if (Length(keys[i]) > max) {
123: max = Length(keys[i]);
124: }
125: }
126: /* Println(max); */
127: max = max+3;
128: width = 80;
129: m = 0;
130: while ((m*max) < 80) {
131: m = m+1;
132: }
133: k = 0; kk = 0;
134: for (i=1; i<n; i++) {
135: Print(keys[i]); kk = kk+1;
136: k = k+Length(keys[i]);
137: tmp0 = max-Length(keys[i]);
138: if (kk >= m) {
139: }else {
140: for (j=0; j < tmp0 ; j++) {
141: k = k+1;
142: Print(" ");
143: }
144: }
145: if (kk >= m) {
146: kk = 0; k=0; Ln();
147: }
148: }
149: Ln();
150: Ln();
151: Println("Type in (keyword) usage ; to see a help message.");
152:
153: /* Println(keys); */
154: }
155:
1.9 takayama 156: /* Start of HelpAdd */
157: HelpAdd(
158: ["Map",
159: ["Map(<<karg>>,<<func>>) applies the function <<func>> to the <<karg>> (string <<func>>).",
160: " Ex. Map([82,83,85],\"AsciiToString\"):"],
161: ["karg","func"],
162: null,
163: "apply a function to each element of a list."
164: ]);
165: HelpAdd(["Position",
166: ["Position(<<list>>,<<elem>>) returns the position p of the element <<elem>> in",
167: " the array <<list>>. If <<elem>> is not in <<list>>, it return -1",
168: " (array <<list>>).",
169: "Ex. Position([1,34,2],34): "],
170: ["list","elem"],
171: null,
172: "find a position of an element in a list."
173: ]);
174: HelpAdd(["StringToAsciiArray",
175: ["StringToAsciiArray(<<s>>) decomposes the string <<s>> into an array of ",
176: "ascii codes of <<s>>.",
177: "cf. AsciiToString."],
178: ["s"],
179: ["AsciiToString"],
180: "translate a string to an array of ascii codes."
181: ]);
182:
183: HelpAdd(["NewArray",
184: ["NewArray(<<n>>) returns an array of size integer <<n>>."],
185: ["n"],
186: ["NewMatrix"],
187: "it returns an array of a given size."
188: ]);
189: HelpAdd(["GetEnv",
190: ["GetEnv(<<s>>) returns the value of the environmental variable string <<s>>."],
191: ["s"],
192: null,
193: "value of an environmental variable."
194: ]);
195: HelpAdd(["Boundp",
196: ["Boundp(<<s>>) checks if the symbol <<s>> is bounded to a value or not (string <<s>>)."],
197: ["s"],
198: null,
199: "check if a symbol is assigned a value or not."
200: ]);
201: HelpAdd(["Rest",
202: ["Rest(<<a>>) returns the rest (cdr) of <<a>> (list <<a>>)."],
203: ["a"],
204: ["Append","Join"],
205: "it returns the rest of a given list."
206: ]);
207: HelpAdd(["GetPathName",
208: ["GetPathName(<<s>>) checks if the file <<s>> exists in the current directory or",
209: "in LOAD_K_PATH. If there exists, it returns the path name (string <<s>>)."],
210: ["s"],
211: ["GetEnv"],
212: "find a file in the search path."
213: ]);
214: HelpAdd(["Load_sm1",
215: ["Load_sm1(<<s>>,<<flag>>) loads a sm1 program from <<s>>[0], <<s>>[1], ....",
216: "If loading is succeeded, the already-loaded <<flag>> is set to true.",
217: "(list <<s>>, string <<flag>>)."],
218: ["s","flag"],
219: ["load"],
220: "load a sm1 program"
221: ]);
222: HelpAdd(["ReParse",
223: ["Reparse(<<obj>>): ",
224: "It parses the given object <<obj>> in the current ring."],
225: ["obj"],
226: ["Mapto","RingD"],
227: "parses a given object in the current ring."
228: ]);
229: HelpAdd(["Pmat",
230: ["Pmat(<<m>>): ",
231: "Print the array <<m>> in a pretty way."],
232: ["m"],
233: ["Println"],
234: "print an given array in a pretty way."
235: ]);
236: HelpAdd(["Tag",
237: ["Tag(<<f>>) returns the datatype tag of <<f>> where",
238: "0: null, 5: string, 6: array, 9: polynomial, 15: integer(big-num), ",
239: "16: rational, 18:double, 257: Error ",
240: "Ex. Tag([Poly(\"0\"), 0]):"],
241: ["f"],
242: ["Is*"],
243: "return the tag of a given object."
244: ]);
245: HelpAdd(["Error",
246: ["Error(<<s>>) causes an error and outputs a message <<s>>."],
247: ["s"],
248: null,
249: "cause an error."
250: ]);
251:
252: HelpAdd(["Help",
253: ["Help(<<key>>) or help(<<key>>) shows an explanation on the <<key>> (string <<key>>)."],
254: ["key"],
255: ["HelpAdd","help","man"],
256: "display a help message."
257: ]);
1.1 maekawa 258: HelpAdd(["HelpAdd",
1.9 takayama 259: ["HelpAdd([<<key>>,<<explanation>>]) (string <<key>>, string <<explanation>>)",
260: " or (string <<key>>, array <<explanation>>).",
261: " ",
262: "HelpAdd([<<key>>,<<explanation>>,<<category>>]) is used to specify ",
263: "the <<category>> of the topics."],
264: ["key","explanation"],
265: ["help","man"],
266: "Add a help message in the system."
267: ]);
268:
1.1 maekawa 269: HelpAdd(["load",
1.9 takayama 270: ["load(<<fname>>) loads the file << fname >>(string <<fname>>).",
271: "load <<fname>> loads the file << fname >>.",
272: "load[<<fname>>] loads the file << fname >> with the preprocessing by /lib/cpp."
273: ],
274: ["fname"],
275: ["Load_sm1"],
276: "load a given file."]);
277:
278: HelpAdd(["Ln","Print newline.",
279: [ ],
280: ["Print","Println"],
281: "print newline."]);
282: HelpAdd(["Println",
283: ["Println(<<f>>) prints <<f>> and goes to the new line."],
284: ["f"],
285: ["Ln","Print","Stderr."],
286: "display a given object with the newline."
287: ]);
288: HelpAdd(["Print",
289: ["Print(<<f>>) prints <<f>> without the newline."],
290: ["f"],
291: ["Println"],
292: "display a given object."
293: ]);
1.1 maekawa 294: HelpAdd(["Poly",
1.9 takayama 295: ["Poly(<<name>>) parses a given string <<name>> in the current ring ",
296: "and returns a polynomial."
297: ],
298: ["name"],
299: ["DC","PolyR","ReParse","RingD"],
300: "translate a string to a polynomial."
301: ]);
1.1 maekawa 302: HelpAdd(["PolyR",
1.9 takayama 303: ["PolyR(<<name>>,<<r>>) parses a string <<name>> in the ring <<r>> ",
304: "Ex. r = RingD(\"x,y\"); y = PolyR(\"x+2*y\",r); "],
305: ["name","r"],
306: ["Poly"],
307: "translate a string to a polynomial in a given ring."
308: ]);
1.1 maekawa 309: HelpAdd(["RingD",
1.9 takayama 310: ["RingD(<<names>>) defines a new ring of differential operators (string <<names>>).",
311: "RingD(<<names>>,<<weight_vector>>) defines a new ring with the weight vector",
312: "(string <<names>>, array <<weight_vector>>).",
313: "RingD(<<names>>,<<weight_vector>>,<<characteristic>>)",
314: "Dx is the associated variable to x where Dx*x - x*Dx = 1 holds.",
315: " Ex. RingD(\"x,y\",[[\"x\",2,\"y\",1]]) "],
316: ["names","weight_vector"],
317: ["GetRing","PolyR","ReParse","SetRing"],
318: "define a new ring of differential operators."
319: ]);
320: HelpAdd(["Reduction",
321: ["Reduction(<<f>>,<<G>>) returns the remainder and sygygies when
322: <<f>> is devided by <<G>> (polynomial <<f>>, array <<G>>)."],
323: ["f","g"],
324: ["Gb"],
325: "get the remainder and the quotients."
326: ]);
327: HelpAdd(["AddString","AddString(<<list>>) returns the concatnated string (array <<list>>).",
328: ["list"],
329: null,
330: "concatenate strings."
331: ]);
332: HelpAdd(["AsciiToString",
333: "AsciiToString(<<ascii_code>>) returns the string of which
334: ascii code is <<ascii_code>> (integer <<ascii_code>>).",
335: ["ascii_code"],
336: ["!ReservedNames","AddString","StringToAsciiArray"],
337: "translate from ascii code to a string."
338: ]);
339: HelpAdd(["ToString",
340: "ToString(<<obj>>) transforms the <<obj>> to a string.",
341: ["obj"],
342: ["DC"],
343: "translate a given object to a string."
344: ]);
345: HelpAdd(["Numerator",
346: "Numerator(<<f>>) returns the numerator of the rational <<f>>.",
347: ["f"],
348: ["Cancel","Denominator"],
349: "numerator"
350: ]);
351: HelpAdd(["Denominator",
352: "Denominator(<<f>>) returns the denominator of the rational <<f>>.",
353: ["f"],
354: ["Cancel","Numerator"],
355: "denominator"
356: ]);
1.7 takayama 357: HelpAdd(["Replace",
1.9 takayama 358: ["Replace(<<f>>,<<rule>>) rewrites <<f>> by the <<rule>> (polynomial <<f>>, array <<rule>>). ",
359: "Ex. RingD(\"x,y\"); Replace( (x+y)^3, [[x,Poly(\"1\")]])"],
360: ["f","rule"],
361: ["replace (sm1)"],
362: "substitute variables by given values"
363: ]);
1.1 maekawa 364: HelpAdd(["SetRingVariables",
1.9 takayama 365: "Set the generators of the current ring as global variables.
366: You do not need explicitly call this function which is called from RingD.
367: cf. RingD(), Poly(), PolyR()",
368: [ ],
369: ["RingD"],
370: " "
371: ]);
372: HelpAdd(["Append",
373: "Append([<<f1>>,...,<<fn>>],<<g>>) returns the list [<<f1>>,...,<<fn>>,<<g>>]",
374: ["f1","fn","g"],
375: ["Join","NewArray","Rest"],
376: "append two lists or arrays."
377: ]);
1.1 maekawa 378: HelpAdd(["Join",
1.9 takayama 379: "Join([<<f1>>,...,<<fn>>],[<<g1>>,...,<<gm>>]) returns the list
380: [<<f1>>,...,<<fn>>,<<g1>>,...,<<gm>>]",
381: ["f1","fn","g1","gm"],
382: ["Append","NewArray","Rest"],
383: "join two lists or arrays"
384: ]);
1.1 maekawa 385:
1.8 takayama 386: HelpAdd(["!ReservedNames",
1.1 maekawa 387: ["The names k00*, K00*, sm1* , arg1,arg2,arg3,arg4,....," ,
388: "Helplist, Arglist, FunctionValue,",
1.9 takayama 389: "@@*, db.*, k.*, tmp002*, tmp00* are used for system functions.",
390: "Percent, LeftBracket, RightBracket, Dollar, Newline are constants"],
391: null,
392: null,
393: "reserved symbols."
394: ]);
1.1 maekawa 395:
396: HelpAdd(["IntegerToSm1Integer",
1.9 takayama 397: "IntegerToSm1Integer(<<i>>) translates integer <<i>>
398: to sm1 integer (integer <<i>>).",
399: ["i"],
400: null,
401: "translates integer to 32 bit integer (sm1 integer)"
402: ]);
403: HelpAdd(["true","true returns sm1 integer 1.",null,null," "]);
404: HelpAdd(["false","false returns sm1 integer 0.",null,null," "]);
1.1 maekawa 405: HelpAdd(["IsArray",
1.9 takayama 406: ["If <<f>> is an array (or list) object, then IsArray(<<f>>) returns true,",
407: "else IsArray(<<f>>) returns false."],
408: ["f"],
409: ["Is*","Tag"],
410: "check if an given object is an array."
411: ]);
1.1 maekawa 412:
413: HelpAdd(["Init_w",
1.9 takayama 414: ["Init_w(<<f>>,<<vars>>,<<w>>) returns the initial terms with respect to the",
1.1 maekawa 415: "weight vector <<w>> (array of integer) of the polynomial <<f>>",
416: "(polynomial). Here, <<f>> is regarded as a polynomial with respect",
417: "to the variables <<vars>> (array of polynomials).",
1.9 takayama 418: "Ex. RingD(\"x,y\"); Init_w(x^2+y^2+x,[x,y],[1,1]):"],
419: ["f","vars","w"],
420: ["Gb","Init"],
421: "return the initial terms."
422: ]);
1.1 maekawa 423:
424:
425: HelpAdd(["Groebner",
1.9 takayama 426: ["Groebner(<<input>>) returns Groebner basis of the left ideal or the submodule",
1.1 maekawa 427: "defined by <<input>> (array of polynomials)",
428: "The order is that of the ring to which each element of <<input>>",
429: "belongs.",
430: "The input is automatically homogenized.",
1.9 takayama 431: "Ex. RingD(\"x,y\",[[\"x\", 10, \"y\", 1]]);",
432: " Groebner([Poly(\" x^2+y^2-4\"),Poly(\" x*y-1 \")]):",
433: "cf. RingD, Homogenize"],
434: ["input"],
435: ["Gb","Init_w","RingD","groebner (sm1)"],
436: "compute the Grobner basis."
437: ]);
1.1 maekawa 438:
439:
440: HelpAdd(["RingPoly",
1.9 takayama 441: ["RingPoly(<<names>>) defines a ring of polyomials (string <<names>>).",
1.1 maekawa 442: "The names of variables of that ring are <<names>> and ",
443: "the homogenization variable h.",
444: "cf. SetRingVariables, RingD",
1.9 takayama 445: "Ex. R=RingPoly(\"x,y\");",
1.1 maekawa 446: " ",
1.9 takayama 447: "RingPoly(<<names>>,<<weight_vector>>) defines a ring of polynomials",
448: "with the order defined by the <<weight_vector>>",
449: "(string <<names>>, array of array <<weight_vector>>).",
450: "RingPoly(<<names>>,<<weight_vector>>,<<characteristic>>)",
1.1 maekawa 451: "Example: R=RingPoly(\"x,y\",[[\"x\",10,\"y\",1]]);",
1.9 takayama 452: " (x+y)^10: "],
453: ["names","weight_vector"],
454: ["GetRing","RingD","SetRing"],
455: "define a ring of polynomials."
456: ]);
1.1 maekawa 457:
458:
459: HelpAdd(["CancelNumber",
1.9 takayama 460: ["CancelNumber(<<rn>>) reduces the rational number <<rn>>",
461: "(rational <<rn>>).",
462: "Ex. CancelNumber( 2/6 ) : "],
463: ["rn"],
464: ["Cancel"],
465: "factor out the greatest common divisor."
466: ]);
1.1 maekawa 467:
468: HelpAdd(["IsString",
1.9 takayama 469: ["IsString(<<obj>>) returns true if << obj >> is a string (object <<obj>>).",
470: "Ex. if (IsString(\"abc\")) Println(\"Hello\"); ;"],
471: ["obj"],
472: ["DC","Is*","Tag"],
473: "check if a given object is a string."
474: ]);
1.1 maekawa 475:
1.6 takayama 476: HelpAdd(["IsRing",
1.9 takayama 477: ["IsRing(<<obj>>) returns true if << obj >> is a ring (object <<obj>>)."
478: ],
479: ["obj"],
480: ["DC","Is*","Tag"],
481: "check if a given object is a ring."
482: ]);
1.6 takayama 483:
1.1 maekawa 484:
485: HelpAdd(["IsSm1Integer",
1.9 takayama 486: ["IsSm1Integer(<<obj>>) returns true if << obj >> is an integer of sm1(object <<obj>>)."],
487: ["obj"],
488: ["DC","Is*","Tag"],
489: "check if a given object is a 32 bit integer."
490: ]);
1.1 maekawa 491:
492: HelpAdd(["sm1",
1.9 takayama 493: ["sm1(<<arg1>>,<<arg2>>,...) is used to embed sm1 native code in the kxx program.",
494: "Ex. sm1( 2, 2, \" add print \"); ",
495: "Ex. def myadd(a,b) { sm1(\" a b add /FunctionValue set \"); }" ],
496: ["arg1","arg2"],
497: ["usage (sm1)"],
498: "execute sm1 commands"
499: ]);
1.1 maekawa 500:
501: HelpAdd(["DC",
1.9 takayama 502: ["DC(<<obj>>,<<key>>) converts << obj >> to a new object in the primitive",
503: "class << key >> (object <<obj>>, string <<key>>)",
504: "Ex. DC(\" (x+1)^10 \", \"polynomial\"): "],
505: ["obj","key"],
506: ["ToString"],
507: "translate data types."
508: ]);
1.1 maekawa 509:
510: HelpAdd(["Length",
1.9 takayama 511: ["Length(<<vec>>) returns the length of the array << vec >>",
512: "(array <<vec>>)"],
513: ["vec"],
514: null,
515: "length of a given array or a list."
516: ]);
1.1 maekawa 517:
518: HelpAdd(["Transpose",
1.10 takayama 519: ["Transpose(<<m>>.) return the transpose of the matrix << m >>",
1.9 takayama 520: "(array of array <<m>>)."],
521: ["m"],
522: ["NewMatrix"],
523: "transposition"
524: ]);
1.1 maekawa 525:
526: HelpAdd(["Save",
1.9 takayama 527: ["Save(<<obj>>) appends << obj >> to the file sm1out.txt (object <<obj>>)."],
528: ["obj"],
529: null,
530: "write a given object to a file."
531: ]);
1.1 maekawa 532:
533: HelpAdd(["Coefficients",
1.9 takayama 534: ["Coefficients(<<f>>,<<v>>) returns [exponents, coefficients] of << f >>",
1.1 maekawa 535: "with respect to the variable << v >>",
1.9 takayama 536: "(polynomial <<f>>,<<v>>).",
537: "Ex. Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "],
538: ["f","v"],
539: ["Exponent","Init","Init_w"],
540: "get the exponents and coefficients."
541: ]);
1.1 maekawa 542:
543: HelpAdd(["System",
1.9 takayama 544: ["System(<<comm>>) executes the unix system command << comm >>",
545: "(string <<comm>>)",
546: "Ex. System(\"ls\");"],
547: ["comm"],
548: null,
549: "call the unix shell."
550: ]);
1.1 maekawa 551:
552: HelpAdd(["Exponent",
1.9 takayama 553: ["Expoent(<<f>>,<<vars>>) returns the vector of exponents of the polynomial <<f>>",
554: "Ex. Exponent( x^2*y-1,[x,y])"],
555: ["f","vars"],
556: ["Coefficients"],
557: "exponents of a given polynomial."
558: ]);
1.1 maekawa 559:
560: HelpAdd(["Protect",
1.9 takayama 561: ["Protect(<<name>>) protects the symbol <<name>> (string)",
562: "Protect(<<name>>,<<level>>) protects the symbol <<name>> (string) with ",
563: "<<level>> "],
564: ["name","level"],
565: ["extension (sm1)"],
566: "add read-only property for a given variable."
567: ]);
1.1 maekawa 568:
569: HelpAdd(["IsPolynomial",
1.9 takayama 570: ["IsPolynomial(<<f>>) returns true if <<f>> (object) is a polynomial."],
571: ["obj"],
572: ["DC","Is*","Tag"],
573: "check if a given object is a polynomial."
1.11 takayama 574: ]);
575:
576: HelpAdd(["QuoteMode",
577: ["QuoteMode(1) sets the parser in the quotemode; if unknown function symbol",
578: "comes, it automatically translates the expression into a tree.",
1.12 ! takayama 579: "Example 1: class polymake extends PrimitiveObject {local ; def hogera() { return(1);} } ",
! 580: " QuoteMode(1); polymake.foo(1,2): ",
! 581: "Example 2: polymake=\"polymake\"; ",
1.11 takayama 582: " QuoteMode(1); polymake.foo(1,2): ",
583: "QuoteMode(0) turns off the quotemode."],
584: ["Tag"],
585: "Change into the quote mode."
1.9 takayama 586: ]);
1.1 maekawa 587:
588:
589:
590: /* -----------------------------------------------
591: functions on tests. */
592: /* ------------ Developping functions --------------------- */
593:
594: def RingPoly(vList,weightMatrix,pp) {
595: local new0,tmp,size,n,i,j,newtmp,ringpp,argsize;
596: argsize = Length(Arglist);
597: if (argsize == 1) {
598: sm1("[", vList,
599: "ring_of_polynomials ( ) elimination_order 0 ] define_ring
600: /tmp set ");
1.3 takayama 601: SetRingVariables();
1.1 maekawa 602: return(tmp);
603: } else ;
604: if (argsize == 2) {
605: pp = 0;
606: }
607: pp = IntegerToSm1Integer(pp);
608: size = Length(weightMatrix);
609: new0 = NewVector(size);
610: sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def ");
611: sm1(" 0 @@@.indexMode ");
612: for (i=0; i<size; i++) {
613: tmp = weightMatrix[i];
614: n = Length(tmp);
615: newtmp = NewVector(n);
616: for (j=1; j<n; j = j+2) {
617: newtmp[j-1] = tmp[j-1];
618: newtmp[j] = IntegerToSm1Integer( tmp[j] );
619: }
620: new0[i] = newtmp;
621: }
1.3 takayama 622: SetRingVariables();
1.1 maekawa 623: ringpp =
624: sm1("[", vList,
625: "ring_of_polynomials ", new0, " weight_vector", pp, " ] define_ring");
626: sm1(" @@@.indexMode.flag.save @@@.indexMode ");
627: return( ringpp );
628: }
629:
630: def IsString(ob) {
631: sm1(ob , " isString /FunctionValue set ");
632: }
633:
634: def IsSm1Integer(ob) {
635: sm1(ob , " isInteger /FunctionValue set ");
1.6 takayama 636: }
637:
638: def IsRing(ob) {
639: sm1(ob , " isRing /FunctionValue set ");
1.1 maekawa 640: }
641:
642:
643: def CancelNumber(rn) {
644: local tmp;
645: sm1(" [(cancel) ",rn," ] mpzext /tmp set ");
646: if (IsInteger(tmp)) return(tmp);
647: sm1(" tmp (denominator) dc (1).. eq { /FunctionValue tmp (numerator) dc def} { /FunctionValue tmp def } ifelse ");
648: }
649:
1.5 takayama 650: def DC_polynomial(obj) {
651: return(DC(obj,"polynomial"));
652: }
1.1 maekawa 653: def DC(obj,key) {
1.5 takayama 654: if (IsArray(obj) && key=="polynomial") {
655: return(Map(obj,"DC_polynomial"));
656: }
1.1 maekawa 657: if (key == "string") { return(ToString(obj)); }
658: else if (key == "integer") { key = "universalNumber"; }
659: else if (key == "sm1integer") { key = "integer"; }
660: else if (key == "polynomial") { key = "poly"; }
661: else ;
662: sm1( obj , key, " data_conversion /FunctionValue set ");
663: }
664:
665: def Transpose(m) {
666: sm1(m, " transpose /FunctionValue set ");
667: }
668:
669: def Save(obj) {
670: sm1(obj, " output ");
671: }
672:
673:
674: def void System(comm) {
675: sm1(comm, " system ");
676: }
677:
678:
679: def IsReducible(f,g) {
680: sm1("[ (isReducible) ",f,g," ] gbext /FunctionValue set ");
681: }
682:
683: def IsPolynomial(f) {
684: sm1(" f isPolynomial /FunctionValue set ");
685: }
686: sm1(" /k00.toric0.mydegree {2 1 roll degree} def ");
687: def Exponent(f,vars) {
688: local n,i,ans;
689: if (f == Poly("0")) return([ ] );
690: sm1(f," /ff.tmp set ", vars ,
691: " {ff.tmp k00.toric0.mydegree (universalNumber) dc }map /FunctionValue set ");
692: }
693: def void Protect(name,level) {
694: local n,str;
695: n = Length(Arglist);
696: if (n == 1) {
697: level = 1;
698: str = AddString(["[(chattr) ",ToString(level)," /",name," ",
699: " ] extension pop "]);
700: /* Println(str); */
701: sm1(" [(parse) ",str ," ] extension pop ");
702: } else if (n ==2) {
703: str = AddString(["[(chattr) ",ToString(level)," /",name," ",
704: " ] extension pop "]);
705: /* Println(str); */
706: sm1(" [(parse) ",str ," ] extension pop ");
707: } else {
708: k00_error("Protect","Arguments must be one or two. ");sm1(" error ");
709: }
710: }
711:
712: def void k00_error(name,msg) {
713: Print("Error in "); Print(name); Print(". ");
714: Println(msg);
715: }
716:
717: def Init(f) {
718: if (IsArray(f)) {
719: return(Map(f,"Init"));
720: } else if (IsPolynomial(f)) {
721: sm1(f," init /FunctionValue set ");
722: } else {
723: k00_error("Init","Argment must be polynomial or an array of polynomials");
724: sm1(" error ");
725: }
726: }
727: HelpAdd(["Init",
1.9 takayama 728: ["Init(<<f>>) returns the initial term of the polynomial <<f>> (polynomial)",
729: "Init(<<list>>) returns the array of initial terms of the array of polynomials",
730: "<< list >> (array)"],
731: ["f"],
732: ["Init_w"],
733: "return the initial term."
734: ]);
1.1 maekawa 735:
736: HelpAdd(["NewMatrix",
1.9 takayama 737: ["NewMatrix(<<m>>,<<n>>) returns the (<<m>>,<<n>>)-matrix (array) with the entries 0."],
738: ["m","n"],
739: ["NewArray"],
740: "generate a matrix of a given size."
741: ]);
1.1 maekawa 742:
743: def Eliminatev(list,var) /* [(x-y). (y-z).] [(z) ] */
744: {
745: sm1(list, var, " eliminatev /FunctionValue set ");
746: }
747: HelpAdd(["Eliminatev",
1.9 takayama 748: ["Eliminatev(<<list>>,<<var>>) prunes polynomials in << list >>(array of polynomials)",
1.1 maekawa 749: "which contains the variables in << var >> ( array of strings )",
1.9 takayama 750: "Ex. Eliminatev([Poly(\" x+h \"),Poly(\" x \")],[ \"h\" ]): "],
751: ["list","var"],
752: ["eliminatev (sm1)"],
753: " "
754: ]);
1.1 maekawa 755:
756: def ReducedBase(base) {
757: sm1( base, " reducedBase /FunctionValue set ");
758: }
759: HelpAdd(["ReducedBase",
1.9 takayama 760: ["ReducedBase(<<base>>) prunes redundant elements in the Grobner basis <<base>> (array)."
761: ],
762: ["base"],
763: ["Gb","Groebner"],
764: "remove unnecessary elements."
765: ]);
1.1 maekawa 766:
767:
768: def Coefficients(f,v) {
769: local ans,exp;
770: ans = sm1(f,v, " coefficients ");
771: exp = ans[0];
772: exp = sm1(exp," { (universalNumber) dc } map ");
773: return([exp,ans[1]]);
774: }
775:
776: def IsInteger(a) {
777: sm1(a , " isUniversalNumber /FunctionValue set ");
778: }
779: HelpAdd(["IsInteger",
1.9 takayama 780: ["IsInteger(<<a>>) returns true if << a >> is an integer (object <<a>>).",
1.1 maekawa 781: "It returns false if << a >> is not.",
1.9 takayama 782: "cf. IsSm1Integer"],
783: ["a"],
784: ["DC","Is*","Tag"],
785: "check if a given object is an integer."
786: ]);
1.1 maekawa 787:
788: def IsRational(a) {
789: sm1(a , " isRational /FunctionValue set ");
790: }
791: HelpAdd(["IsRational",
1.9 takayama 792: ["IsRational(<<a>>) returns true if << a >> is a rational (object <<a>>).",
793: "It returns false if << a >> is not."],
794: ["a"],
795: ["DC","Is*","Tag"],
796: "check if a given object is a rational."
797: ]);
1.1 maekawa 798:
799:
800: def IsDouble(a) {
801: sm1(a , " isDouble /FunctionValue set ");
802: }
803: HelpAdd(["IsDouble",
1.9 takayama 804: ["IsDouble(<<a>>) returns true if << a >> is a double (object <<a>>).",
805: "It returns false if << a >> is not."],
806: ["a"],
807: ["DC","Is*","Tag"],
808: "check if a given object is double."
809: ]);
1.1 maekawa 810:
811:
812: sm1(" /cs { this [ ] Cleards } def ");
813:
814:
815: def Init_w(f,vars,weight) {
816: local w,w2,w3,ans,i,n;
817: if (f == Poly("0")) return( Poly("0") );
818: w = Map(vars,"ToString");
819: w2 = sm1(weight," {$integer$ data_conversion} map ");
820: n = Length(w);
821: w3 = NewArray(n*2);
822: for (i=0; i<n ; i++) {
823: w3[2*i] = w[i]; w3[2*i+1] = w2[i];
824: }
825: ans = sm1(f,w3, " weightv init ");
826: return(ans);
827: }
828:
829: HelpAdd(["Mapto",
1.9 takayama 830: ["Mapto(<<obj>>,<<ring>>) parses << obj >> as elements of the << ring >>.",
1.1 maekawa 831: "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).",
832: "Ex. R = RingD(\"x,y\"); SetRingVariables();",
833: " f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ",
1.9 takayama 834: " f2 = Mapto(f,R2); f2: "],
835: ["obj","ring"],
836: ["ReParse"],
837: "parse a polynomial in a given ring."
838: ]);
1.1 maekawa 839:
840: def Mapto(obj,ring) {
841: local ans,i,n;
842: if (IsArray(obj)) {
843: n = Length(obj);
844: ans = Map(obj,"ToString");
845: for (i=0; i<n; i++) {
846: ans[i] = PolyR(ans[i],ring);
847: }
848: }else{
849: ans = ToString(obj);
850: ans = PolyR(ans,ring);
851: }
852: return(ans);
853: }
854:
855:
856: HelpAdd(["ToDouble",
1.9 takayama 857: ["ToDouble(<<f>>) translates << f >> into double when it is possible",
1.1 maekawa 858: "object << f >>.",
1.9 takayama 859: "Ex. ToDouble([1,1/2,[5]]): "],
860: ["f"],
861: ["DC","Is*","Tag"],
862: "translate a given object to double."
863: ]);
1.1 maekawa 864: def k00_toDouble(f) { return(DC(f,"double")); }
865: def ToDouble(f) {
866: if (IsArray(f)) return(Map(f,"ToDouble"));
867: if (IsDouble(f)) return(f);
868: return(k00_toDouble(f));
869: }
870:
871:
872:
873: def Mod(f,n) {
874: if (IsPolynomial(f)) {
875: sm1("[(mod) ",f,n,"] gbext /FunctionValue set ");
876: } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); }
877: }
878: HelpAdd(["Mod",
1.9 takayama 879: ["Mod(<<f>>,<<p>>) returns f modulo <<n>> where << f >> (polynomial) and",
880: " << p >> (integer). "],
881: ["f","p"],
882: ["gbext (sm1)"],
883: "modulo"
884: ]);
1.1 maekawa 885:
886:
887:
888:
889: def Characteristic(ringp) {
890: local r,p;
891: r = sm1(" [(CurrentRingp)] system_variable ");
892: sm1("[(CurrentRingp) ",ringp, " ] system_variable ");
893: p = sm1("[(P)] system_variable (universalNumber) dc ");
894: sm1("[(CurrentRingp) ",r, " ] system_variable ");
895: return(p);
896: }
897: HelpAdd(["Characteristic",
1.9 takayama 898: ["Characteristic(<<ring>>) returns the characteristic of the << ring >>."],
899: ["ring"],
900: ["GetRing","RingD","RingPoly","SetRing"],
901: "get the characteristic of a given ring."
902: ]);
1.1 maekawa 903:
904: def IsConstant(f) {
905: if (Length(f) > 1) return(false);
906: sm1("[(isConstant) ", f," ] gbext /FunctionValue set ");
907: }
908: HelpAdd(["IsConstant",
1.9 takayama 909: ["IsConstant(<<f>>) returns true if the polynomial << f >> is a constant."
910: ],
911: ["f"],
912: ["DC","Is*","Tag"],
913: "check if a given object is a constant."
914: ]);
1.1 maekawa 915:
916: Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h");
917:
918: def Substitute(f,xx,g) {
1.7 takayama 919: local tmp, coeff0,ex,i,n,newex,ans;
1.1 maekawa 920: if (IsInteger(f)) return(f);
1.7 takayama 921: if (IsArray(f)) {
922: n = Length(f);
923: ans = NewVector(n);
924: for (i=0; i<n; i++) {
925: ans[i] = Substitute(f[i],xx,g);
926: }
927: return(ans);
928: }
1.1 maekawa 929: if (! IsPolynomial(f)) {
930: k00_error("Substitute","The first argument must be polynomial.");
931: }
932: tmp = Coefficients(f,xx);
933: coeff0 = tmp[1];
934: ex = tmp[0]; /* [3, 2, 0] */
935: n = Length(ex);
936: newex = NewVector(n);
937: if (n>0) { newex[n-1] = g^ex[n-1]; }
938: for (i=n-2; i>=0; i--) {
939: newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1]));
940: }
941: return(Cancel(coeff0*newex));
942: }
943: HelpAdd(["Substitute",
1.9 takayama 944: ["Substitute(<<f>>,<<xx>>,<<g>>) replaces << xx >> in << f >> by << g >>.",
1.1 maekawa 945: "This function takes coeffients of << f >> with respect to << xx >>",
946: "and returns the inner product of the vector of coefficients and the vector",
947: "of which elements are g^(corresponding exponent).",
948: "Note that it may cause an unexpected result in non-commutative rings."
1.9 takayama 949: ],
950: ["f","xx","g"],
951: ["Replace"],
952: " "
953: ]);
954:
955:
956: HelpAdd(["OutputPrompt",
957: ["Output the prompt. Files should end with this command."],
958: null,
959: null,
960: "output the prompt."]);
961:
962: Protect("Percent");
963: Protect("LeftBracket");
964: Protect("RightBracket");
965: Protect("Dollar");
966: Protect("Newline");
1.1 maekawa 967:
968: OutputPrompt ;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>