       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:=
F[{x, 2, c}]F[{x, 1, f}] /.
HoldPattern[F[{___, a_, ___}]F[{___, a_, ___}]] :>
"yes, and same instance is " <> ToString[a]

Out=
"yes, and same instance is x"

In fact this matches too:

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

Out= yes

Your proposal in fact does not what desired:

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

Out= 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:=
F[{x, 2, c}]F[{1, f, x}] /.
F[{p___, a_, ___}]F[{q___, a_, ___}] /; Length[{p}] === Length[{q}] :>
yes

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

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

Out= yes

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

Out= 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 :(