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: [mg24849] RE: [mg24835] Expanding a nested structure (pattern matching?)
  • From: Wolf Hartmut <hwolf at debis.com>
  • Date: Wed, 16 Aug 2000 03:24:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


> -----Original Message-----
> From:	John A. Gunnels [SMTP:gunnels at cs.utexas.edu]
To: mathgroup at smc.vnet.net
> Sent:	Tuesday, August 15, 2000 9:04 AM
> To:	mathgroup at smc.vnet.net
> Subject:	[mg24835] Expanding a nested structure (pattern matching?)
> 
> 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
> 
[Hartmut Wolf]  

Hello John,

if you invariably have expressions of form a[b,c,d[{f,g},{g,h}]], then you
may MapAt (Distribute over List) to the right position (3 here) and finally
Thread:

In[14]:=
Thread at MapAt[Distribute[#, List] &, 
          a[b, c, d[{f, g}, {h, j}]], 3]
Out[14]=
{a[b, c, d[f, h]], 
 a[b, c, d[f, j]], 
 a[b, c, d[g, h]],
 a[b, c, d[g, j]]} 


-- Hartmut



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