Changeset f937e2 in git
- Timestamp:
- Jun 7, 1999, 7:25:07 PM (24 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 445434af88451a04abc772d0ad55d79c18a769fa
- Parents:
- 47a6aecfda7eb8cdd122babe0e3446aafc41cf0d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/general.lib
r47a6aec rf937e2 1 // $Id: general.lib,v 1.1 0 1999-04-19 11:02:10 obachmanExp $1 // $Id: general.lib,v 1.11 1999-06-07 17:25:07 Singular Exp $ 2 2 //system("random",787422842); 3 3 //GMG, last modified 30.9.98 4 4 /////////////////////////////////////////////////////////////////////////////// 5 5 6 version="$Id: general.lib,v 1.1 0 1999-04-19 11:02:10 obachmanExp $";6 version="$Id: general.lib,v 1.11 1999-06-07 17:25:07 Singular Exp $"; 7 7 info=" 8 8 LIBRARY: general.lib PROCEDURES OF GENERAL TYPE … … 140 140 /////////////////////////////////////////////////////////////////////////////// 141 141 142 proc binomial (int n, int k, list #) 143 "USAGE: binomial(n,k[,p/s]); n,k,p integers, s string 144 RETURN: binomial(n,k); binomial coefficient n choose k of type int 145 (machine integer, limited size! ) 146 binomial(n,k,p); n choose k in char p of type string 147 binomial(n,k,s); n choose k of type number (s any string), computed 148 in char of basering if a basering is defined 142 proc binomial (def n, int k, list #) 143 "USAGE: binomial(n,k[,p]); n,k,p integers 144 RETURN: binomial(n,k); binomial coefficient n choose k, 145 of type number if n is of type number (computed in char(basering)), 146 of type int if n is of type int (machine integer, limited size!) 147 binomial(n,k,p); n choose k in char p, of type string 149 148 EXAMPLE: example binomial; shows an example 150 149 " 151 150 { 152 if ( size(#)==0 ) { int rr=1; } 151 if ( size(#)==0 ) 152 { 153 if ( typeof(n)=="number" ) { number rr=1; } 154 else { int rr=1; } 155 } 153 156 if ( typeof(#[1])=="int") { ring bin = #[1],x,dp; number rr=1; } 154 if ( typeof(#[1])=="string") { number rr=1; } 155 if ( size(#)==0 or typeof(#[1])=="int" or typeof(#[1])=="string" ) 157 if ( size(#)==0 or typeof(#[1])=="int" ) 156 158 { 157 159 def r = rr; … … 170 172 { "EXAMPLE:"; echo = 2; 171 173 int b1 = binomial(10,7); b1; 172 binomial(37,17,0); 173 ring t = 31,x,dp; 174 number b2 = binomial(37,17,""); b2; 175 } 176 /////////////////////////////////////////////////////////////////////////////// 177 178 proc factorial (int n, list #) 179 "USAGE: factorial(n[,string]); n integer 180 RETURN: factorial(n); string of n! in char 0 181 factorial(n,s); n! of type number (s any string), computed in char of 182 basering if a basering is defined 174 binomial(137,17,0); 175 ring t = 0,x,dp; 176 number b2 = binomial(number(137),17); b2; 177 } 178 /////////////////////////////////////////////////////////////////////////////// 179 180 proc factorial (def n) 181 "USAGE: factorial(n); n = integer 182 RETURN: factorial(n); n! in char 0, of type string if n is of type int 183 n! of type number, computed in char(basering) if n is of type number 183 184 EXAMPLE: example factorial; shows an example 184 185 " 185 186 { 186 if ( size(#)==0 ) { ring R = 0,x,dp; poly r=1; } 187 if ( typeof(#[1])=="string" ) { number r=1; } 188 if ( size(#)==0 or typeof(#[1])=="string" ) 189 { 190 int l; 191 for (l=2; l<=n; l=l+1) 192 { 193 r=r*l; 194 } 195 if ( size(#)==0 ) { return(string(r)); } 196 return(r); 197 } 187 int t,l; 188 if ( typeof(n)=="number" ) { number r=1; } 189 else { ring R = 0,x,dp; number r=1; t=1; } 190 for (l=2; l<=n; l=l+1) 191 { 192 r=r*l; 193 } 194 if ( t==1 ) { return(string(r)); } 195 return(r); 198 196 } 199 197 example … … 201 199 factorial(37); 202 200 ring r1 = 32003,(x,y,z),ds; 203 number p = factorial( 37,""); p;204 } 205 /////////////////////////////////////////////////////////////////////////////// 206 207 proc fibonacci ( int n, list #)208 "USAGE: fibonacci(n [,string]); (n integer)209 RETURN: fibonacci(n); string ofnth Fibonacci number,201 number p = factorial(number(37)); p; 202 } 203 /////////////////////////////////////////////////////////////////////////////// 204 205 proc fibonacci (def n) 206 "USAGE: fibonacci(n); (n integer) 207 RETURN: fibonacci(n); nth Fibonacci number, 210 208 f(0)=f(1)=1, f(i+1)=f(i-1)+f(i) 211 fibonacci(n,s); nth Fibonacci number of type number (s any string),212 computed in characteristic of basering if a basering is defined209 of type string if n is of type int 210 of type number computed in char(basering) if n is of type number 213 211 EXAMPLE: example fibonacci; shows an example 214 212 " 215 213 { 216 if ( size(#)==0 ) { ring fibo = 0,x,dp; number f=1; } 217 if ( typeof(#[1])=="string" ) { number f=1; } 218 if ( size(#)==0 or typeof(#[1])=="string" ) 219 { 220 number g,h = 1,1; int ii; 221 for (ii=3; ii<=n; ii=ii+1) 222 { 223 h = f+g; f = g; g = h; 224 } 225 if ( size(#)==0 ) { return(string(h)); } 226 return(h); 227 } 214 int ii,t; 215 if ( typeof(n)=="number" ) { number f,g,h=1,1,1; } 216 else { ring fibo = 0,x,dp; number f,g,h=1,1,1; t=1; } 217 for (ii=3; ii<=n; ii=ii+1) 218 { 219 h = f+g; f = g; g = h; 220 } 221 if ( t==1 ) { return(string(h)); } 222 return(h); 228 223 } 229 224 example … … 231 226 fibonacci(37); 232 227 ring r = 17,x,dp; 233 number b = fibonacci( 37,""); b;228 number b = fibonacci(number(37)); b; 234 229 } 235 230 ///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.