Re: About patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg9798] Re: About patterns
- From: Daniel Lichtblau <danl>
- Date: Fri, 28 Nov 1997 05:35:12 -0500
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
Idoia Aguirre wrote: > > I woul like to substitue any R*C appearence in a expression by another > variable like A. For example from the expression: > > R1*R2*C1*C2 > > to obtain somethin like this : A*A > > Haw coul I do it. If could. > > TIA > > I. Aguirre If your expression is a polynomial in the variables of interest you could use PolynomialReduce (more generally, you could map PolynomialReduce over relevant parts of your expression). Here we show how to operate on your example. First we create a set of polynomials with respect to which we will reduce your expression. Then we do just that using PolynomialReduce. In[41]:= polys = Flatten[Outer[Times,{r1,r2},{c1,c2}]] - a Out[41]= {-a + c1 r1, -a + c2 r1, -a + c1 r2, -a + c2 r2} In[42]:= Last[PolynomialReduce[r1*r2*c1*c2, polys, {r1,r2,c1,c2,a}]] 2 Out[42]= a For some examples simple rule-based replacement might suffice. For example, say instead you use "indexed" variables r[1], etc. Then you could do this as below. In[43]:= rule = r[_]*c[_] -> a; General::spell1: Possible spelling error: new symbol name "rule" is similar to existing symbol "Rule". In[46]:= r[1]*r[2]*c[1]*c[2] //. rule 2 Out[46]= a Daniel Lichtblau Wolfram Research