MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: Defining a flat, orderless, one-identical function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28148] RE: Re: Defining a flat, orderless, one-identical function?
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Sun, 1 Apr 2001 00:08:07 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

In my earlier reply I forgot to mention the two pages on the Wolfram site
that help explain what's going on here.  I am not sure if I provide links to
these pages on my tips, tricks site.  The URLs for the Wolfram pages are:

http://support.wolfram.com/Kernel/Symbols/System/Flat.html

http://support.wolfram.com/Kernel/Symbols/System/OneIdentity.html

----------------------------------
Ralph Benzinger was trying to define a flat, orderless, one-identical
function `max', i.e. he wanted the following equivalences to hold: 
(1) max[a, max[b, c]] == max[a, b, c] 
(2) max[a, b] == max[b, a] 
(3) max[a] == a 
The built-in Plus[] function has exactly these properties. 
------------------------
I wanted to do that a few years ago, and Carl Woll came up with the
following ingenious solution.

In[1]:= ClearAll[max];
  SetAttributes[max, {Flat,OneIdentity,Orderless}];
  a_max /; Length[Unevaluated[a]]==1 := Identity@@Unevaluated[a]

In[4]:=
  max[a,max[b,c]]

Out[4]=
  max[a,b,c]

In[5]:=
  max[b,a]

Out[5]=
  max[a,b]


In[6]:=
  max[a]

Out[6]=
  a

To read a complete discussion of this trick goto my web-site (URL below)
then goto the section on Flat. This discussion is at the end of this section
and stars with "A warning about the Flat attribute" in bold.

--------------------
Regards,
Ted Ersek

Download Mathematica tips, tricks from 
http://www.verbeia.com/mathematica/tips/Tricks.html



  • Prev by Date: Re: NIntegrate embedded in a function
  • Next by Date: Re: NIntegrate embedded in a function
  • Previous by thread: Re: Defining a flat, orderless, one-identical function?
  • Next by thread: C, MathLink or Java, J/Link