MathGroup Archive 2000

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

Search the Archive

Re: Expanding a nested structure (pattern matching?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24842] Re: Expanding a nested structure (pattern matching?)
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Wed, 16 Aug 2000 03:24:07 -0400 (EDT)
  • References: <8naqam$eug@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

John,

One possible technique (I replaced D with d since D is for differentiation)

ReplaceList[A[B, C, d[ {F, G}, {H, J}]],
  A[B, C, d[{___, x_, ___}, {___, y_, ___}]] -> A[B, C, d[x, y]]]


        {A[B, C, d[F, H]], A[B, C, d[F, J]], A[B, C, d[G, H]], A[B, C, d[G,
J]]}


Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"John A. Gunnels" <gunnels at cs.utexas.edu> wrote in message
news:8naqam$eug at smc.vnet.net...
> I hope that this is not a _really_ stupid question, but I have run
> into what appears to be a problem using rewrite rules to un-nest
> a structure.
>
> The crux of the problem (I have tried to make it as simple as possible
> without losing the essence of my difficulty) has to do with duplicating
> the structure surrounding the terms that I wish to rewrite.
>
> Any nested list is intended to represent a choice point and my rewrite
> rules are aimed at enumerating all of the possible sequences of choices.
>
> An example:
> Input:
> A[B, C, D[ {F, G}, {H, J}]]
> should become
> A[B, C, D[F, H]],
> A[B, C, D[F, J]],
> A[B, C, D[G, J]],
> A[B, C, D[G, J]]
>
> Obviously, the order isn't important, but the nesting isn't restricted
> to level 2 nor am I guaranteed that all heads or elements are unique.
> I realize that I may have to simply write the code that iterates through
> the different Depth[]s, but this seems like it might have a very clean
> answer that simply hasn't occurred to me.
>
> Thanks,
> John A. Gunnels
> gunnels at cs.utexas.edu
>




  • Prev by Date: Re: List of Interpolated functions inside plot
  • Next by Date: Re: List of Interpolated functions inside plot
  • Previous by thread: Expanding a nested structure (pattern matching?)
  • Next by thread: RE: Expanding a nested structure (pattern matching?)