MathGroup Archive 1998

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

Search the Archive

are nested patterns impossible?



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



  • Prev by Date: Simple question
  • Next by Date: Assignment to submatrices
  • Prev by thread: Re: Simple question
  • Next by thread: Re: are nested patterns impossible?