Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24061] Re: Pattern Matching
  • From: "David Bailey" <db at salford-software.com>
  • Date: Thu, 22 Jun 2000 01:01:53 -0400 (EDT)
  • Organization: University of Salford, Salford, Manchester, UK
  • References: <8hsu3g$dh4@smc.vnet.net> <8i1suj$jls@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Allan Hayes <hay at haystack.demon.co.uk> wrote in message
news:8i1suj$jls at smc.vnet.net...
> Johannes,
>
> Re your first question.
>
>
> We can avoid this by using HoldPattern:
>
>
> x[1] b[1] + x[2] b[2] /.
>   HoldPattern[Plus[Times[x[_],  b[_]] ..]] -> z
>
>         z
>
>
> However it does seem odd that, in spite of (*1*), we get
>
> x * b[1] + x* b[2] /.
>   (x* b[_]) .. -> z
>
>         2 z
>
> --
> Allan

I experimented with various constructs based on HoldPattern and Repeated,
but without success. I think the easiest way to isolate terms of the form
x[i]b[i] is to proceed in stages. First wrap the terms of interest in a
function - say f - and then merge them together:

ss = x[1]b[1] + x[2]b[2] + x[3]b[3] + x[10]b[5]

ss /. x[n_]b[n_] -> f[x[n]b[n]] //.
  f[a_, a1___] + f[b_, b1___] -> f[a, a1, b, b1]

This gives:

f[b[3] x[3], b[1] x[1], b[2] x[2]] + b[5] x[10]

At this point you can use a replacement such as f[__]->v, or you can do
something useful to the arguments of  f.

David Bailey
Salford Software




  • Prev by Date: Mean of Geometric and Negative Binomial distributions
  • Next by Date: Re: Re:two dimensional distribution
  • Previous by thread: Re: Pattern Matching
  • Next by thread: First Order Differential Equation