/* $OpenXM: OpenXM/src/k097/slib.k,v 1.8 2001/01/05 11:14:25 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 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 Reduction(f,myset) { local n, indexTable, set2, i, j, tmp, t_syz,r,rng, vsize,tt; vsize = null; r = GetRing(Poly("1")); /* Save the current ring */ rng = GetRing(f); if (Tag(rng) == 0) { rng = GetRing(myset); } if (Tag(rng) != 0) {SetRing(rng);} if (IsArray(f)) { vsize = Length(f); sm1(" [f] fromVectors 0 get /f set "); } n = Length(myset); if (n > 0) { if (IsArray(myset[0])) { if (vsize != Length(myset[0])) { Error("Reduction: size mismatch."); } sm1(" myset fromVectors /myset set "); } } indexTable = NewArray(n); set2 = [ ]; j = 0; for (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