/* $OpenXM: OpenXM/src/k097/help.k,v 1.12 2003/11/20 09:24:35 takayama Exp $ */ if (K00_verbose) Println("help.k: 8/6, 1996 --- 8/7, 1996. 3/6, 1997 --- 12/21, 1997."); def help(x) { if (Length(Arglist) < 1) { ShowKeyWords(" "); } else { Help(x); } } def Help(key) { local n,i,item,m,item1,j; if (Length(Arglist) < 1) { ShowKeyWords(" "); return( [ ] ); } if (key == "ALL") { ShowKeyWords("ALL"); return(0); } n = Length(Helplist); PSfor (i=0; i> could not be found."); return([ ]); } def ShowKeyWords(ss) { local i,j,n,keys,max,width,m,k,kk,tmp0; Ln(); n = Length(Helplist); keys = [" " ]; /* This is a gate keeper for shell. */ PSfor (i=0; i< n; i++ ) { keys = Append(keys,Helplist[i,1,0]); } keys = sm1(keys," shell "); n = Length(keys); if (ss == "ALL") { PSfor (i=1; i max) { max = Length(keys[i]); } } /* Println(max); */ max = max+3; width = 80; m = 0; while ((m*max) < 80) { m = m+1; } if (m > 1) m = m-1; k = 0; kk = 0; PSfor (i=1; i= m) { kk = 0; k=0; Ln(); } } Ln(); Println("Type in Help(keyword); to see a help message (string keyword)."); Println("A new help system can be used as man() or man(keyword)."); /* Println(keys); */ } def ShowKeyWordsOfSm1(ss) { local i,j,n,keys,max,width,m,k,kk,tmp0; Ln(); sm1(" /help_Sm1Macro @.usages def "); n = Length(help_Sm1Macro); keys = [" " ]; for (i=0; i< n; i++ ) { keys = Append(keys,help_Sm1Macro[i,0]); } keys = sm1(keys," shell "); n = Length(keys); if (ss == "ALL") { for (i=1; i max) { max = Length(keys[i]); } } /* Println(max); */ max = max+3; width = 80; m = 0; while ((m*max) < 80) { m = m+1; } k = 0; kk = 0; for (i=1; i= m) { }else { for (j=0; j < tmp0 ; j++) { k = k+1; Print(" "); } } if (kk >= m) { kk = 0; k=0; Ln(); } } Ln(); Ln(); Println("Type in (keyword) usage ; to see a help message."); /* Println(keys); */ } /* Start of HelpAdd */ HelpAdd( ["Map", ["Map(<>,<>) applies the function <> to the <> (string <>).", " Ex. Map([82,83,85],\"AsciiToString\"):"], ["karg","func"], null, "apply a function to each element of a list." ]); HelpAdd(["Position", ["Position(<>,<>) returns the position p of the element <> in", " the array <>. If <> is not in <>, it return -1", " (array <>).", "Ex. Position([1,34,2],34): "], ["list","elem"], null, "find a position of an element in a list." ]); HelpAdd(["StringToAsciiArray", ["StringToAsciiArray(<>) decomposes the string <> into an array of ", "ascii codes of <>.", "cf. AsciiToString."], ["s"], ["AsciiToString"], "translate a string to an array of ascii codes." ]); HelpAdd(["NewArray", ["NewArray(<>) returns an array of size integer <>."], ["n"], ["NewMatrix"], "it returns an array of a given size." ]); HelpAdd(["GetEnv", ["GetEnv(<>) returns the value of the environmental variable string <>."], ["s"], null, "value of an environmental variable." ]); HelpAdd(["Boundp", ["Boundp(<>) checks if the symbol <> is bounded to a value or not (string <>)."], ["s"], null, "check if a symbol is assigned a value or not." ]); HelpAdd(["Rest", ["Rest(<>) returns the rest (cdr) of <> (list <>)."], ["a"], ["Append","Join"], "it returns the rest of a given list." ]); HelpAdd(["GetPathName", ["GetPathName(<>) checks if the file <> exists in the current directory or", "in LOAD_K_PATH. If there exists, it returns the path name (string <>)."], ["s"], ["GetEnv"], "find a file in the search path." ]); HelpAdd(["Load_sm1", ["Load_sm1(<>,<>) loads a sm1 program from <>[0], <>[1], ....", "If loading is succeeded, the already-loaded <> is set to true.", "(list <>, string <>)."], ["s","flag"], ["load"], "load a sm1 program" ]); HelpAdd(["ReParse", ["Reparse(<>): ", "It parses the given object <> in the current ring."], ["obj"], ["Mapto","RingD"], "parses a given object in the current ring." ]); HelpAdd(["Pmat", ["Pmat(<>): ", "Print the array <> in a pretty way."], ["m"], ["Println"], "print an given array in a pretty way." ]); HelpAdd(["Tag", ["Tag(<>) returns the datatype tag of <> where", "0: null, 5: string, 6: array, 9: polynomial, 15: integer(big-num), ", "16: rational, 18:double, 257: Error ", "Ex. Tag([Poly(\"0\"), 0]):"], ["f"], ["Is*"], "return the tag of a given object." ]); HelpAdd(["Error", ["Error(<>) causes an error and outputs a message <>."], ["s"], null, "cause an error." ]); HelpAdd(["Help", ["Help(<>) or help(<>) shows an explanation on the <> (string <>)."], ["key"], ["HelpAdd","help","man"], "display a help message." ]); HelpAdd(["HelpAdd", ["HelpAdd([<>,<>]) (string <>, string <>)", " or (string <>, array <>).", " ", "HelpAdd([<>,<>,<>]) is used to specify ", "the <> of the topics."], ["key","explanation"], ["help","man"], "Add a help message in the system." ]); HelpAdd(["load", ["load(<>) loads the file << fname >>(string <>).", "load <> loads the file << fname >>.", "load[<>] loads the file << fname >> with the preprocessing by /lib/cpp." ], ["fname"], ["Load_sm1"], "load a given file."]); HelpAdd(["Ln","Print newline.", [ ], ["Print","Println"], "print newline."]); HelpAdd(["Println", ["Println(<>) prints <> and goes to the new line."], ["f"], ["Ln","Print","Stderr."], "display a given object with the newline." ]); HelpAdd(["Print", ["Print(<>) prints <> without the newline."], ["f"], ["Println"], "display a given object." ]); HelpAdd(["Poly", ["Poly(<>) parses a given string <> in the current ring ", "and returns a polynomial." ], ["name"], ["DC","PolyR","ReParse","RingD"], "translate a string to a polynomial." ]); HelpAdd(["PolyR", ["PolyR(<>,<>) parses a string <> in the ring <> ", "Ex. r = RingD(\"x,y\"); y = PolyR(\"x+2*y\",r); "], ["name","r"], ["Poly"], "translate a string to a polynomial in a given ring." ]); HelpAdd(["RingD", ["RingD(<>) defines a new ring of differential operators (string <>).", "RingD(<>,<>) defines a new ring with the weight vector", "(string <>, array <>).", "RingD(<>,<>,<>)", "Dx is the associated variable to x where Dx*x - x*Dx = 1 holds.", " Ex. RingD(\"x,y\",[[\"x\",2,\"y\",1]]) "], ["names","weight_vector"], ["GetRing","PolyR","ReParse","SetRing"], "define a new ring of differential operators." ]); HelpAdd(["Reduction", ["Reduction(<>,<>) returns the remainder and sygygies when <> is devided by <> (polynomial <>, array <>)."], ["f","g"], ["Gb"], "get the remainder and the quotients." ]); HelpAdd(["AddString","AddString(<>) returns the concatnated string (array <>).", ["list"], null, "concatenate strings." ]); HelpAdd(["AsciiToString", "AsciiToString(<>) returns the string of which ascii code is <> (integer <>).", ["ascii_code"], ["!ReservedNames","AddString","StringToAsciiArray"], "translate from ascii code to a string." ]); HelpAdd(["ToString", "ToString(<>) transforms the <> to a string.", ["obj"], ["DC"], "translate a given object to a string." ]); HelpAdd(["Numerator", "Numerator(<>) returns the numerator of the rational <>.", ["f"], ["Cancel","Denominator"], "numerator" ]); HelpAdd(["Denominator", "Denominator(<>) returns the denominator of the rational <>.", ["f"], ["Cancel","Numerator"], "denominator" ]); HelpAdd(["Replace", ["Replace(<>,<>) rewrites <> by the <> (polynomial <>, array <>). ", "Ex. RingD(\"x,y\"); Replace( (x+y)^3, [[x,Poly(\"1\")]])"], ["f","rule"], ["replace (sm1)"], "substitute variables by given values" ]); HelpAdd(["SetRingVariables", "Set the generators of the current ring as global variables. You do not need explicitly call this function which is called from RingD. cf. RingD(), Poly(), PolyR()", [ ], ["RingD"], " " ]); HelpAdd(["Append", "Append([<>,...,<>],<>) returns the list [<>,...,<>,<>]", ["f1","fn","g"], ["Join","NewArray","Rest"], "append two lists or arrays." ]); HelpAdd(["Join", "Join([<>,...,<>],[<>,...,<>]) returns the list [<>,...,<>,<>,...,<>]", ["f1","fn","g1","gm"], ["Append","NewArray","Rest"], "join two lists or arrays" ]); HelpAdd(["!ReservedNames", ["The names k00*, K00*, sm1* , arg1,arg2,arg3,arg4,....," , "Helplist, Arglist, FunctionValue,", "@@*, db.*, k.*, tmp002*, tmp00* are used for system functions.", "Percent, LeftBracket, RightBracket, Dollar, Newline are constants"], null, null, "reserved symbols." ]); HelpAdd(["IntegerToSm1Integer", "IntegerToSm1Integer(<>) translates integer <> to sm1 integer (integer <>).", ["i"], null, "translates integer to 32 bit integer (sm1 integer)" ]); HelpAdd(["true","true returns sm1 integer 1.",null,null," "]); HelpAdd(["false","false returns sm1 integer 0.",null,null," "]); HelpAdd(["IsArray", ["If <> is an array (or list) object, then IsArray(<>) returns true,", "else IsArray(<>) returns false."], ["f"], ["Is*","Tag"], "check if an given object is an array." ]); HelpAdd(["Init_w", ["Init_w(<>,<>,<>) returns the initial terms with respect to the", "weight vector <> (array of integer) of the polynomial <>", "(polynomial). Here, <> is regarded as a polynomial with respect", "to the variables <> (array of polynomials).", "Ex. RingD(\"x,y\"); Init_w(x^2+y^2+x,[x,y],[1,1]):"], ["f","vars","w"], ["Gb","Init"], "return the initial terms." ]); HelpAdd(["Groebner", ["Groebner(<>) returns Groebner basis of the left ideal or the submodule", "defined by <> (array of polynomials)", "The order is that of the ring to which each element of <>", "belongs.", "The input is automatically homogenized.", "Ex. RingD(\"x,y\",[[\"x\", 10, \"y\", 1]]);", " Groebner([Poly(\" x^2+y^2-4\"),Poly(\" x*y-1 \")]):", "cf. RingD, Homogenize"], ["input"], ["Gb","Init_w","RingD","groebner (sm1)"], "compute the Grobner basis." ]); HelpAdd(["RingPoly", ["RingPoly(<>) defines a ring of polyomials (string <>).", "The names of variables of that ring are <> and ", "the homogenization variable h.", "cf. SetRingVariables, RingD", "Ex. R=RingPoly(\"x,y\");", " ", "RingPoly(<>,<>) defines a ring of polynomials", "with the order defined by the <>", "(string <>, array of array <>).", "RingPoly(<>,<>,<>)", "Example: R=RingPoly(\"x,y\",[[\"x\",10,\"y\",1]]);", " (x+y)^10: "], ["names","weight_vector"], ["GetRing","RingD","SetRing"], "define a ring of polynomials." ]); HelpAdd(["CancelNumber", ["CancelNumber(<>) reduces the rational number <>", "(rational <>).", "Ex. CancelNumber( 2/6 ) : "], ["rn"], ["Cancel"], "factor out the greatest common divisor." ]); HelpAdd(["IsString", ["IsString(<>) returns true if << obj >> is a string (object <>).", "Ex. if (IsString(\"abc\")) Println(\"Hello\"); ;"], ["obj"], ["DC","Is*","Tag"], "check if a given object is a string." ]); HelpAdd(["IsRing", ["IsRing(<>) returns true if << obj >> is a ring (object <>)." ], ["obj"], ["DC","Is*","Tag"], "check if a given object is a ring." ]); HelpAdd(["IsSm1Integer", ["IsSm1Integer(<>) returns true if << obj >> is an integer of sm1(object <>)."], ["obj"], ["DC","Is*","Tag"], "check if a given object is a 32 bit integer." ]); HelpAdd(["sm1", ["sm1(<>,<>,...) is used to embed sm1 native code in the kxx program.", "Ex. sm1( 2, 2, \" add print \"); ", "Ex. def myadd(a,b) { sm1(\" a b add /FunctionValue set \"); }" ], ["arg1","arg2"], ["usage (sm1)"], "execute sm1 commands" ]); HelpAdd(["DC", ["DC(<>,<>) converts << obj >> to a new object in the primitive", "class << key >> (object <>, string <>)", "Ex. DC(\" (x+1)^10 \", \"polynomial\"): "], ["obj","key"], ["ToString"], "translate data types." ]); HelpAdd(["Length", ["Length(<>) returns the length of the array << vec >>", "(array <>)"], ["vec"], null, "length of a given array or a list." ]); HelpAdd(["Transpose", ["Transpose(<>.) return the transpose of the matrix << m >>", "(array of array <>)."], ["m"], ["NewMatrix"], "transposition" ]); HelpAdd(["Save", ["Save(<>) appends << obj >> to the file sm1out.txt (object <>)."], ["obj"], null, "write a given object to a file." ]); HelpAdd(["Coefficients", ["Coefficients(<>,<>) returns [exponents, coefficients] of << f >>", "with respect to the variable << v >>", "(polynomial <>,<>).", "Ex. Coefficients(Poly(\"(x+1)^2\"),Poly(\"x\")): "], ["f","v"], ["Exponent","Init","Init_w"], "get the exponents and coefficients." ]); HelpAdd(["System", ["System(<>) executes the unix system command << comm >>", "(string <>)", "Ex. System(\"ls\");"], ["comm"], null, "call the unix shell." ]); HelpAdd(["Exponent", ["Expoent(<>,<>) returns the vector of exponents of the polynomial <>", "Ex. Exponent( x^2*y-1,[x,y])"], ["f","vars"], ["Coefficients"], "exponents of a given polynomial." ]); HelpAdd(["Protect", ["Protect(<>) protects the symbol <> (string)", "Protect(<>,<>) protects the symbol <> (string) with ", "<> "], ["name","level"], ["extension (sm1)"], "add read-only property for a given variable." ]); HelpAdd(["IsPolynomial", ["IsPolynomial(<>) returns true if <> (object) is a polynomial."], ["obj"], ["DC","Is*","Tag"], "check if a given object is a polynomial." ]); HelpAdd(["QuoteMode", ["QuoteMode(1) sets the parser in the quotemode; if unknown function symbol", "comes, it automatically translates the expression into a tree.", "Example 1: class polymake extends PrimitiveObject {local ; def hogera() { return(1);} } ", " QuoteMode(1); polymake.foo(1,2): ", "Example 2: polymake=\"polymake\"; ", " QuoteMode(1); polymake.foo(1,2): ", "QuoteMode(0) turns off the quotemode."], ["Tag"], "Change into the quote mode." ]); /* ----------------------------------------------- functions on tests. */ /* ------------ Developping functions --------------------- */ def RingPoly(vList,weightMatrix,pp) { local new0,tmp,size,n,i,j,newtmp,ringpp,argsize; argsize = Length(Arglist); if (argsize == 1) { sm1("[", vList, "ring_of_polynomials ( ) elimination_order 0 ] define_ring /tmp set "); SetRingVariables(); return(tmp); } else ; if (argsize == 2) { pp = 0; } pp = IntegerToSm1Integer(pp); size = Length(weightMatrix); new0 = NewVector(size); sm1(" /@@@.indexMode.flag.save @@@.indexMode.flag def "); sm1(" 0 @@@.indexMode "); for (i=0; i>) returns the initial term of the polynomial <> (polynomial)", "Init(<>) returns the array of initial terms of the array of polynomials", "<< list >> (array)"], ["f"], ["Init_w"], "return the initial term." ]); HelpAdd(["NewMatrix", ["NewMatrix(<>,<>) returns the (<>,<>)-matrix (array) with the entries 0."], ["m","n"], ["NewArray"], "generate a matrix of a given size." ]); def Eliminatev(list,var) /* [(x-y). (y-z).] [(z) ] */ { sm1(list, var, " eliminatev /FunctionValue set "); } HelpAdd(["Eliminatev", ["Eliminatev(<>,<>) prunes polynomials in << list >>(array of polynomials)", "which contains the variables in << var >> ( array of strings )", "Ex. Eliminatev([Poly(\" x+h \"),Poly(\" x \")],[ \"h\" ]): "], ["list","var"], ["eliminatev (sm1)"], " " ]); def ReducedBase(base) { sm1( base, " reducedBase /FunctionValue set "); } HelpAdd(["ReducedBase", ["ReducedBase(<>) prunes redundant elements in the Grobner basis <> (array)." ], ["base"], ["Gb","Groebner"], "remove unnecessary elements." ]); def Coefficients(f,v) { local ans,exp; ans = sm1(f,v, " coefficients "); exp = ans[0]; exp = sm1(exp," { (universalNumber) dc } map "); return([exp,ans[1]]); } def IsInteger(a) { sm1(a , " isUniversalNumber /FunctionValue set "); } HelpAdd(["IsInteger", ["IsInteger(<>) returns true if << a >> is an integer (object <>).", "It returns false if << a >> is not.", "cf. IsSm1Integer"], ["a"], ["DC","Is*","Tag"], "check if a given object is an integer." ]); def IsRational(a) { sm1(a , " isRational /FunctionValue set "); } HelpAdd(["IsRational", ["IsRational(<>) returns true if << a >> is a rational (object <>).", "It returns false if << a >> is not."], ["a"], ["DC","Is*","Tag"], "check if a given object is a rational." ]); def IsDouble(a) { sm1(a , " isDouble /FunctionValue set "); } HelpAdd(["IsDouble", ["IsDouble(<>) returns true if << a >> is a double (object <>).", "It returns false if << a >> is not."], ["a"], ["DC","Is*","Tag"], "check if a given object is double." ]); sm1(" /cs { this [ ] Cleards } def "); def Init_w(f,vars,weight) { local w,w2,w3,ans,i,n; if (f == Poly("0")) return( Poly("0") ); w = Map(vars,"ToString"); w2 = sm1(weight," {$integer$ data_conversion} map "); n = Length(w); w3 = NewArray(n*2); for (i=0; i>,<>) parses << obj >> as elements of the << ring >>.", "(ring << ring >>, polynomial << obj >> or array of polynomial << obj >>).", "Ex. R = RingD(\"x,y\"); SetRingVariables();", " f = (x+y)^2; R2 = RingD(\"x,y,z\",[[\"y\",1]]); ", " f2 = Mapto(f,R2); f2: "], ["obj","ring"], ["ReParse"], "parse a polynomial in a given ring." ]); def Mapto(obj,ring) { local ans,i,n; if (IsArray(obj)) { n = Length(obj); ans = Map(obj,"ToString"); for (i=0; i>) translates << f >> into double when it is possible", "object << f >>.", "Ex. ToDouble([1,1/2,[5]]): "], ["f"], ["DC","Is*","Tag"], "translate a given object to double." ]); def k00_toDouble(f) { return(DC(f,"double")); } def ToDouble(f) { if (IsArray(f)) return(Map(f,"ToDouble")); if (IsDouble(f)) return(f); return(k00_toDouble(f)); } def Mod(f,n) { if (IsPolynomial(f)) { sm1("[(mod) ",f,n,"] gbext /FunctionValue set "); } else if (IsInteger(f)) { return( Gmp.Mod(f,n) ); } } HelpAdd(["Mod", ["Mod(<>,<

>) returns f modulo <> where << f >> (polynomial) and", " << p >> (integer). "], ["f","p"], ["gbext (sm1)"], "modulo" ]); def Characteristic(ringp) { local r,p; r = sm1(" [(CurrentRingp)] system_variable "); sm1("[(CurrentRingp) ",ringp, " ] system_variable "); p = sm1("[(P)] system_variable (universalNumber) dc "); sm1("[(CurrentRingp) ",r, " ] system_variable "); return(p); } HelpAdd(["Characteristic", ["Characteristic(<>) returns the characteristic of the << ring >>."], ["ring"], ["GetRing","RingD","RingPoly","SetRing"], "get the characteristic of a given ring." ]); def IsConstant(f) { if (Length(f) > 1) return(false); sm1("[(isConstant) ", f," ] gbext /FunctionValue set "); } HelpAdd(["IsConstant", ["IsConstant(<>) returns true if the polynomial << f >> is a constant." ], ["f"], ["DC","Is*","Tag"], "check if a given object is a constant." ]); Println("Default ring is Z[x,h]."); x = Poly("x"); h = Poly("h"); def Substitute(f,xx,g) { local tmp, coeff0,ex,i,n,newex,ans; if (IsInteger(f)) return(f); if (IsArray(f)) { n = Length(f); ans = NewVector(n); for (i=0; i0) { newex[n-1] = g^ex[n-1]; } for (i=n-2; i>=0; i--) { newex[i] = newex[i+1]*(g^(ex[i]-ex[i+1])); } return(Cancel(coeff0*newex)); } HelpAdd(["Substitute", ["Substitute(<>,<>,<>) replaces << xx >> in << f >> by << g >>.", "This function takes coeffients of << f >> with respect to << xx >>", "and returns the inner product of the vector of coefficients and the vector", "of which elements are g^(corresponding exponent).", "Note that it may cause an unexpected result in non-commutative rings." ], ["f","xx","g"], ["Replace"], " " ]); HelpAdd(["OutputPrompt", ["Output the prompt. Files should end with this command."], null, null, "output the prompt."]); Protect("Percent"); Protect("LeftBracket"); Protect("RightBracket"); Protect("Dollar"); Protect("Newline"); OutputPrompt ;