Re: Matching two patterns?

• To: mathgroup at smc.vnet.net
• Subject: [mg74180] Re: Matching two patterns?
• From: "dimitris" <dimmechan at yahoo.com>
• Date: Tue, 13 Mar 2007 05:10:41 -0500 (EST)
• References: <esu6g5\$rpk\$1@smc.vnet.net>

```On Mar 10, 1:57 pm, "Neri" <nkafk... at yahoo.com> wrote:
> Can two patterns be matched with each other, to find if they
> intersect?
>
> What I mean is that  { _, 1} matches {1, _ } in the sense that there
> are lists that fit both, in this case {1,1}.
> However, { _, 1} doesn't match { _, 2} in the sense that no list can
> fit both.
>
> For lists it seems easy to write a function that does that, but I
> wondered if such a function already exists and can it be more general?
>
> Thanks,
>
> Neri

Cases[{{2, 1}, {3, 1}, {a, 1}, {a, a}, {1, 1}}, {x_, x_}]
{{a, a}, {1, 1}}

Cases[f[g[2, 1], g[3, 1], g[a, 1], g[a, a], g[1, 1]], g[x_, x_]]
{g[a, a], g[1, 1]}

{{2, 1}, {3, 1}, {a, 1}, {a, a}, {1, 1}, {3, 3}, {1, 4}, {1, 2}}
Cases[%, {x_, 1}]
Cases[%%, {1, x_}]
Intersection[%, %%]

{{2, 1}, {3, 1}, {a, 1}, {a, a}, {1, 1}, {3, 3}, {1, 4}, {1, 2}}
{{2, 1}, {3, 1}, {a, 1}, {1, 1}}
{{1, 1}, {1, 4}, {1, 2}}
{{1, 1}}

???

```

• Prev by Date: Re: How do I write tabular output?
• Next by Date: Re: Bug with Limit?
• Previous by thread: Re: Matching two patterns?
• Next by thread: plot of "marginal distributions" of scatter plot