       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:=
Unprotect[NonCommutativeMultiply];

In:=
Default[NonCommutativeMultiply]=1;

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

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

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

In:=
NonCommutativeMultiply[term1,5]

Out=
5 term1

In:=
NonCommutativeMultiply[5, term2]

Out=
5 term2

In:=
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=
5 term1**term2

In:=
FullForm[%]

Out//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