Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3548 > unrolled thread

Re: Unwanted Recursion

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-07-07 11:42 +0000
Last post2011-07-08 09:00 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Unwanted Recursion Bill Rowe <readnews@sbcglobal.net> - 2011-07-07 11:42 +0000
    Re: Unwanted Recursion Kambis Veschgini <k.veschgini@thphys.uni-heidelberg.de> - 2011-07-08 09:00 +0000

#3548 — Re: Unwanted Recursion

FromBill Rowe <readnews@sbcglobal.net>
Date2011-07-07 11:42 +0000
SubjectRe: Unwanted Recursion
Message-ID<iv4637$f8u$1@smc.vnet.net>
On 7/6/11 at 5:39 AM, casorati@f-m.fm (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
>flat:

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.

[toc] | [next] | [standalone]


#3579

FromKambis Veschgini <k.veschgini@thphys.uni-heidelberg.de>
Date2011-07-08 09:00 +0000
Message-ID<iv6gvi$s74$1@smc.vnet.net>
In reply to#3548
On 2011-07-07 13:42:31 +0200, Bill Rowe said:

> On 7/6/11 at 5:39 AM, casorati@f-m.fm (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
>> flat:
> 
> Unless you are inventing new syntax a^b is not the product of a
> and b. It is a raised to the b power.

I am defining a new product called p. a^b^c should be represented in 
mathematica by p[a,b,c]
and so on.
> 
>> 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

I get the iterative behaviour executing this code (Mathematica 8 under 
Linux and Mac, I can't test it under Windows).

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

For this reason mathematica should replace it by the argument itself. 
This makes writing  other rules for example chain rule for derivatives 
much easier.

> 
> 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.

But I want p[a,b] to stay as p[a,b] brcause it represents the product 
of a and b. Consider them beeing Grassmann Numbers for example.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web