Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

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

Search the Archive

Patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7647] Patterns
  • From: mabi at solidmr.kun.nl (Marlies Brinksma)
  • Date: Tue, 24 Jun 1997 03:36:10 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi all,

I don't understand why the following implementation results in an infinite recursion. Does anyone know what the problem is?

Thanks in advance for any help!

Best regards,

Marlies Brinksma

*****************************************************************************
 In[1]:=
Unprotect[NonCommutativeMultiply];

In[2]:=
Default[NonCommutativeMultiply]=1;

In[3]:=
NonCommutativeMultiply[a_,1]:= a
NonCommutativeMultiply[1,a_]:=a


(* This is the rule which causes the infitite recursion *)

In[5]:=
NonCommutativeMultiply[a_.,b_?NumberQ,c_.]:=
  Times[b,NonCommutativeMultiply[a,c]]

In[6]:=
NonCommutativeMultiply[term1,5]

Out[6]=
5 term1

In[7]:=
NonCommutativeMultiply[5, term2]

Out[7]=
5 term2

In[8]:=
NonCommutativeMultiply[term1,5, term2 ]

$RecursionLimit::"reclim": "Recursion depth of \!\(256\) exceeded."

$RecursionLimit::"reclim": "Recursion depth of \!\(256\) exceeded."

$RecursionLimit::"reclim": "Recursion depth of \!\(256\) exceeded."

General::"stop": 
    "Further output of \!\($RecursionLimit :: \"reclim\"\) will be suppressed \
during this calculation."

Out[8]=
5 term1**term2

In[9]:=
FullForm[%]

Out[9]//FullForm=
Times[5,NonCommutativeMultiply[term1,term2]]


  • Prev by Date: Re: Legend
  • Next by Date: Replacing Parts
  • Previous by thread: Re: problems with precision
  • Next by thread: Replacing Parts