Changeset b42ab6 in git
- Timestamp:
- Dec 29, 2000, 2:52:42 AM (22 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
- Children:
- 584f84d6e8c6f3340af1d80fff4224b3f977de76
- Parents:
- c52356dc5f8ba01144cc02b2004e285f29b0cc41
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/general.lib
rc52356d rb42ab6 2 2 //anne, added deleteSublist and watchdog 12.12.2000 3 3 /////////////////////////////////////////////////////////////////////////////// 4 version="$Id: general.lib,v 1.3 0 2000-12-22 13:52:31greuel Exp $";4 version="$Id: general.lib,v 1.31 2000-12-29 01:52:42 greuel Exp $"; 5 5 category="General purpose"; 6 6 info=" … … 88 88 proc ASCII (list #) 89 89 "USAGE: ASCII([n,m]); n,m= integers (32 <= n <= m <= 126) 90 RETURN: printable ASCII characters (no native language support)90 RETURN: string of printable ASCII characters (no native language support) 91 91 ASCII(): string of all ASCII characters with its numbers, 92 no return value 93 ASCII(n): string, n-th ASCII character 94 ASCII(n,m): list, n-th up to m-th ASCII character (inclusive) 92 ASCII(n): n-th ASCII character 93 ASCII(n,m): n-th up to m-th ASCII character (inclusive) 95 94 EXAMPLE: example ASCII; shows an example 96 95 " … … 138 137 proc binomial (int n, int k, list #) 139 138 "USAGE: binomial(n,k[,p]); n,k,p integers 140 RETURN: binomial(n,k); binomial coefficient n choose k, 141 @* - of type string (computed in characteristic 0) 142 binomial(n,k,p); n choose k, computed in characteristic prime(p) 143 @* - of type number if a basering is present and prime(p)=char(basering) 144 @* - of type string else 139 RETURN: binomial(n,k); binomial coefficient n choose k 140 @* - of type string (computed in characteristic 0) 141 @* binomial(n,k,p); n choose k, computed in characteristic 0 or prime(p) 142 @* - of type number if a basering, say R, is present and p=0=char(R) 143 or if prime(p)=char(R) 144 @* - of type string else 145 145 NOTE: In any characteristic, binomial(n,k) = coefficient of x^k in (1+x)^n 146 SEE ALSO: prime 146 147 EXAMPLE: example binomial; shows an example 147 148 " … … 261 262 262 263 proc factorial (int n, list #) 263 "USAGE: factorial(n[,p]); n,p integers 264 RETURN: factorial(n): n! (computed in characteristic 0), of type string 265 factorial(n,p): n! computed in characteristic prime(p) 266 - of type number if a basering is present and prime(p)=char(basering) 267 - of type string else 268 EXAMPLE: example factorial; shows an example 264 "USAGE: factorial(n[,p]); n,p integers 265 RETURN: factorial(n): n! (computed in characteristic 0), of type string. 266 @* factorial(n,p): n! computed in characteristic 0 or prime(p) 267 @* - of type number if a basering is present and 0=p=char(basering) 268 or if prime(p)=char(basering) 269 @* - of type string else 270 SEE ALSO: prime 271 EXAMPLE: example factorial; shows an example 269 272 " 270 273 { int str,l,p; … … 313 316 314 317 proc fibonacci (int n, list #) 315 "USAGE: fibonacci(n); n,p integers 316 RETURN: fibonacci(n): nth Fibonacci number, f(0)=f(1)=1, f(i+1)=f(i-1)+f(i) 317 - computed in characteristic 0, of type string 318 of type number computed in char(basering) if n is of type number 319 fibonacci(n,p): f(n) computed in characteristic prime(p) 320 - of type number if a basering is present and prime(p)=char(basering) 321 - of type string else 318 "USAGE: fibonacci(n); n,p integers 319 RETURN: fibonacci(n): nth Fibonacci number, f(0)=f(1)=1, f(i+1)=f(i-1)+f(i) 320 @* - computed in characteristic 0, of type string 321 @* fibonacci(n,p): f(n) computed in characteristic 0 or prime(p) 322 @* - of type number if a basering is present and p=0=char(basering) 323 or if prime(p)=char(basering) 324 @* - of type string else 325 SEE ALSO: prime 322 326 EXAMPLE: example fibonacci; shows an example 323 327 " … … 359 363 example 360 364 { "EXAMPLE:"; echo = 2; 361 fibonacci( 333); ""; //f(333) of type string (as long integer)362 ring r = 17,x,dp;363 number b = fibonacci( 333,17); //f(333) of type number, computed in r365 fibonacci(42); ""; //f(42) of type string (as long integer) 366 ring r = 2,x,dp; 367 number b = fibonacci(42,2); //f(42) of type number, computed in r 364 368 b; 365 369 } … … 367 371 368 372 proc kmemory (list #) 369 "USAGE: kmemory([n,[v]]); n = int373 "USAGE: kmemory([n,[v]]); n,v integers 370 374 RETURN: memory in kilobyte of type int 371 372 373 374 375 @* n=0: memory used by active variables (same as no parameters) 376 @* n=1: total memory allocated by Singular 377 @* n=2: difference between top and init memory adress (sbrk memory) 378 @* n!=0,1,2: 0 375 379 DISPLAY: detailed information about allocated and used memory if v!=0 376 380 NOTE: kmemory uses internal function 'memory' to compute kilobyte, and … … 410 414 killall(\"type_name\"); 411 415 killall(\"not\", \"type_name\"); 412 COMPUTE: killall(); kills all user-defined variables but not loaded procedures 413 killall(\"type_name\"); kills all user-defined variables,414 of type \"type_name\" 415 killall(\"not\", \"type_name\"); kills all user-defined variables,416 except those of type \"type_name\" and except loaded procedures 417 killall(\"not\", \"name_1\", \"name_2\", ...);418 kills all user-defined variables, except those of name \"name_i\"419 and except loaded procedures420 RETURN: no return value 416 RETURN: killall(); kills all user-defined variables except loaded procedures, 417 no return value. 418 @* - killall(\"type_name\"); kills all user-defined variables, 419 of type \"type_name\" 420 @* - killall(\"not\", \"type_name\"); kills all user-defined variables, 421 except those of type \"type_name\" and except loaded procedures 422 @* - killall(\"not\", \"name_1\", \"name_2\", ...); 423 kills all user-defined variables, except those of name \"name_i\" 424 and except loaded procedures 421 425 NOTE: killall should never be used inside a procedure 422 426 EXAMPLE: example killall; shows an example AND KILLS ALL YOUR VARIABLES 423 427 " 424 428 { 425 list L=names(); int joni=size(L);426 int no_kill, j;427 for ( j=1; j<=size(#); j++)429 list @marie=names(); 430 int no_kill, @joni; 431 for ( @joni=1; @joni<=size(#); @joni++) 428 432 { 429 if (typeof(#[ j]) != "string")433 if (typeof(#[@joni]) != "string") 430 434 { 431 ERROR("Need string as " + string( j) + "th argument");435 ERROR("Need string as " + string(@joni) + "th argument"); 432 436 } 433 437 } … … 436 440 if( size(#)==0 ) 437 441 { 438 for ( ; joni>0;joni-- )442 for ( @joni=size(@marie); @joni>0; @joni-- ) 439 443 { 440 if( L[joni]!="LIB" and typeof(`L[joni]`)!="proc" ) { kill `L[joni]`; } 444 if( @marie[@joni]!="LIB" and typeof(`@marie[@joni]`)!="proc" ) 445 { kill `@marie[@joni]`; } 441 446 } 442 447 } … … 449 454 if( #[1] == "proc" ) 450 455 { 451 for ( joni=size(L); joni>0;joni-- )456 for ( @joni=size(@marie); @joni>0; @joni-- ) 452 457 { 453 if((L[joni]!="killall") and (L[joni]=="LIB" or typeof(`L[joni]`)=="proc")) 454 { kill `L[joni]`; } 458 if((@marie[@joni]!="killall") and (@marie[@joni]=="LIB" or 459 typeof(`@marie[@joni]`)=="proc")) 460 { kill `@marie[@joni]`; } 455 461 } 456 462 } … … 458 464 { 459 465 // other types 460 for ( ; joni>2;joni-- )466 for ( @joni=size(@marie); @joni>2; @joni-- ) 461 467 { 462 if(typeof(`L[joni]`)==#[1] and L[joni]!="LIB" and typeof(`L[joni]`)!="proc") { kill `L[joni]`; } 468 if(typeof(`@marie[@joni]`)==#[1] and @marie[@joni]!="LIB" 469 and typeof(`@marie[@joni]`)!="proc") 470 { kill `@marie[@joni]`; } 463 471 } 464 472 } … … 467 475 { 468 476 // kills all user-defined variables whose name or type is not #i 469 for ( ; joni>2;joni-- )470 { 471 if ( L[joni] != "LIB" && typeof(`L[joni]`) != "proc")477 for ( @joni=size(@marie); @joni>2; @joni-- ) 478 { 479 if ( @marie[@joni] != "LIB" && typeof(`@marie[@joni]`) != "proc") 472 480 { 473 481 no_kill = 0; 474 482 for (j=2; j<= size(#); j++) 475 483 { 476 if (typeof(` L[joni]`)==#[j] or L[joni] == #[j])484 if (typeof(`@marie[@joni]`)==#[j] or @marie[@joni] == #[j]) 477 485 { 478 486 no_kill = 1; … … 482 490 if (! no_kill) 483 491 { 484 kill ` L[joni]`;492 kill `@marie[@joni]`; 485 493 } 486 494 } … … 505 513 proc number_e (int n) 506 514 "USAGE: number_e(n); n integer 507 COMPUTE:Euler number e=exp(1) up to n decimal digits (no rounding)508 by A.H.J. Sale's algorithm 509 RETURN: - string of exp(1) if no basering of char 0 is defined; 510 - exp(1), type number, if a basering of char 0 is defined, display its 511 decimal format if printlevel >= voice (default:printlevel=voice-1 ) 515 RETURN: Euler number e=exp(1) up to n decimal digits (no rounding) 516 @* - of type string if no basering of char 0 is defined 517 @* - of type number if a basering of char 0 is defined 518 DISPLAY: decimal format of e if printlevel > 0 (default:printlevel=0 ) 519 NOTE: procedure uses algorithm of A.H.J. Sale 512 520 EXAMPLE: example number_e; shows an example 513 521 " … … 550 558 proc number_pi (int n) 551 559 "USAGE: number_pi(n); n positive integer 552 COMPUTE:pi (area of unit circle) up to n decimal digits (no rounding)553 by algorithm of S. Rabinowitz 554 RETURN: - string of pi if no basering of char 0 is defined, 555 - pi, of type number, if a basering of char 0 is defined, display its 556 decimal format if printlevel >= voice (default:printlevel=voice-1 ) 560 RETURN: pi (area of unit circle) up to n decimal digits (no rounding) 561 @* - of type string if no basering of char 0 is defined, 562 @* - of type number, if a basering of char 0 is defined 563 DISPLAY: decimal format of pi if printlevel > 0 (default:printlevel=0 ) 564 NOTE: procedure uses algorithm of S. Rabinowitz 557 565 EXAMPLE: example number_pi; shows an example 558 566 " … … 624 632 "USAGE: primes(n,m); n,m integers 625 633 RETURN: intvec, consisting of all primes p, prime(n)<=p<=m, in increasing 626 order if n<=m, resp. prime(m)<=p<=n, in decreasing order if m<n 627 NOTE: prime(n); returns the biggest prime number <= n (if n>=2, else 2) 634 order if n<=m, resp. prime(m)<=p<=n, in decreasing order if m<n. 635 NOTE: prime(n); returns the biggest prime number <= min(n,32003) 636 if n>=2, else 2 628 637 EXAMPLE: example primes; shows an example 629 638 " … … 644 653 proc product (id, list #) 645 654 "USAGE: product(id[,v]); id ideal/vector/module/matrix/intvec/intmat/list, 646 v intvec (default: v=1.. 647 RETURN: - if id is not a list: poly resp. int, the product of all entries of 648 id with index given by v. 649 id is treated as a list of polys resp. integers. A module m is650 identified with corresponding matrix M (columns of M generate m) 651 - if id is a list: product of list entries, with index given by v.652 Assume that list members can be multiplied655 v intvec (default: v=1..number of entries of id) 656 ASSUME: list members can be multiplied. 657 RETURN: The product of all entries of id [with index given by v] of type 658 depending on the entries of id. 659 NOTE: If id is not a list, id is treated as a list of polys resp. integers. 660 A module m is identified with the corresponding matrix M (columns 661 of M generate m). 653 662 EXAMPLE: example product; shows an example 654 663 " … … 721 730 /////////////////////////////////////////////////////////////////////////////// 722 731 proc ringweights (list # ) 723 "USAGE: ringweights (P); P=name of an existing ring (true name, not a string) 724 RETURN: intvec, size=nvars(P), consisting of the weights of the variables of P 732 "USAGE: ringweights(P); P=name of an existing ring (true name, not a string) 733 RETURN: intvec consisting of the weights of the variables of P, as they 734 appear when typing P;. 725 735 NOTE: This is useful when enlarging P but keeping the weights of the old 726 variables 727 EXAMPLE: example ringweights; 736 variables. 737 EXAMPLE: example ringweights; shows an example 728 738 " 729 739 { … … 790 800 ringweights(r0); 791 801 ring r1 = 0,x(1..5),(ds(3),wp(2,3)); 792 ringweights(r1); 793 ring r2 = 0,x(1..5),(a(1,2,3,0),dp); 794 ringweights(r2); 795 ring r3 = 0,x(1..10),(a(1..5),dp(5),a(10..13),Wp(5..9)); 796 ringweights(r3); 797 // an example for enlarging the ring: 798 intvec v = 6,2,3,4,5; 799 ring R = 0,x(1..10),(a(ringweights(r1),v),dp); 802 ringweights(r1);""; 803 // an example for enlarging the ring, keeping the first weights: 804 intvec v = ringweights(r1),6,2,3,4,5; 805 ring R = 0,x(1..10),(a(v),dp); 800 806 ordstr(R); 801 807 } … … 804 810 805 811 proc sort (id, list #) 806 "USAGE: sort(id[v,o,n]); id=ideal/module/intvec/list (of intvec's or int's) 807 sort may be called with 1, 2 or 3 arguments in the following way: 808 sort(id[v,n]); v=intvec of positive integers, n=integer, 809 sort(id[o,n]); o=string (any allowed ordstr of a ring), n=integer 810 RETURN: a list of two elements: 811 [1]: object of same type as input but sorted in the following manner: 812 "USAGE: sort(id[v,o,n]); id=ideal/module/intvec/list(of intvec's or int's) 813 @* sort may be called with 1, 2 or 3 arguments in the following way: 814 @* sort(id[v,n]); v=intvec of positive integers, n=integer, 815 @* sort(id[o,n]); o=string (any allowed ordstr of a ring), n=integer 816 RETURN: a list l of two elements: 817 @format 818 l[1]: object of same type as input but sorted in the following way: 812 819 - if id=ideal/module: generators of id are sorted w.r.t. intvec v 813 820 (id[v[1]] becomes 1-st, id[v[2]] 2-nd element, etc.). If no v is 814 821 present, id is sorted w.r.t. ordering o (if o is given) or w.r.t. 815 822 actual monomial ordering (if no o is given): 816 generators with smaller leading term come first817 (e.g. sort(id); sorts w.r.tactual monomial ordering)823 NOTE: generators with SMALLER(!) leading term come FIRST 824 (e.g. sort(id); sorts backwards to actual monomial ordering) 818 825 - if id=list of intvec's or int's: consider a list element, say 819 826 id[1]=3,2,5, as exponent vector of the monomial x^3*y^2*z^5; … … 830 837 - if n!=0 the ordering is inverse, i.e. w.r.t. v(size(v)..1) 831 838 default: n=0 832 [2]: intvec, describing the permutation of the input (hence [2]=v if 833 v is given (with positive integers) 839 l[2]: intvec, describing the permutation of the input (hence l[2]=v 840 if v is given (with positive integers)) 841 @end format 834 842 NOTE: If v is given id may be any simply indexed object (e.g. any list or 835 843 string); if v[i]<0 and i<=size(id) v[i] is set internally to i; … … 921 929 ring r0 = 0,(x,y,z,t),lp; 922 930 ideal i = x3,z3,xyz; 923 sort(i); // sort w.r.t. lex ordering 931 sort(i); //sorts using lex ordering,smaller polys come first 932 924 933 sort(i,3..1); 925 sort(i,"ls")[1]; // sort w.r.t. negative lex ordering 926 list L =1,8..5,3..10; 927 sort(L)[1]; // sort L lexicographically 928 sort(L,"Dp",1)[1]; // sort L w.r.t (total sum, reverse lex) 929 } 930 /////////////////////////////////////////////////////////////////////////////// 931 934 935 sort(i,"ls")[1]; //sort w.r.t. negative lex ordering 936 937 intvec v =1,10..5,2..4;v; 938 sort(v)[1]; // sort v lexicographically 939 940 sort(v,"Dp",1)[1]; // sort v w.r.t (total sum, reverse lex) 941 } 942 /////////////////////////////////////////////////////////////////////////////// 932 943 proc sum (id, list #) 933 "USAGE: sum(id[,v]); id=ideal/vector/module/matrix resp. id=intvec/intmat, 934 v=intvec (e.g. v=1..n, n=integer) 935 RETURN: poly resp. int which is the sum of all entries of id, with index 936 given by v (default: v=1..number of entries of id) 937 NOTE: id is treated as a list of polys resp. integers. A module m is 938 identified with corresponding matrix M (columns of M generate m) 944 "USAGE: sum(id[,v]); id ideal/vector/module/matrix/intvec/intmat/list, 945 v intvec (default: v=1..number of entries of id) 946 ASSUME: list members can be added. 947 RETURN: The sum of all entries of id [with index given by v] of type 948 depending on the entries of id. 949 NOTE: If id is not a list, id is treated as a list of polys resp. integers. 950 A module m is identified with the corresponding matrix M (columns 951 of M generate m). 939 952 EXAMPLE: example sum; shows an example 940 953 " 941 954 { 942 if( typeof(id)=="poly" or typeof(id)=="ideal" or typeof(id)=="vector" 943 or typeof(id)=="module" or typeof(id)=="matrix" ) 955 int n,j,tt; 956 string ty; 957 list l; 958 int s = size(#); 959 if( s!=0 ) 960 { if ( typeof(#[s])=="intvec" ) 961 { intvec v = #[s]; 962 tt=1; s=s-1; 963 if ( s>0 ) { # = #[1..s]; } 964 } 965 } 966 if ( s>0 ) 967 { 968 l = list(id)+#; 969 kill id; 970 list id = l; 971 ty = "list"; 972 } 973 else 974 { ty = typeof(id); 975 } 976 if( ty=="list" ) 977 { n = size(id); 978 def f(1) = id[1]; 979 for( j=2; j<=n; j=j+1 ) { def f(j)=f(j-1)+id[j]; } 980 return(f(n)); 981 } 982 if( ty=="poly" or ty=="ideal" or ty=="vector" 983 or ty=="module" or ty=="matrix" ) 944 984 { 945 985 ideal i = ideal(matrix(id)); 946 if( size(#)!=0 ) { i = i[#[1]]; } 947 matrix Z = matrix(i); 948 } 949 if( typeof(id)=="int" or typeof(id)=="intvec" or typeof(id)=="intmat" ) 950 { 951 if ( typeof(id) == "int" ) { intmat S =id; } 986 kill id; 987 ideal id = i; 988 if( tt!=0 ) { id = id[v]; } 989 n = ncols(id); poly f(1)=id[1]; 990 } 991 if( ty=="int" or ty=="intvec" or ty=="intmat" ) 992 { 993 if ( ty == "int" ) { intmat S =id; } 952 994 else { intmat S = intmat(id); } 953 995 intvec i = S[1..nrows(S),1..ncols(S)]; 954 if( size(#)!=0 ) { i = i[#[1]]; } 955 intmat Z=transpose(i); 956 } 957 intvec v; v[ncols(Z)]=0; v=v+1; 958 return((Z*v)[1,1]); 959 } 996 kill id; 997 intvec id = i; 998 if( tt!=0 ) { id = id[v]; } 999 n = size(id); int f(1)=id[1]; 1000 } 1001 for( j=2; j<=n; j=j+1 ) { def f(j)=f(j-1)+id[j]; } 1002 return(f(n)); int n,j,tt; 1003 } 960 1004 example 961 1005 { "EXAMPLE:"; echo = 2; … … 1031 1075 1032 1076 proc watchdog(int i, string cmd) 1033 "USAGE :watchdog(i,cmd); i integer; cmd string1034 RETURN S: Result of cmd, if the result can be computed in1035 i seconds. Otherwise the computation is interrupted after1036 i seconds, the string "Killed" is returned and the global1037 variable'watchdog_interrupt' is defined.1077 "USAGE: watchdog(i,cmd); i integer; cmd string 1078 RETURN: Result of cmd, if the result can be computed in i seconds. 1079 Otherwise the computation is interrupted after i seconds, 1080 the string "Killed" is returned and the global variable 1081 'watchdog_interrupt' is defined. 1038 1082 NOTE: * the MP package must be enabled 1039 * the current basering should not be watchdog_rneu 1083 * the current basering should not be watchdog_rneu, since 1084 watchdog_rneu will be killed 1040 1085 * if there are variable names of the structure x(i) all 1041 1086 polynomials have to be put into eval(...) in order to be
Note: See TracChangeset
for help on using the changeset viewer.