Re: Defining a flat, orderless, one-identical function?
- To: mathgroup at smc.vnet.net
- Subject: [mg28072] Re: [mg28046] Defining a flat, orderless, one-identical function?
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Fri, 30 Mar 2001 04:12:24 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
I just noticed that the solution I proposed has an undesirable property, in that it gives: In[8]:= max[a,b] Out[8]= a To following defintion avoids the problem: In[1]:= SetAttributes[max, {Flat, OneIdentity, Orderless, NumericFunction}] In[2]:= max[a_?NumericQ, b_?NumericQ] := Max[a, b]; max[a_ b_, a_ c_] := a max[b, c]; (x_max/;Length[Unevaluated[x]]==1):=Hold[x][[1,1]] This works as before except that this time: In[5]:= max[a] Out[5]= a In[6]:= max[a,b] Out[6]= max[a,b] on 3/29/01 11:57 AM, Andrzej Kozlowski at andrzej at platon.c.u-tokyo.ac.jp wrote: > This is a rather complex issue tha thas been already discussed in some detail > a number of times so you shoudl search the archives to understand more. Here > is just one solution to your problem, the main idea of which, if I remeber > correctly, was once suggested by Carl Woll: > > In[1]:= > SetAttributes[max, {Flat, OneIdentity, > Orderless, NumericFunction}] > > In[2]:= > max[a_?NumericQ, b_?NumericQ] := Max[a, b]; > max[a_ b_, a_ c_] := a max[b, c]; > (x_max/;True):=Hold[x][[1,1]] > > This should now work correctly, e.g.: > > In[3]:= > max[1,3] > > Out[3]= > 3 > > In[4]:= > max[a,a] > > Out[4]= > a > > In[5]:= > max[a] > > Out[5]= > a > -- Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/ http://sigma.tuins.ac.jp/