Changeset 298d0a in git


Ignore:
Timestamp:
Aug 13, 2004, 4:09:21 PM (20 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c3b42bd22345d6bc9ce1a7e84df4e0c62e0173bf
Parents:
cbcc6f60e9762c35407e5f53eca609495277d48c
Message:
*hannes: namespace fixes(killall)


git-svn-id: file:///usr/local/Singular/svn/trunk@7399 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/general.lib

    rcbcc6f6 r298d0a  
    33//eric, added absValue 11.04.2002
    44///////////////////////////////////////////////////////////////////////////////
    5 version="$Id: general.lib,v 1.43 2004-08-13 12:52:37 Singular Exp $";
     5version="$Id: general.lib,v 1.44 2004-08-13 14:09:21 Singular Exp $";
    66category="General purpose";
    77info="
     
    2626 watchdog(i,cmd);       only wait for result of command cmd for i seconds
    2727 which(command);        search for command and return absolute path, if found
    28  primecoeffs(J[,q]);    primefactors <= min(p,32003) of coeffs of J 
     28 primecoeffs(J[,q]);    primefactors <= min(p,32003) of coeffs of J
    2929 primefactors(n [,p]);  primefactors <= min(p,32003) of n
    3030           (parameters in square brackets [] are optional)
     
    141141
    142142proc absValue(def c)
    143 "USAGE:  absValue(c); c int, number or poly 
     143"USAGE:  absValue(c); c int, number or poly
    144144RETURN:  absValue(c); the absolute value of c
    145145NOTE:    absValue(c)=c if c>=0; absValue=-c if c<=0.
    146146@*       So the function can be applied to any type, for which comparison
    147 @*       operators are defined. 
     147@*       operators are defined.
    148148SEE ALSO: boolean expressions
    149149EXAMPLE: example absValue; shows an example
     
    492492        for ( @joni=size(@marie); @joni>0; @joni-- )
    493493        {
    494           if((@marie[@joni]!="General")
     494          if( (@marie[@joni]!="General")
    495495          and (@marie[@joni]!="Top")
    496496          and (@marie[@joni]!="killall")
    497           and (@marie[@joni]=="LIB" or
    498               typeof(`@marie[@joni]`)=="package" or
    499               typeof(`@marie[@joni]`)=="proc"))
    500           { kill `@marie[@joni]`;
    501           if (defined(`@marie[@joni]`)) {kill `@marie[@joni]`;}}
     497          and (@marie[@joni]!="LIB") and
     498              ((typeof(`@marie[@joni]`)=="package") or
     499              (typeof(`@marie[@joni]`)=="proc")))
     500          {
     501            if (defined(`@marie[@joni]`)) {kill `@marie[@joni]`;}
     502          }
     503          if (!defined(@joni)) break;
    502504        }
    503         if (system("with","Namespaces"))
     505        if ((system("with","Namespaces")) && defined(General))
    504506        {
     507         
    505508          @marie=names(General);
    506509          for ( @joni=size(@marie); @joni>0; @joni-- )
     
    546549          }
    547550        }
     551        if (!defined(@joni)) break;
    548552      }
    549553    }
     
    12441248"USAGE:   primefactors(n [,p]); n = int or number, p = integer
    12451249COMPUTE: primefactors <= min(p,32003) of n (default p = 32003)
    1246 RETURN:  a list, say l, 
    1247          l[1] : primefactors <= min(p,32003) of n 
     1250RETURN:  a list, say l,
     1251         l[1] : primefactors <= min(p,32003) of n
    12481252         l[2] : l[2][i] = multiplicity of l[1][i]
    12491253         l[3] : remaining factor ( n=product{ (l[1][i]^l[2][i])*l[3]} )
     
    12601264   intvec w1,w2,v;
    12611265   list l;
    1262    if (size(#) == 0) 
    1263    {
    1264       p=32003; 
    1265    }
    1266    else 
     1266   if (size(#) == 0)
     1267   {
     1268      p=32003;
     1269   }
     1270   else
    12671271   {
    12681272     if( typeof(#[1]) != "int")
     
    12741278   if( n<0) { n=-n;};
    12751279
    1276 // ----------------- case: 1st parameter is a number --------------------   
     1280// ----------------- case: 1st parameter is a number --------------------
    12771281   if (typeof(n) =="number")
    12781282   {
     
    12841288        number m;
    12851289        for( ii=1; ii<=size(v); ii++)
    1286         { 
     1290        {
    12871291          jj=0;
    12881292          while(1)
    1289           { 
     1293          {
    12901294            q  = v[ii];
    1291             jj = jj+1;             
     1295            jj = jj+1;
    12921296            m  = n/q;                  //divide n as often as possible
    12931297            if (denominator(m)!=1) { break;  }
    12941298            n=m;
    12951299          }
    1296           if( jj>1 ) 
     1300          if( jj>1 )
    12971301          {
    12981302             w1 = w1,v[ii];          //primes
     
    13091313         w1 = w1[2..size(w1)];
    13101314         w2 = w2[2..size(w2)];
    1311        } 
     1315       }
    13121316       else                           //no primefactor was found
    13131317       {
    13141318         w1 = 1; w2 = 1;
    1315        }     
     1319       }
    13161320       l  = w1,w2,n;
    13171321       return(l);
     
    13251329     }
    13261330   }
    1327    
     1331
    13281332// --------------------------- trivial cases --------------------
    1329    if( n==0 ) 
    1330    { 
     1333   if( n==0 )
     1334   {
    13311335     w1=1; w2=1; w3=0; l=w1,w2,w3;
    13321336     return(l);
    13331337   }
    1334    
    1335    if( n==1 ) 
    1336    {   
     1338
     1339   if( n==1 )
     1340   {
    13371341       w3=1;
    13381342       if( size(w1) >1 )               //at least 1 primefactor was found
     
    13401344         w1 = w1[2..size(w1)];
    13411345         w2 = w2[2..size(w2)];
    1342        } 
     1346       }
    13431347       else                           //no primefactor was found
    13441348       {
    13451349         w1 = 1; w2 = 1;
    1346        }     
     1350       }
    13471351      l=w1,w2,w3;
    13481352      return(l);
     
    13511355   {                          //case n is a prime
    13521356      if (p > n)
    1353       { 
     1357      {
    13541358        w1=w1,n; w2=w2,1; w3=1;
    13551359        w1 = w1[2..size(w1)];
     
    13651369           w1 = w1[2..size(w1)];
    13661370           w2 = w2[2..size(w2)];
    1367          } 
     1371         }
    13681372         else                           //no primefactor was found
    13691373         {
    13701374           w1 = 1; w2 = 1;
    1371          }     
     1375         }
    13721376         l=w1,w2,w3;
    13731377        return(l);
    1374       }     
    1375    }
    1376    else 
     1378      }
     1379   }
     1380   else
    13771381   {
    13781382      if ( p >= n)
     
    13841388         v = primes(q,p);
    13851389      }
    1386 //------------- search for primfactors <= last entry of v ------------   
     1390//------------- search for primfactors <= last entry of v ------------
    13871391      for(ii=1; ii<=size(v); ii++)
    13881392      {
    13891393         z=0;
    13901394         while( (n mod v[ii]) == 0 )
    1391          { 
     1395         {
    13921396            z=z+1;
    13931397            n = n div v[ii];
    13941398         }
    13951399         if (z!=0)
    1396          { 
     1400         {
    13971401            w1 = w1,v[ii];        //primes
    13981402            w2 = w2,z;            //multiplicities
     
    14051409      w1 = w1[2..size(w1)];
    14061410      w2 = w2[2..size(w2)];
    1407    } 
     1411   }
    14081412   else                           //no primefactor was found
    14091413   {
    14101414     w1 = 1; w2 = 1;
    1411    } 
     1415   }
    14121416   w3 = n;
    14131417   l  = w1,w2,w3;
     
    14191423   ring r = 0,x,dp;
    14201424   primefactors(123456789100);
    1421 } 
     1425}
    14221426
    14231427///////////////////////////////////////////////////////////////////////////////
     
    14361440{
    14371441   int q,ii,n,mark;;
    1438    if (size(#) == 0) 
    1439    {
    1440       q=32003; 
    1441    }
    1442    else 
     1442   if (size(#) == 0)
     1443   {
     1444      q=32003;
     1445   }
     1446   else
    14431447   {
    14441448     if( typeof(#[1]) != "int")
     
    14561460   def I = ideal(matrix(J));
    14571461   poly p = product(maxideal(1));
    1458    matrix Coef=coef(I[1],p); 
     1462   matrix Coef=coef(I[1],p);
    14591463   ideal id, jd, rest;
    14601464   intvec v,re;
     
    14661470   id = Coef[2,1..ncols(Coef)];
    14671471   id = simplify(id,6);
    1468    for (ii=1; ii<=size(id); ii++) 
    1469    {   
    1470      l = primefactors(number(id[ii]),q);     
     1472   for (ii=1; ii<=size(id); ii++)
     1473   {
     1474     l = primefactors(number(id[ii]),q);
    14711475     jd = jd,l[1];
    14721476     rest = rest,l[3];
    1473    } 
     1477   }
    14741478   jd = simplify(jd,6);
    1475    for (ii=1; ii<=size(jd); ii++) 
    1476    { 
     1479   for (ii=1; ii<=size(jd); ii++)
     1480   {
    14771481     v[ii]=int(jd[ii]);
    14781482   }
     
    14901494   else
    14911495   {
    1492       result = v,rest; 
     1496      result = v,rest;
    14931497   }
    14941498   return(result);
     
    15001504   ideal I = -13b6c3t+4b5c4t,-10b4c2t-5b4ct2;
    15011505   primecoeffs(I);
    1502 } 
    1503 ///////////////////////////////////////////////////////////////////////////////
     1506}
     1507///////////////////////////////////////////////////////////////////////////////
Note: See TracChangeset for help on using the changeset viewer.