MathGroup Archive 2002

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

Search the Archive

RE: Question about pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34099] RE: [mg34057] Question about pattern matching
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Thu, 2 May 2002 03:49:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> -----Original Message-----
> From: Mike Varney [mailto:varney at collorado.edu]
To: mathgroup at smc.vnet.net
> Sent: Wednesday, May 01, 2002 2:00 PM
> Subject: [mg34099] [mg34057] Question about pattern matching
> 
> 
> Hello.
> I have a rather straight forward question on pattern matching.
> 
> Say that I have a expression given as:
> 
> (kg m^2) /(s^2)
> 
> When I try a pattern matching substitution such as:
> 
> (kg m^2) /(s^2) /. (kg m)/(s^2) -> n
> 
> Returns:
> (kg m^2) /(s^2)
> 
> 
> Am I missing some sort of rule?  How can I do this sort of 
> pattern matching.
> 
> Thanks for you help.
> Mike
> 
> 

Mike,

your pattern cannot match (part of) your dimensional expression. You have to
bring it to exponent form, but allow for the exponents to be one by default,
e.g.

In[9]:=
(kg m^2)/(s^2)/. kg^d_. m^e_. s^f_. :> n m^(e-1) kg^(d-1) s^(f+2)

Out[9]= m n

In[11]:= kg^d_. m^e_. s^f_.//FullForm

Out[11]//FullForm=
Times[Power[kg,Optional[Pattern[d,Blank[]]]],
 
Power[m,Optional[Pattern[e,Blank[]]]],Power[s,Optional[Pattern[f,Blank[]]]]]

Look up the meaning of Optional[Pattern[...]]

--
Hartmut



  • Prev by Date: Re: Split Polynom into Sum of Monomials
  • Next by Date: Re: Memory restoring form within Mathematica ?
  • Previous by thread: Re: Question about pattern matching
  • Next by thread: Re: Re: Question about pattern matching