/* $OpenXM: OpenXM/src/k097/slib.k,v 1.5 2000/12/10 09:34:27 takayama Exp $ */ /* slib.sm1, standard library. */ /* April 26-- , 1996 */ /* Don't use function names that is already used as a postscipt macro names*/ /* You may encounter operand stack overflow. */ /* sm1("(incmac.sm1) run (slib.sm1) run "); */ if (K00_verbose) sm1(" ( slib.k (slib.ccc): 8/17,1996, 3/4 -- 3/10,1997 ) message "); Helplist = [ ]; def void HelpAdd(s) { Helplist = Append(Helplist,s); } def Print(a) { /* print object without new line */ sm1(a," messagen"); } def Println(a) { /* print object with new line */ sm1(a," message"); } def Ln() { sm1(" ( ) message"); } /* newline */ /* Warning!! When use sm1 as f = sm1(...), Never set /FunctionValue. Example: f = sm1(" 1 1 add /FunctionValue set ") causes error. */ def Poly(f) { sm1(f," (poly) data_conversion /FunctionValue set"); } def PolyR(f,r) { /* parse the polynomial in R */ sm1(f,r," ,, /FunctionValue set"); } def Degree(f,v) { sm1(f,v," degree (universalNumber) dc /FunctionValue set"); } def Append(f,g) { return(Join(f,[g])); } def Length(f) { sm1(f," length (universalNumber) dc /FunctionValue set"); } def Indexed(name,i) { sm1(name,i," s.Indexed /FunctionValue set "); } /* Indexed2("a",2,3) ---> "a[2,3]" */ def Indexed2(name,i,j) { sm1(name,i,j," s.Indexed2 /FunctionValue set "); } def Transpose(mat) { sm1(mat," transpose /FunctionValue set "); } sm1(" /s.Indexed { (integer) dc /arg2 set /arg1 set arg1 ([) arg2 (dollar) dc (]) 4 cat_n } def /s.Indexed2 { (integer) dc /arg3 set (integer) dc /arg2 set /arg1 set arg1 ([) arg2 (dollar) dc (,) arg3 (dollar) dc (]) 6 cat_n } def "); def Groebner(F) { /* Print("Input is "); Println(F); */ sm1(F," {[[(h). (1).]] replace homogenize} map /arg1 set [arg1] groebner 0 get /FunctionValue set "); } def GroebnerTime(F) { /* Print("Input is "); Println(F); */ sm1(F," {[[(h). (1).]] replace homogenize} map /arg1 set { [arg1] groebner 0 get } timer /FunctionValue set "); } def LiftStd(F) { /* Print("Input is "); Println(F); */ sm1(F," {[[(h). (1).]] replace homogenize} map /arg1 set [arg1 [(needBack)]] groebner /FunctionValue set "); } def Reduction(f,G) { sm1(f,G," reduction /FunctionValue set "); } def IntegerToSm1Integer(f) { sm1(f, " (integer) dc /FunctionValue set "); } def RingD(vList,weightMatrix,pp) { local new0,tmp,size,n,i,j,newtmp,ringpp,argsize; argsize = Length(Arglist); if (argsize == 1) { sm1("[", vList, "ring_of_differential_operators ( ) 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 "); PSfor (i=0; i> to the <>(string func).", " Ex. Map([82,83,85],\"AsciiToString\"):"]]); /* test Map def foo1(i) { return(i*2); } def foo() { Println(Map([82,83,84],"foo1")); } */ def Position(list,elem) { local n,pos,i; n = Length(list); pos = -1; for (i=0; i> in", " the array <>. If <> is not in <>, it return -1", " (array list).", "Ex. Position([1,34,2],34): "]]); def StringToIntegerArray(s) { sm1(s," (array) dc { (universalNumber) dc } map /FunctionValue set "); } HelpAdd(["StringToIntegerArray", ["StringToIntegerArray(s) decomposes the string <> into an array of", "ascii codes of <> (string s).", "cf. AsciiToString."]]); def StringToAsciiArray(s) { return(StringToIntegerArray(s)); } HelpAdd(["StringToAsciiArray", ["StringToAsciiArray(s) is StringToIntegerArray(s)."]]); def NewArray(n) { return(NewVector(n)); } HelpAdd(["NewArray", ["NewArray(n) returns an array of size n (integer n)."]]); def GetEnv(s) { sm1(" [(getenv) s] extension /FunctionValue set "); } HelpAdd(["GetEnv", ["GetEnv(s) returns the value of the environmental variable s (string s)."]]); def Boundp(a) { local b; sm1("[(parse) [(/) ",a," ( load tag 0 eq { /FunctionValue 0 def } { /FunctionValue 1 def } ifelse )] cat ] extension"); } HelpAdd(["Boundp", ["Boundp(s) checks if the symbol s is bounded to a value or not (string s)."]]); def Rest(a) { sm1(a," rest /FunctionValue set "); } HelpAdd(["Rest", ["Rest(a) returns the rest (cdr) of a (list a)."]]); def GetPathName(s) { local t,sss; sss = s; sm1(" [(stat) s] extension 0 get /t set "); if (Tag(t) == 0) { s=AddString([GetEnv("LOAD_K_PATH"),"/",s]); sm1(" [(stat) s] extension 0 get /t set "); if (Tag(t) == 0) { return(null); }else{ return(s); } }else{ return(s); } } HelpAdd(["GetPathName", ["GetPathName(s) checks if the file s exists in the current directory or", "in LOAD_K_PATH. If there exists, it returns the path name (string s)."]]); def Load_sm1(fnames,flag) { local ppp,n,i,cmd; if (Boundp(flag)) { }else{ n = Length(fnames); for (i=0; i