       HoldPattern & Pattern Matching

• To: mathgroup at smc.vnet.net
• Subject: [mg50473] HoldPattern & Pattern Matching
• From: Paul Buettiker <buettike at itkp.uni-bonn.de>
• Date: Sun, 5 Sep 2004 03:53:49 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Dear all,

I don't understand the following behavior of Mathematica 4.2:

In:= \$Version
Out= 4.2 for Linux (August 23, 2002)

In:= mysum = h[a] - 7h[b]
Out= h[a] - 7 h[b]

In:= mysum /. HoldPattern[Plus[aaa : (_.*h[_]) ..]] :> aaa
Out= h[a] - 7 h[b]

In:= mysum /. HoldPattern[Plus[aaa : (_.*h[_]) ..]] :> aaa // Trace
Out= {{mysum, h[a] - 7 h[b]},
>    h[a] - 7 h[b] /. HoldPattern[Plus[aaa:((_.) h[_]..)]] :> aaa,
>    Plus[Sequence[h[a], -7 h[b]]], h[a] - 7 h[b]}

The pattern matching should work for an arbitrary number of terms,
that's why I used Repeated[...], i.e. the "..".

I hoped to get Sequence[ h[a], -7 h[b] ].   I dont understand why
Sequence[...] is wrapped by Plus[...]. What did I miss?

Many thanks!
Paul.

```

• Prev by Date: Re: ExpandAll Problem with Rules
• Next by Date: Re: 5 variables Guass isnt working, matrix solution
• Previous by thread: Re: expresion with variables from a list
• Next by thread: Re: HoldPattern & Pattern Matching