MathGroup Archive 2005

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

Search the Archive

Re: Problem with matching.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53919] Re: Problem with matching.
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 4 Feb 2005 04:11:15 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <ctrngb$brk$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <ctrngb$brk$1 at smc.vnet.net>,
 Josef Karthauser <joe at tao.org.uk> wrote:

> Can someone tell me why this doesn't match?
> 
> F[{x, 2, c}]F[{x, 1, f}] /. F[{___, a_, ___}]F[{___, a_, ___}] :> yes
> 
> I'm expecting 'yes' to be returned if any of the list arguments to F[]
> contain the same value.  It doesn't match however; what am I doing
> wrong?

The left-hand side of the replacement rule is being simplified. If you 
enter

  F[{___, a_, ___}]F[{___, a_, ___}]

you will see what is going on. To prevent this evaluation you can use 
HoldPattern:

  F[{x, 2, c}]F[{x, 1, f}] /. 
    HoldPattern[F[{___, a_, ___}]F[{___, a_, ___}]] :> yes

or, alternatively, name all the patterns:

  F[{x, 2, c}]F[{x, 1, f}] /. 
    F[{a___, b_, c___}]F[{d___, b_, f___}] :> yes

Another approach is to use Intersection:

  F[{x, 2, c}]F[{x, 1, f}] /. 
    F[a_]F[b_] :> yes /; Intersection[a,b] != {}

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Problem with matching.
  • Next by Date: Re: Nonlinear Fittings: range / boundaries are not working :(
  • Previous by thread: Re: Problem with matching.
  • Next by thread: Re: Problem with matching.