       Re: Help Mathematica - Generating Patterns

• To: mathgroup at smc.vnet.net
• Subject: [mg54887] Re: [mg54852] Help Mathematica - Generating Patterns
• From: "David Park" <djmp at earthlink.net>
• Date: Sat, 5 Mar 2005 01:34:31 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Here are a couple of routines that I have in one of my packages.

SymbolsToPatterns::usage =
"SymbolsToPatterns[symbollist][expr] will convert symbols in expression,
\
which are on symbollist, to named patterns.";
SymbolsToPatterns[symbols : {_Symbol ..}][expr_] :=
expr /. Thread[symbols -> (Pattern[#, Blank[]] & /@ symbols)]

LHSSymbolsToPatterns::usage =
"LHSSymbolsToPatterns[symbollist][expr] will apply SymbolsToPatterns to
\
the first part of expr.";
LHSSymbolsToPatterns[symbollist_][expr_] :=
MapAt[SymbolsToPatterns[symbollist], expr, 1]

{x1, x2, x3}
% // SymbolsToPatterns[{x1, x2, x3}]
{x1_, x2_, x3_}

Often we may have derived an equation and then wish to use the equation as a
substitution rule in subsequent derivations. That means we want to change
the equation into a rule and specified symbols on the left hand side into
patterns. Here is a trivial made-up example.

(x + y)^2 == Expand[(x + y)^2] // Reverse
rule = Rule @@ % // LHSSymbolsToPatterns[{x, y}]
x^2 + 2*x*y + y^2 == (x + y)^2
(x_)^2 + 2*(x_)*(y_) + (y_)^2 -> (x + y)^2

David Park

From: Awgn78 [mailto:robynobile at gmail.com]
To: mathgroup at smc.vnet.net

How i can obtain a list {x1_,x2_,x3_} from a list {x1, x2, x3}...
thank you for help and sorry for my bad english...i'm italian

```

• Prev by Date: Re: Rearranging a data array containing calendrical as well as data entries.
• Next by Date: How to match/balance parenthesis?
• Previous by thread: Re: Front End Programming question
• Next by thread: How to match/balance parenthesis?