Changeset b5726c in git
- Timestamp:
- Jan 7, 2001, 2:50:32 AM (22 years ago)
- Branches:
- (u'spielwiese', '8d54773d6c9e2f1d2593a28bc68b7eeab54ed529')
- Children:
- 4cb6b8049b916680b0af4440be038380e9c4ac37
- Parents:
- e143c4c97746c0b2a52b6ee135eb652962690f84
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/LIB/general.lib
re143c4 rb5726c 2 2 //anne, added deleteSublist and watchdog 12.12.2000 3 3 /////////////////////////////////////////////////////////////////////////////// 4 version="$Id: general.lib,v 1.3 4 2000-12-31 15:14:46 obachmanExp $";4 version="$Id: general.lib,v 1.35 2001-01-07 01:50:32 greuel Exp $"; 5 5 category="General purpose"; 6 6 info=" … … 20 20 primes(n,m); intvec of primes p, n<=p<=m 21 21 product(../..[,v]); multiply components of vector/ideal/...[indices v] 22 ringweights(r); intvec of weights of ring variables of ring r23 22 sort(ideal/module); sort generators according to monomial ordering 24 23 sum(vector/id/..[,v]); add components of vector/ideal/...[with indices v] … … 271 270 EXAMPLE: example factorial; shows an example 272 271 " 273 { int l,p;272 { int str,l,p; 274 273 //---------------------------- initialization ------------------------------- 275 274 if ( size(#) == 0 ) 276 { 275 { str = 1; 277 276 ring bin = 0,x,dp; 278 277 number r=1; … … 284 283 { 285 284 if ( p == char(basering) ) 286 { 287 // do it clever ! 288 if (n < 1) {return (0);} 289 if (! defined(sv_factorials)) 290 { 291 ideal sv_factorials; 292 sv_factorials[1] = 1; 293 export(sv_factorials); 294 } 295 if (n > size(sv_factorials)) 296 { 297 int i = size(sv_factorials); 298 sv_factorials[n] = 0; 299 number fi = number(sv_factorials[i]); 300 for (i++;i<=n;i++) 301 { 302 fi = fi * i; 303 sv_factorials[i] = fi; 304 } 305 return (fi); 306 } 307 else 308 { 309 return (number(sv_factorials[n])); 310 } 285 { number r=1; 311 286 } 312 287 else 313 { 288 { str = 1; 314 289 ring bin = p,x,dp; 315 290 number r=1; … … 317 292 } 318 293 else 319 { 294 { str = 1; 320 295 ring bin = p,x,dp; 321 296 number r=1; … … 327 302 r=r*l; 328 303 } 329 return(string(r)); 304 if ( str==1 ) { return(string(r)); } 305 else { return(r); } 330 306 } 331 307 example … … 336 312 p; 337 313 } 338 339 340 314 /////////////////////////////////////////////////////////////////////////////// 341 315 … … 787 761 } 788 762 /////////////////////////////////////////////////////////////////////////////// 789 proc ringweights (list # )790 "USAGE: ringweights(P); P=name of an existing ring (true name, not a string)791 RETURN: intvec consisting of the weights of the variables of P, as they792 appear when typing P;.793 NOTE: This is useful when enlarging P but keeping the weights of the old794 variables.795 EXAMPLE: example ringweights; shows an example796 "797 {798 int ii,q,fi,fo,fia;799 intvec rw,nw;800 string os;801 def P = #[1];802 string osP = ordstr(P);803 fo = 1;804 //------------------------- find weights in ordstr(P) -------------------------805 fi = find(osP,"(",fo);806 fia = find(osP,"a",fo)+find(osP,"w",fo)+find(osP,"W",fo);807 while ( fia )808 {809 os = osP[fi+1,find(osP,")",fi)-fi-1];810 if( find(os,",") )811 {812 execute("nw = "+os+";");813 if( size(nw) > ii )814 {815 rw = rw,nw[ii+1..size(nw)];816 }817 else { ii = ii - size(nw); }818 819 if( find(osP[1,fi],"a",fo) ) { ii = size(nw); }820 }821 else822 {823 execute("q = "+os+";");824 if( q > ii )825 {826 nw = 0; nw[q-ii] = 0;827 nw = nw + 1; //creates an intvec 1,...,1 of length q-ii828 rw = rw,nw;829 }830 else { ii = ii - q; }831 }832 fo = fi+1;833 fi = find(osP,"(",fo);834 fia = find(osP,"a",fo)+find(osP,"w",fo)+find(osP,"W",fo);835 }836 //-------------- adjust weight vector to length = nvars(P) -------------------837 if( fo > 1 )838 { // case when weights were found839 rw = rw[2..size(rw)];840 if( size(rw) > nvars(P) )841 {842 rw = rw[1..nvars(P)];843 }844 if( size(rw) < nvars(P) )845 {846 nw=0; nw[nvars(P)-size(rw)]=0; nw=nw+1; rw=rw,nw;847 }848 }849 else850 { // case when no weights were found851 rw[nvars(P)]= 0; rw=rw+1;852 }853 return(rw);854 }855 example856 {"EXAMPLE:"; echo = 2;857 ring r0 = 0,(x,y,z),dp;858 ringweights(r0);859 ring r1 = 0,x(1..5),(ds(3),wp(2,3));860 ringweights(r1);"";861 // an example for enlarging the ring, keeping the first weights:862 intvec v = ringweights(r1),6,2,3,4,5;863 ring R = 0,x(1..10),(a(v),dp);864 ordstr(R);865 }866 867 ///////////////////////////////////////////////////////////////////////////////868 763 869 764 proc sort (id, list #) 870 "USAGE: sort(id[v,o,n]); id =ideal/module/intvec/list(of intvec's or int's)765 "USAGE: sort(id[v,o,n]); id = ideal/module/intvec/list(of intvec's or int's) 871 766 @* sort may be called with 1, 2 or 3 arguments in the following way: 872 767 @* sort(id[v,n]); v=intvec of positive integers, n=integer, … … 907 802 intvec v; 908 803 if ( defined(basering) ) { def P = basering; } 909 if ( size(#)==0 and (typeof(id)=="ideal" or typeof(id)=="module") ) 804 if ( size(#)==0 and (typeof(id)=="ideal" or typeof(id)=="module" 805 or typeof(id)=="matrix")) 910 806 { 911 807 id = simplify(id,2); … … 917 813 else { v = size(id)..1; } 918 814 } 919 if ( size(#)>=1 and (typeof(id)=="ideal" or typeof(id)=="module") ) 815 if ( size(#)>=1 and (typeof(id)=="ideal" or typeof(id)=="module" 816 or typeof(id)=="matrix") ) 920 817 { 921 818 if ( typeof(#[1])=="string" )
Note: See TracChangeset
for help on using the changeset viewer.