are nested patterns impossible?
- To: mathgroup@smc.vnet.net
- Subject: [mg11203] are nested patterns impossible?
- From: Lemm@Stud-Mailer.Uni-Marburg.DE (Thomas Lemm)
- Date: Mon, 2 Mar 1998 23:10:56 -0500
- Organization: HRZ Uni Marburg
I try to create a pattern describing a linear combination of a list of variables. Be those variables u and v, the pattern should match for both u*k+v*l (k,l constants) and u*k (coefficient of v == 0) But when I program it in using nested patterns In[82]:=pat=u*_.+(v*_.|0) Out[82]=(v _.|0)+u _. In[84]:=MatchQ[u*5+v*10,pat] Out[84]=True In[86]:=MatchQ[u*5,pat] Out[86]=False The last case does not match, which leads to the question: what did I program and how can I program the thing I intended to? I already know about the possibility making a pattern like u*_.+v*_.|u*_. But this is not the way I want to program this example as I would like to extend this case to many more than two variables u,v. Thomas Lemm