Changeset 7708934 in git


Ignore:
Timestamp:
Dec 30, 2000, 4:00:57 AM (22 years ago)
Author:
Gert-Martin Greuel <greuel@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a657104b677b4c461d018cbf3204d72d34ad66a9')
Children:
9f8a0c36a14214c0b8e9241e2b54aee67001707d
Parents:
584f84d6e8c6f3340af1d80fff4224b3f977de76
Message:
* GMG Prozeduren sum und product neu ueberarbeitet, leere Summe und leeres
* Produkt mit 0 bzw 1 zurueckgegeben. Funktionalitaet erweitert.


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

Legend:

Unmodified
Added
Removed
  • Singular/LIB/general.lib

    r584f84d r7708934  
    22//anne, added deleteSublist and watchdog 12.12.2000
    33///////////////////////////////////////////////////////////////////////////////
    4 version="$Id: general.lib,v 1.32 2000-12-29 02:19:24 greuel Exp $";
     4version="$Id: general.lib,v 1.33 2000-12-30 03:00:57 greuel Exp $";
    55category="General purpose";
    66info="
     
    660660          A module m is identified with the corresponding matrix M (columns
    661661          of M generate m).
     662@*        If v is outside the range of id, we have the empty product and the
     663          result will be 1 (of type int).
    662664EXAMPLE:  example product; shows an example
    663665"
    664 {
     666
     667//-------------------- initialization and special feature ---------------------
    665668   int n,j,tt;
    666    string ty;
     669   string ty;                                         //will become type of id
    667670   list l;
     671
     672// We wish to allow something like product(x(1..10)) if x(1),...,x(10) are
     673// variables. x(1..10) is a list of polys and enters the procedure with
     674// id=x(1) and # a list with 9 polys, #[1]= x(2),...,#[9]= x(10). Hence, in
     675// this case # is never empty. If an additional intvec v is given,
     676// it is added to #, so we have to separate it first and make
     677// the rest a list which has to be multiplied.
     678
    668679   int s = size(#);
    669680   if( s!=0 )
    670    {  if ( typeof(#[s])=="intvec" )
    671       {  intvec v = #[s];
    672          tt=1; s=s-1;
     681   {  if ( typeof(#[s])=="intvec" or typeof(#[s])=="int")   
     682      { 
     683         intvec v = #[s];
     684         tt=1;
     685         s=s-1;
    673686         if ( s>0 ) { # = #[1..s]; }
    674687      }
     
    676689   if ( s>0 )
    677690   {
    678      l = list(id)+#;
    679      kill id;
    680      list id = l;
    681      ty = "list";
     691      l = list(id)+#;
     692      kill id;
     693      list id = l;                                    //case: id = list
     694      ty = "list";
     695      n = size(id);
    682696   }
    683697   else
    684    { ty = typeof(id);
    685    }
    686    if( ty=="list" )
    687    { n = size(id);
    688      def f(1) = id[1];
    689      for( j=2; j<=n; j=j+1 ) { def f(j)=f(j-1)*id[j]; }
    690      return(f(n));
    691    }
     698   {
     699      ty = typeof(id);
     700      if( ty == "list" )
     701      { n = size(id); }
     702   }
     703//------------------------------ reduce to 3 cases ---------------------------
    692704   if( ty=="poly" or ty=="ideal" or ty=="vector"
    693705       or ty=="module" or ty=="matrix" )
     
    695707      ideal i = ideal(matrix(id));
    696708      kill id;
    697       ideal id = i;
    698       if( tt!=0 ) { id = id[v]; }
    699       n = ncols(id); poly f(1)=id[1];
     709      ideal id = i;                                   //case: id = ideal
     710      n = ncols(id);
    700711   }
    701712   if( ty=="int" or ty=="intvec" or ty=="intmat" )
     
    705716      intvec i = S[1..nrows(S),1..ncols(S)];
    706717      kill id;
    707       intvec id = i;
    708       if( tt!=0 ) { id = id[v]; }
    709       n = size(id); int f(1)=id[1];
    710    }
     718      intvec id = i;                                  //case: id = intvec
     719      n = size(id);
     720   }
     721//--------------- consider intvec v and empty product  -----------------------
     722   if( tt!=0 )
     723   {
     724      for (j=1; j<=size(v); j++)
     725      {
     726         if ( v[j] <= 0 or v[j] > n )                 //v outside range of id
     727         {
     728            return(1);                                //empty product is 1
     729         }                               
     730      }
     731      id = id[v];                                     //consider part of id
     732   }                                                  //corresponding to v
     733//--------------------- special case: one factor is zero  ---------------------
     734   if ( typeof(id) == "ideal")
     735   {
     736      if( size(id) < ncols(id) )
     737      {
     738          poly f; return(f);
     739      }
     740   }
     741//-------------------------- finally, multiply objects  -----------------------
     742   n = size(id);
     743   def f(1) = id[1];
    711744   for( j=2; j<=n; j=j+1 ) { def f(j)=f(j-1)*id[j]; }
    712745   return(f(n));
     
    947980RETURN:   The sum of all entries of id [with index given by v] of type
    948981          depending on the entries of id.
    949 NOTE:      If id is not a list, id is treated as a list of polys resp. integers.
     982NOTE:     If id is not a list, id is treated as a list of polys resp. integers.
    950983          A module m is identified with the corresponding matrix M (columns
    951984          of M generate m).
     985@*        If v is outside the range of id, we have the empty sum and the
     986          result will be 0 (of type int).
    952987EXAMPLE:  example sum; shows an example
    953988"
    954989{
     990//-------------------- initialization and special feature ---------------------
    955991   int n,j,tt;
    956    string ty;
     992   string ty;                                  // will become type of id
    957993   list l;
     994
     995// We wish to allow something like sum(x(1..10)) if x(1),...,x(10) are
     996// variables. x(1..10) is a list of polys and enters the procedure with
     997// id=x(1) and # a list with 9 polys, #[1]= x(2),...,#[9]= x(10). Hence, in
     998// this case # is never empty. If an additional intvec v is given,
     999// it is added to #, so we have to separate it first and make
     1000// the rest a list which has to be added.
     1001
    9581002   int s = size(#);
    9591003   if( s!=0 )
    960    {  if ( typeof(#[s])=="intvec" )
     1004   {  if ( typeof(#[s])=="intvec" or typeof(#[s])=="int")
    9611005      {  intvec v = #[s];
    962          tt=1; s=s-1;
     1006         tt=1;
     1007         s=s-1;
    9631008         if ( s>0 ) { # = #[1..s]; }
    9641009      }
     
    9661011   if ( s>0 )
    9671012   {
    968      l = list(id)+#;
    969      kill id;
    970      list id = l;
    971      ty = "list";
     1013      l = list(id)+#;
     1014      kill id;
     1015      list id = l;                                    //case: id = list
     1016      ty = "list";
    9721017   }
    9731018   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    }
     1019   {
     1020      ty = typeof(id);
     1021   }
     1022//------------------------------ reduce to 3 cases ---------------------------
    9821023   if( ty=="poly" or ty=="ideal" or ty=="vector"
    9831024       or ty=="module" or ty=="matrix" )
    984    {
     1025   {                                                 //case: id = ideal
    9851026      ideal i = ideal(matrix(id));
    9861027      kill id;
    987       ideal id = i;
    988       if( tt!=0 ) { id = id[v]; }
    989       n = ncols(id); poly f(1)=id[1];
     1028      ideal id = simplify(i,2);                      //delete 0 entries
    9901029   }
    9911030   if( ty=="int" or ty=="intvec" or ty=="intmat" )
     
    9951034      intvec i = S[1..nrows(S),1..ncols(S)];
    9961035      kill id;
    997       intvec id = i;
    998       if( tt!=0 ) { id = id[v]; }
    999       n = size(id); int f(1)=id[1];
    1000    }
     1036      intvec id = i;                                 //case: id = intvec
     1037   }
     1038//------------------- consider intvec v and empty sum  -----------------------
     1039   if( tt!=0 )
     1040   {
     1041      for (j=1; j<=size(v); j++)
     1042      {
     1043         if ( v[j] <= 0 or v[j] > size(id) )         //v outside range of id
     1044         {
     1045            return(0);                               //empty sum is 0
     1046         }                               
     1047      }
     1048      id = id[v];                                    //consider part of id
     1049   }                                                 //corresponding to v
     1050
     1051//-------------------------- finally, add objects  ---------------------------
     1052   n = size(id);
     1053   def f(1) = id[1];
    10011054   for( j=2; j<=n; j=j+1 ) { def f(j)=f(j-1)+id[j]; }
    10021055   return(f(n));   int n,j,tt;
Note: See TracChangeset for help on using the changeset viewer.