MathGroup Archive 1997

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

Search the Archive

Bug in pattern matching?

  • To: mathgroup at
  • Subject: [mg8722] Bug in pattern matching?
  • From: "Peter Strömbeck" <pqst at>
  • Date: Fri, 19 Sep 1997 02:48:02 -0400
  • Organization: CelsiusTech Electronics AB
  • Sender: owner-wri-mathgroup at

Hi, I've posted this problem to Wolfram support but received no answer so I
thought I might just post it here aswell.

I'm trying to "deconstruct" a list, perform an operation to a pert of the
list and then recombine the result. When I did this I found out that
multiplication in pattern matching performs differently than otherwise.

Check version:

"Microsoft Windows 3.0 (October 6, 1996)"

Define list:

ls=Table[a[j], {j,0,5}]

I want to split this list into the following three sublists: 

{a[0],a[1],a[2],a[3],a[4],a[5]} -> {a[0]}, {a[1], a[2], a[3], a[4]}, {a[5]}

Use pattern matching:

ls/.{first_, middle___, last_}\[Rule] {{first},{middle},{last}}

This works fine. Now I want to multiply the middle list by a factor C.
Ordinary multiplication works like this:

C ls
{C a[0],C a[1],C a[2],C a[3],C a[4],C a[5]}

Doing this in a pattern matching statement produces a totally different

ls/.{first_, middle___, last_}\[Rule] {{first},C {middle},{last}}
{{a[0]},{C a[1] a[2] a[3] a[4]},{a[5]}}

The middle list now contains a completely different result than Out[4]!

Can anyone please explain this to me?

/Peter Strömbeck

  • Prev by Date: html generation in 3.00
  • Next by Date: [v2.2] Initialization cells and On[] / Off[]
  • Previous by thread: html generation in 3.00
  • Next by thread: Re: Bug in pattern matching?