Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Re: Problem with matching.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53954] Re: [mg53935] Re: Problem with matching.
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 5 Feb 2005 03:15:13 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

 

>-----Original Message-----
>From: p-valko at tamu.edu [mailto:p-valko at tamu.edu] 
To: mathgroup at smc.vnet.net
>Sent: Friday, February 04, 2005 10:12 AM
>Subject: [mg53954] [mg53935] Re: Problem with matching.
>
>Josef,
>
>Because the numbers 1  and 2 are not the same, so they cannot 
>be matched with the same a.
>
>F[{x, 2, c}]F[{x, 1, f}] /. F[{___, a_, ___}]F[{___, b_, ___-}] :> yes
>
>
>will work fine.
>
>Regards
>Peter
>
>

This is what meets your eye, but not what happens:

In[105]:=
F[{x, 2, c}]F[{x, 1, f}] /. 
  HoldPattern[F[{___, a_, ___}]F[{___, a_, ___}]] :> 
    "yes, and same instance is " <> ToString[a]

Out[105]=
"yes, and same instance is x"


In fact this matches too:

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

Out[108]= yes





Your proposal in fact does not what desired:

In[103]:=
F[{1, 2, 3}]F[{4, 5, 6}] /. F[{___, a_, ___}]F[{___, b_, ___}] :> yes

Out[103]= yes


What was desired? I copy back (part of) the original post:

"I'm expecting 'yes' to be returned if any of the list arguments to F[]
contain the same value."
(Add: and of course not "yes" if not).



Now, we have seen, HoldPattern even is not enough, if matching arguments
have to be at the same position.

In[5]:=
F[{x, 2, c}]F[{1, f, x}] /. 
  F[{p___, a_, ___}]F[{q___, a_, ___}] /; Length[{p}] === Length[{q}] :>
yes

Out[5]= F[{1, f, x}] F[{x, 2, c}]


In[6]:=
F[{x, 2, c}]F[{x, 1, f}] /. 
  F[{p___, a_, ___}]F[{q___, a_, ___}] /; Length[{p}] === Length[{q}] :>
yes

Out[6]= yes


In[7]:=
F[{2, c, x}]F[{1, f, x}] /. 
  F[{p___, a_, ___}]F[{q___, a_, ___}] /; Length[{p}] === Length[{q}] :>
yes

Out[7]= yes


--
Hartmut Wolf


  • Prev by Date: Re: Nonlinear Fittings: range / boundaries are not working :(
  • Next by Date: Re: New Web Site for Mathematica Users using WikiMedia
  • Previous by thread: Re: Problem with matching.
  • Next by thread: Nonlinear Fittings: range / boundaries are not working :(