MathGroup Archive 2011

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

Search the Archive

Re: Unwanted Recursion

  • To: mathgroup at
  • Subject: [mg120066] Re: Unwanted Recursion
  • From: Bill Rowe <readnews at>
  • Date: Thu, 7 Jul 2011 07:32:32 -0400 (EDT)

On 7/6/11 at 5:39 AM, casorati at (Casorati) wrote:

>I'm trying to define an anti-commutative algebra in Mathematica.
>Here I will show only a minimal example to demonstrate my point. The
>product of two elements a^b should be give by p[a,b] so I make p

Unless you are inventing new syntax a^b is not the product of a
and b. It is a raised to the b power.

>SetAttributes[p, {Flat}]

>But now I want p[a] to reduce to a. Such a  rule would make other
>rules much simpler but when I define

>p[a_] := a

>the expression p[a] causes an infinite recursion. I get the message

>$IterationLimit::itlim: Iteration limit of 4096 exceeded.

While I cannot explain precisely why this message occurs I can
confirm I get the same result when I set the attributes for p to
be Flat. However, if I do not set the attributes of p then
things work fine as demonstrated by:

In[1]:= p[a_] := a

In[2]:= p[a]

Out[2]= a

and given that p has been defined with a single argument, it
makes no sense for it to also have the attribute Flat.

If you were to define p to take an arbitrary number of arguments
and give it the attribute Flat, i.e.,

In[6]:= Clear[p]

In[7]:= SetAttributes[p, {Flat}]

In[8]:= p[a__] := a

In[9]:= p[a, b]

Out[9]= Sequence[a,b]

the error message doesn't occur.

  • Prev by Date: Re: Bug 1+4/10
  • Next by Date: Re: How can I get better solution for this...?
  • Previous by thread: Re: Unwanted Recursion
  • Next by thread: Re: Unwanted Recursion