MathGroup Archive 2001

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

Search the Archive

Re: Defining a flat, orderless, one-identical function?[2]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28130] Re: Defining a flat, orderless, one-identical function?[2]
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 31 Mar 2001 02:59:00 -0500 (EST)
  • References: <200103290824.DAA03033@smc.vnet.net> <B6E8D3A8.BC10%andrzej@platon.c.u-tokyo.ac.jp> <9a1l0p$aav@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Another way of stopping cycling - don't use x_ .

ClearAll[f]
SetAttributes[f,{Flat,OneIdentity}]

f[x__]/;Length[{x}]==1:=x

f[a]

        a

f[a,b]

        f[a,b]

The pattern matcher does not convert f[a,b ] to f[f[a,b]] to match f[x__].

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Ralph Benzinger" <mma-l at endlos.net> wrote in message
news:9a1l0p$aav at smc.vnet.net...
> On March 29, you 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.
>
> Thanks for pointing this out; I admit I did a shoddy job in
> searching the archives.  I've now found a series of article from
> January 2000 that pretty much settle the issue once and for all.
> There also was an inquiry from 1995 and an interesting solution
> from Wolfram's support staff that suggested removing the Flat
> attribute and adding definitions that would unfold nested function
> calls manually.
>
> > Here is just one solution to your problem, the main idea of which, if
> > I remeber correctly, was once suggested by Carl Woll: [...]
> >
> > In[2]:=
> >    (x_max/;Length[Unevaluated[x]]==1):=Hold[x][[1,1]]
>
> Great! This ingenious rule works like a charm.  It's quite a hack,
> though, isn't it? ;-)
>
> Ralph
>
> --
> Ralph Benzinger          "This is my theory, it is mine, I own it,
> Cornell Univeristy        and what it is, too." -- Ann Elk (Mrs.)
>




  • Prev by Date: Novice question regarding variable naming and subscripts
  • Next by Date: 2D Fourier and Plot3D???
  • Previous by thread: Re: Defining a flat, orderless, one-identical function?
  • Next by thread: Re: Defining a flat, orderless, one-identical function?