Changeset 188cfbd in git


Ignore:
Timestamp:
Apr 17, 2015, 2:45:34 PM (8 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '8e0ad00ce244dfd0756200662572aef8402f13d5')
Children:
f52bd59412a399cb6c4ca21c965dd68c19aa5def
Parents:
7203f75e9a4e317e9e009db8a853ed8c0e6be6357cb9b47e0c889244f467795deb33c7c8156369b4
Message:
Merge pull request #711 from YueRen/max_min_multiple_arguments

chg: min and max now take more than 2 inputs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/LIB/standard.lib

    r7203f7 r188cfbd  
    1717 par2varRing([i])       create a ring making pars to vars, together with i
    1818 datetime()             return date and time as a string
    19  max(i,j)               maximum of i and j
    20  min(i,j)               minimum of i and j
     19 max(i_1,...,i_k)       maximum of i_1, ..., i_k
     20 min(i_1,...,i_k)       minimum of i_1, ..., i_k
    2121
    2222";
     
    21852185
    21862186///////////////////////////////////////////////////////////////////////////////
    2187 proc max(def i,def j)
    2188 "SYNTAX: max (i, j)
    2189 TYPE:    same as type of i resp. j
    2190 PURPOSE: returns the maximum for any 2 arguments of a type
     2187proc max(def i,list #)
     2188"SYNTAX: max (i_1, ..., i_k)
     2189TYPE:    same as type of i_1, ..., i_k resp.
     2190PURPOSE: returns the maximum for any arguments of a type
    21912191         for which '>' is defined
    21922192SEE ALSO: min
    21932193EXAMPLE: example max; shows an example"
    21942194{
    2195   if(i>j){return(i);}
    2196   return(j);
     2195  def maximum = i;
     2196  for (int j=1; j<=size(#); j++)
     2197  {
     2198    if(#[j]>maximum)
     2199    {
     2200      maximum = #[j];
     2201    }
     2202  }
     2203  return(maximum);
    21972204}
    21982205example
    21992206{ "EXAMPLE:"; echo=2;
     2207  // biggest int
    22002208  max(2,3);
    2201   max(4,3);
     2209  max(1,4,3);
     2210  // lexicographically biggest intvec
     2211  max(intvec(1,2),intvec(0,1),intvec(1,1));
     2212  // polynopmial with biggest leading monomial
     2213  ring r = 0,x,dp;
     2214  max(x+1,x2+x);
    22022215}
    22032216///////////////////////////////////////////////////////////////////////////////
    2204 proc min(def i,def j)
    2205 "SYNTAX: min (i, j)
    2206 TYPE:    same as type of i resp. j
    2207 PURPOSE: returns the minimum for any 2 arguments of a type
     2217proc min(def i,list #)
     2218"SYNTAX: min (i_1, ..., i_k)
     2219TYPE:    same as type of i_1, ..., i_k resp.
     2220PURPOSE: returns the minimum for any arguments of a type
    22082221         for which '>' is defined
    22092222SEE ALSO: max
    22102223EXAMPLE: example min; shows an example"
    22112224{
    2212   if(i>j){return(j);}
    2213   return(i);
     2225  def minimum = i;
     2226  for (int j=1; j<=size(#); j++)
     2227  {
     2228    if(#[j]<minimum)
     2229    {
     2230      minimum = #[j];
     2231    }
     2232  }
     2233  return(minimum);
    22142234}
    22152235example
    22162236{ "EXAMPLE:"; echo=2;
     2237  // smallest int
    22172238  min(2,3);
    2218   min(4,3);
     2239  min(1,4,3);
     2240  // lexicographically smallest intvec
     2241  min(intvec(1,2),intvec(0,1),intvec(1,1));
     2242  // polynopmial with smallest leading monomial
     2243  ring r = 0,x,dp;
     2244  min(x+1,x2+x);
    22192245}
    22202246
Note: See TracChangeset for help on using the changeset viewer.